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 autoreturnkey : 1;
150 Eina_Bool input_panel_enable : 1;
151 Eina_Bool autocapital : 1;
152 Elm_Input_Panel_Layout input_panel_layout;
153 Eina_Bool autoperiod : 1;
156 struct _Elm_Entry_Context_Menu_Item
160 const char *icon_file;
161 const char *icon_group;
162 Elm_Icon_Type icon_type;
167 struct _Elm_Entry_Item_Provider
169 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
173 struct _Elm_Entry_Text_Filter
175 void (*func) (void *data, Evas_Object *entry, char **text);
179 static const char *widtype = NULL;
181 static Evas_Object *cnpwidgetdata = NULL;
184 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
185 static void _del_hook(Evas_Object *obj);
186 static void _theme_hook(Evas_Object *obj);
187 static void _disable_hook(Evas_Object *obj);
188 static void _sizing_eval(Evas_Object *obj);
189 static void _on_focus_hook(void *data, Evas_Object *obj);
190 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
191 static const char *_getbase(Evas_Object *obj);
192 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
193 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
194 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
195 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
196 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
197 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
198 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
199 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
200 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
201 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
202 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
203 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
204 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
205 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
206 static int _is_width_over(Evas_Object *obj);
207 static void _ellipsis_entry_to_width(Evas_Object *obj);
208 static void _reverse_ellipsis_entry(Evas_Object *obj);
209 static int _entry_length_get(Evas_Object *obj);
211 static const char SIG_CHANGED[] = "changed";
212 static const char SIG_ACTIVATED[] = "activated";
213 static const char SIG_PRESS[] = "press";
214 static const char SIG_LONGPRESSED[] = "longpressed";
215 static const char SIG_CLICKED[] = "clicked";
216 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
217 static const char SIG_FOCUSED[] = "focused";
218 static const char SIG_UNFOCUSED[] = "unfocused";
219 static const char SIG_SELECTION_PASTE[] = "selection,paste";
220 static const char SIG_SELECTION_COPY[] = "selection,copy";
221 static const char SIG_SELECTION_CUT[] = "selection,cut";
222 static const char SIG_SELECTION_START[] = "selection,start";
223 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
224 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
225 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
226 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
227 static const Evas_Smart_Cb_Description _signals[] = {
231 {SIG_LONGPRESSED, ""},
233 {SIG_CLICKED_DOUBLE, ""},
236 {SIG_SELECTION_PASTE, ""},
237 {SIG_SELECTION_COPY, ""},
238 {SIG_SELECTION_CUT, ""},
239 {SIG_SELECTION_START, ""},
240 {SIG_SELECTION_CHANGED, ""},
241 {SIG_SELECTION_CLEARED, ""},
242 {SIG_CURSOR_CHANGED, ""},
243 {SIG_ANCHOR_CLICKED, ""},
247 static Eina_List *entries = NULL;
251 void (*obj_hook) (Evas_Object *obj);
252 void (*obj_unhook) (Evas_Object *obj);
253 void (*obj_longpress) (Evas_Object *obj);
254 void (*obj_hidemenu) (Evas_Object *obj);
255 void (*obj_mouseup) (Evas_Object *obj);
259 _module(Evas_Object *obj __UNUSED__)
261 static Elm_Module *m = NULL;
262 if (m) goto ok; // already found - just use
263 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
265 m->api = malloc(sizeof(Mod_Api));
266 if (!m->api) return NULL;
267 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
268 _elm_module_symbol_get(m, "obj_hook");
269 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
270 _elm_module_symbol_get(m, "obj_unhook");
271 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
272 _elm_module_symbol_get(m, "obj_longpress");
273 ((Mod_Api *)(m->api) )->obj_hidemenu = // called on hide menu
274 _elm_module_symbol_get(m, "obj_hidemenu");
275 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
276 _elm_module_symbol_get(m, "obj_mouseup");
277 ok: // ok - return api
282 _buf_append(char *buf, const char *str, int *len, int *alloc)
284 int len2 = strlen(str);
285 if ((*len + len2) >= *alloc)
287 char *buf2 = realloc(buf, *alloc + len2 + 512);
288 if (!buf2) return NULL;
290 *alloc += (512 + len2);
292 strcpy(buf + *len, str);
298 _load_file(const char *file)
302 int alloc = 0, len = 0;
303 char *text = NULL, buf[PATH_MAX];
305 f = fopen(file, "rb");
307 while ((size = fread(buf, 1, sizeof(buf), f)))
311 tmp_text = _buf_append(text, buf, &len, &alloc);
312 if (!tmp_text) break;
320 _load_plain(const char *file)
324 text = _load_file(file);
329 text2 = elm_entry_utf8_to_markup(text);
337 _load(Evas_Object *obj)
339 Widget_Data *wd = elm_widget_data_get(obj);
344 elm_entry_entry_set(obj, "");
349 case ELM_TEXT_FORMAT_PLAIN_UTF8:
350 text = _load_plain(wd->file);
352 case ELM_TEXT_FORMAT_MARKUP_UTF8:
353 text = _load_file(wd->file);
361 elm_entry_entry_set(obj, text);
365 elm_entry_entry_set(obj, "");
369 _save_markup_utf8(const char *file, const char *text)
373 if ((!text) || (!text[0]))
375 ecore_file_unlink(file);
378 f = fopen(file, "wb");
381 // FIXME: report a write error
384 fputs(text, f); // FIXME: catch error
389 _save_plain_utf8(const char *file, const char *text)
393 text2 = elm_entry_markup_to_utf8(text);
396 _save_markup_utf8(file, text2);
401 _save(Evas_Object *obj)
403 Widget_Data *wd = elm_widget_data_get(obj);
405 if (!wd->file) return;
408 case ELM_TEXT_FORMAT_PLAIN_UTF8:
409 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
411 case ELM_TEXT_FORMAT_MARKUP_UTF8:
412 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
420 _delay_write(void *data)
422 Widget_Data *wd = elm_widget_data_get(data);
423 if (!wd) return ECORE_CALLBACK_CANCEL;
425 wd->delay_write = NULL;
426 return ECORE_CALLBACK_CANCEL;
430 _del_pre_hook(Evas_Object *obj)
432 Widget_Data *wd = elm_widget_data_get(obj);
436 ecore_timer_del(wd->delay_write);
437 wd->delay_write = NULL;
438 if (wd->autosave) _save(obj);
443 _del_hook(Evas_Object *obj)
445 Widget_Data *wd = elm_widget_data_get(obj);
446 Elm_Entry_Context_Menu_Item *it;
447 Elm_Entry_Item_Provider *ip;
448 Elm_Entry_Text_Filter *tf;
450 if (wd->file) eina_stringshare_del(wd->file);
452 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
453 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
455 entries = eina_list_remove(entries, obj);
456 #ifdef HAVE_ELEMENTARY_X
457 ecore_event_handler_del(wd->sel_notify_handler);
458 ecore_event_handler_del(wd->sel_clear_handler);
460 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
461 if (wd->text) eina_stringshare_del(wd->text);
462 if (wd->bg) evas_object_del(wd->bg);
463 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
464 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
465 EINA_LIST_FREE(wd->items, it)
467 eina_stringshare_del(it->label);
468 eina_stringshare_del(it->icon_file);
469 eina_stringshare_del(it->icon_group);
472 EINA_LIST_FREE(wd->item_providers, ip)
476 EINA_LIST_FREE(wd->text_filters, tf)
484 _theme_hook(Evas_Object *obj)
486 Widget_Data *wd = elm_widget_data_get(obj);
488 Ecore_IMF_Context *ic;
490 t = eina_stringshare_add(elm_entry_entry_get(obj));
491 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
492 elm_entry_entry_set(obj, t);
493 eina_stringshare_del(t);
494 if (elm_widget_disabled_get(obj))
495 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
496 edje_object_message_signal_process(wd->ent);
497 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
498 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
499 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
500 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
502 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
505 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
512 _disable_hook(Evas_Object *obj)
514 Widget_Data *wd = elm_widget_data_get(obj);
516 if (elm_widget_disabled_get(obj))
518 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
519 wd->disabled = EINA_TRUE;
523 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
524 wd->disabled = EINA_FALSE;
529 _elm_win_recalc_job(void *data)
531 Widget_Data *wd = elm_widget_data_get(data);
532 Evas_Coord minw = -1, minh = -1, maxh = -1;
533 Evas_Coord resw, resh, minminw;
535 wd->deferred_recalc_job = NULL;
536 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
538 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
539 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
541 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
542 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
543 evas_object_size_hint_min_set(data, minminw, minh);
544 if (wd->single_line) maxh = minh;
545 evas_object_size_hint_max_set(data, -1, maxh);
546 if (wd->deferred_cur)
547 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
551 _sizing_eval(Evas_Object *obj)
553 Widget_Data *wd = elm_widget_data_get(obj);
554 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
555 Evas_Coord resw, resh;
557 if ((wd->linewrap) || (wd->char_linewrap))
559 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
560 if ((resw == wd->lastw) && (!wd->changed)) return;
561 wd->changed = EINA_FALSE;
563 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
564 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
568 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
569 edje_object_size_min_calc(wd->ent, &minw, &minh);
570 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
571 evas_object_size_hint_min_set(obj, minw, minh);
572 if (wd->single_line) maxh = minh;
573 evas_object_size_hint_max_set(obj, maxw, maxh);
575 if (wd->ellipsis && wd->single_line)
577 if (_is_width_over(obj))
578 _ellipsis_entry_to_width(obj);
579 else if (wd->ellipsis_threshold > 1 && _entry_length_get(obj) < wd->ellipsis_threshold)
580 _reverse_ellipsis_entry(obj);
586 _check_enable_returnkey(Evas_Object *obj)
588 Widget_Data *wd = elm_widget_data_get(obj);
591 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
594 if (!wd->autoreturnkey) return;
596 if (_entry_length_get(obj) == 0)
598 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
602 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
607 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
609 Widget_Data *wd = elm_widget_data_get(obj);
610 Evas_Object *top = elm_widget_top_get(obj);
611 Evas_Object *parent_obj = obj;
612 Evas_Object *above = NULL;
615 if (!wd->editable) return;
616 if (elm_widget_focus_get(obj))
618 evas_object_focus_set(wd->ent, EINA_TRUE);
619 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
620 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
621 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
622 _check_enable_returnkey(obj);
626 above = evas_object_above_get(parent_obj);
628 evas_object_data_set(parent_obj, "raise", above);
629 evas_object_raise(parent_obj);
630 parent_obj = elm_widget_parent_get(parent_obj);
635 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
636 evas_object_focus_set(wd->ent, EINA_FALSE);
637 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
638 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
642 above = evas_object_data_get(parent_obj, "raise");
644 evas_object_stack_below(parent_obj, above);
645 parent_obj = elm_widget_parent_get(parent_obj);
647 if ((wd->api) && (wd->api->obj_hidemenu))
649 wd->api->obj_hidemenu(data);
655 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
657 Widget_Data *wd = elm_widget_data_get(obj);
659 edje_object_signal_emit(wd->ent, emission, source);
663 _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)
665 Widget_Data *wd = elm_widget_data_get(obj);
667 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
671 _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)
673 Widget_Data *wd = elm_widget_data_get(obj);
674 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
679 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
681 Widget_Data *wd = elm_widget_data_get(obj);
682 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
686 _hoversel_position(Evas_Object *obj)
688 Widget_Data *wd = elm_widget_data_get(obj);
689 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
691 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
692 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
694 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
705 evas_object_move(wd->hoversel, x + cx, y + cy);
706 evas_object_resize(wd->hoversel, cw, ch);
710 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
712 Widget_Data *wd = elm_widget_data_get(data);
714 if (wd->hoversel) _hoversel_position(data);
718 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
720 Widget_Data *wd = elm_widget_data_get(data);
722 if ((wd->linewrap) || (wd->char_linewrap))
726 if (wd->hoversel) _hoversel_position(data);
727 // Evas_Coord ww, hh;
728 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
732 _hover_del(void *data)
734 Widget_Data *wd = elm_widget_data_get(data);
739 evas_object_del(wd->hoversel);
742 wd->hovdeljob = NULL;
746 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
748 Widget_Data *wd = elm_widget_data_get(data);
750 if (wd->hoversel) evas_object_hide(wd->hoversel);
754 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
756 elm_widget_scroll_freeze_pop(data);
757 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
758 wd->hovdeljob = ecore_job_add(_hover_del, data);
762 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
764 Widget_Data *wd = elm_widget_data_get(data);
766 wd->selmode = EINA_TRUE;
768 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
769 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
770 edje_object_part_text_select_all(wd->ent, "elm.text");
771 //elm_widget_scroll_hold_push(data);
772 elm_object_scroll_freeze_pop(data);
776 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
778 Widget_Data *wd = elm_widget_data_get(data);
780 wd->selmode = EINA_TRUE;
781 edje_object_part_text_select_none(wd->ent, "elm.text");
783 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
784 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
785 elm_object_scroll_freeze_pop(data);
786 //elm_widget_scroll_hold_push(data);
790 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
792 Widget_Data *wd = elm_widget_data_get(data);
794 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
795 if (wd->sel_notify_handler)
797 #ifdef HAVE_ELEMENTARY_X
798 wd->selection_asked = EINA_TRUE;
799 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data, NULL, NULL);
805 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
807 Widget_Data *wd = elm_widget_data_get(obj);
811 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
812 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
813 if (seltype == ELM_SEL_CLIPBOARD)
814 eina_stringshare_replace(&wd->cut_sel, sel);
818 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
820 Widget_Data *wd = elm_widget_data_get(data);
823 wd->selmode = EINA_FALSE;
824 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
825 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
826 elm_widget_scroll_hold_pop(data);
827 _store_selection(ELM_SEL_CLIPBOARD, data);
828 edje_object_part_text_insert(wd->ent, "elm.text", "");
829 edje_object_part_text_select_none(wd->ent, "elm.text");
833 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
835 Widget_Data *wd = elm_widget_data_get(data);
837 //wd->selmode = EINA_FALSE;
838 //edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
839 //edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
840 elm_widget_scroll_hold_pop(data);
841 _store_selection(ELM_SEL_CLIPBOARD, data);
842 //edje_object_part_text_select_none(wd->ent, "elm.text");
846 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
848 Widget_Data *wd = elm_widget_data_get(data);
850 wd->selmode = EINA_FALSE;
851 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
852 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
853 elm_widget_scroll_hold_pop(data);
854 edje_object_part_text_select_none(wd->ent, "elm.text");
858 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
860 Widget_Data *wd = elm_widget_data_get(data);
864 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
865 cnpwidgetdata = data;
866 elm_cbhm_helper_init(obj);
867 elm_cbhm_send_raw_data("show");
873 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
875 Widget_Data *wd = elm_widget_data_get(data);
877 cnpwidgetdata = data;
883 _item_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
885 Elm_Entry_Context_Menu_Item *it = data;
886 Evas_Object *obj2 = it->obj;
887 if (it->func) it->func(it->data, obj2, NULL);
891 _long_press(void *data)
893 Widget_Data *wd = elm_widget_data_get(data);
896 const Elm_Entry_Context_Menu_Item *it;
897 if (!wd) return ECORE_CALLBACK_CANCEL;
898 if ((wd->api) && (wd->api->obj_longpress))
900 wd->api->obj_longpress(data);
902 else if (wd->context_menu)
904 const char *context_menu_orientation;
906 if (wd->hoversel) evas_object_del(wd->hoversel);
907 else elm_widget_scroll_freeze_push(data);
908 wd->hoversel = elm_hoversel_add(data);
909 context_menu_orientation = edje_object_data_get
910 (wd->ent, "context_menu_orientation");
911 if ((context_menu_orientation) &&
912 (!strcmp(context_menu_orientation, "horizontal")))
913 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
914 elm_object_style_set(wd->hoversel, "entry");
915 elm_widget_sub_object_add(data, wd->hoversel);
916 elm_hoversel_label_set(wd->hoversel, "Text");
917 top = elm_widget_top_get(data);
918 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
919 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
923 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
925 if (1) // need way to detect if someone has a selection
928 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
933 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
934 _clipboard_menu, data);
941 if (wd->have_selection)
943 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
946 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
949 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
952 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
953 _clipboard_menu, data);
957 EINA_LIST_FOREACH(wd->items, l, it)
959 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
960 it->icon_type, _item_clicked, it);
964 _hoversel_position(data);
965 evas_object_show(wd->hoversel);
966 elm_hoversel_hover_begin(wd->hoversel);
968 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
969 edje_object_part_text_select_abort(wd->ent, "elm.text");
971 wd->longpress_timer = NULL;
972 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
973 return ECORE_CALLBACK_CANCEL;
977 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
979 Widget_Data *wd = elm_widget_data_get(data);
980 Evas_Event_Mouse_Down *ev = event_info;
982 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
983 if (ev->button != 1) return;
984 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
985 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
986 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
987 wd->downx = ev->canvas.x;
988 wd->downy = ev->canvas.y;
990 wd->long_pressed = EINA_FALSE;
994 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
996 Widget_Data *wd = elm_widget_data_get(data);
997 Evas_Event_Mouse_Up *ev = event_info;
999 if (ev->button != 1) return;
1001 if (!wd->double_clicked)
1003 if ((wd->api) && (wd->api->obj_mouseup))
1005 wd->api->obj_mouseup(data);
1008 if (wd->longpress_timer)
1010 ecore_timer_del(wd->longpress_timer);
1011 wd->longpress_timer = NULL;
1014 elm_object_scroll_freeze_pop(data);
1018 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1020 Widget_Data *wd = elm_widget_data_get(data);
1021 Evas_Event_Mouse_Move *ev = event_info;
1025 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1027 if (wd->longpress_timer)
1029 ecore_timer_del(wd->longpress_timer);
1030 wd->longpress_timer = NULL;
1033 else if (wd->longpress_timer)
1037 dx = wd->downx - ev->cur.canvas.x;
1039 dy = wd->downy - ev->cur.canvas.y;
1042 ((_elm_config->finger_size / 2) *
1043 (_elm_config->finger_size / 2)))
1045 ecore_timer_del(wd->longpress_timer);
1046 wd->longpress_timer = NULL;
1050 else if (wd->longpress_timer)
1054 dx = wd->downx - ev->cur.canvas.x;
1056 dy = wd->downy - ev->cur.canvas.y;
1059 ((_elm_config->finger_size / 2) *
1060 (_elm_config->finger_size / 2)))
1062 ecore_timer_del(wd->longpress_timer);
1063 wd->longpress_timer = NULL;
1069 _getbase(Evas_Object *obj)
1071 Widget_Data *wd = elm_widget_data_get(obj);
1072 if (!wd) return "base";
1077 if (wd->show_last_character) return "custom-password";
1078 else return "base-password";
1082 if (wd->single_line) return "base-single";
1085 if (wd->linewrap) return "base";
1086 else if (wd->char_linewrap) return "base-charwrap";
1087 else return "base-nowrap";
1095 if (wd->show_last_character) return "custom-password";
1096 else return "base-password";
1100 if (wd->single_line) return "base-single-noedit";
1103 if (wd->linewrap) return "base-noedit";
1104 else if (wd->char_linewrap) return "base-noedit-charwrap";
1105 else return "base-nowrap-noedit";
1113 _entry_length_get(Evas_Object *obj)
1116 const char *str = elm_entry_entry_get(obj);
1119 char *plain_str = _elm_util_mkup_to_text(str);
1120 if (!plain_str) return 0;
1122 len = strlen(plain_str);
1129 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1131 Widget_Data *wd = elm_widget_data_get(data);
1133 wd->changed = EINA_TRUE;
1135 if (wd->text) eina_stringshare_del(wd->text);
1137 _check_enable_returnkey(data);
1138 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1139 if (wd->delay_write)
1141 ecore_timer_del(wd->delay_write);
1142 wd->delay_write = NULL;
1144 if ((!wd->autosave) || (!wd->file)) return;
1145 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1149 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1151 Widget_Data *wd = elm_widget_data_get(data);
1152 elm_object_scroll_freeze_push(data);
1154 if ((wd->api) && (wd->api->obj_hidemenu))
1156 wd->api->obj_hidemenu(data);
1161 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1163 Widget_Data *wd = elm_widget_data_get(data);
1164 elm_object_scroll_freeze_pop(data);
1166 if (wd->have_selection)
1171 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1174 Widget_Data *wd = elm_widget_data_get(data);
1182 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1184 Widget_Data *wd = elm_widget_data_get(data);
1188 EINA_LIST_FOREACH(entries, l, entry)
1190 if (entry != data) elm_entry_select_none(entry);
1192 wd->have_selection = EINA_TRUE;
1193 wd->selmode = EINA_TRUE;
1194 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1195 #ifdef HAVE_ELEMENTARY_X
1196 if (wd->sel_notify_handler)
1198 const char *txt = elm_entry_selection_get(data);
1201 top = elm_widget_top_get(data);
1202 if ((top) && (elm_win_xwindow_get(top)))
1203 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1209 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1211 Evas_Coord cx, cy, cw, ch;
1212 Widget_Data *wd = elm_widget_data_get(data);
1214 wd->have_selection = EINA_TRUE;
1215 wd->selmode = EINA_TRUE;
1216 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1217 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1218 elm_entry_selection_get(data));
1220 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1221 if (!wd->deferred_recalc_job)
1222 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get());
1225 wd->deferred_cur = EINA_TRUE;
1229 wd->ch = ch + elm_finger_size_get();
1234 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1236 Widget_Data *wd = elm_widget_data_get(data);
1238 if (!wd->have_selection) return;
1239 wd->have_selection = EINA_FALSE;
1240 wd->selmode = EINA_FALSE;
1241 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1242 if (wd->sel_notify_handler)
1246 #ifdef HAVE_ELEMENTARY_X
1249 top = elm_widget_top_get(data);
1250 if ((top) && (elm_win_xwindow_get(top)))
1251 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1254 eina_stringshare_del(wd->cut_sel);
1259 #ifdef HAVE_ELEMENTARY_X
1262 top = elm_widget_top_get(data);
1263 if ((top) && (elm_win_xwindow_get(top)))
1264 elm_selection_clear(ELM_SEL_PRIMARY, data);
1271 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1273 Widget_Data *wd = elm_widget_data_get(data);
1275 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1276 if (wd->sel_notify_handler)
1278 #ifdef HAVE_ELEMENTARY_X
1281 top = elm_widget_top_get(data);
1282 if ((top) && (elm_win_xwindow_get(top)))
1284 wd->selection_asked = EINA_TRUE;
1285 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1293 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1295 Widget_Data *wd = elm_widget_data_get(data);
1297 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1298 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1299 elm_entry_selection_get(data));
1303 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1305 Widget_Data *wd = elm_widget_data_get(data);
1307 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1308 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1309 elm_entry_selection_get(data));
1310 edje_object_part_text_insert(wd->ent, "elm.text", "");
1311 wd->changed = EINA_TRUE;
1316 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1318 Widget_Data *wd = elm_widget_data_get(data);
1319 Evas_Coord cx, cy, cw, ch;
1321 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1322 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1323 &cx, &cy, &cw, &ch);
1324 if (!wd->deferred_recalc_job)
1325 elm_widget_show_region_set(data, cx, cy, cw, ch);
1328 wd->deferred_cur = EINA_TRUE;
1337 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1339 Widget_Data *wd = elm_widget_data_get(data);
1344 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1346 Widget_Data *wd = elm_widget_data_get(data);
1347 Elm_Entry_Anchor_Info ei;
1348 char *buf2, *p, *p2, *n;
1350 p = strrchr(emission, ',');
1353 const Eina_List *geoms;
1357 while (p2 >= emission)
1359 if (*p2 == ',') break;
1363 buf2 = alloca(5 + p - p2);
1364 strncpy(buf2, p2, p - p2);
1367 ei.button = atoi(buf2);
1368 ei.x = ei.y = ei.w = ei.h = 0;
1370 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1373 Evas_Textblock_Rectangle *r;
1375 Evas_Coord px, py, x, y;
1377 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1378 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1379 EINA_LIST_FOREACH(geoms, l, r)
1381 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1382 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1393 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1398 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1400 Widget_Data *wd = elm_widget_data_get(data);
1405 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1407 Widget_Data *wd = elm_widget_data_get(data);
1412 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1414 Widget_Data *wd = elm_widget_data_get(data);
1419 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1421 Widget_Data *wd = elm_widget_data_get(data);
1423 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1427 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1429 Widget_Data *wd = elm_widget_data_get(data);
1431 wd->double_clicked = EINA_FALSE;
1432 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1434 if ((wd->api) && (wd->api->obj_hidemenu))
1436 wd->api->obj_hidemenu(data);
1441 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1443 Widget_Data *wd = elm_widget_data_get(data);
1445 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1449 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1451 Widget_Data *wd = elm_widget_data_get(data);
1453 wd->double_clicked = EINA_TRUE;
1454 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1457 #ifdef HAVE_ELEMENTARY_X
1459 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1461 Widget_Data *wd = elm_widget_data_get(data);
1462 Ecore_X_Event_Selection_Notify *ev = event;
1463 if (!wd) return ECORE_CALLBACK_PASS_ON;
1464 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1465 return ECORE_CALLBACK_PASS_ON;
1467 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1468 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1470 Ecore_X_Selection_Data_Text *text_data;
1472 text_data = ev->data;
1473 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1475 if (text_data->text)
1477 char *txt = _elm_util_text_to_mkup(text_data->text);
1481 elm_entry_entry_insert(data, txt);
1486 wd->selection_asked = EINA_FALSE;
1488 else if (ev->selection == ECORE_X_SELECTION_XDND)
1490 Ecore_X_Selection_Data_Text *text_data;
1492 text_data = ev->data;
1493 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1495 if (text_data->text)
1497 char *txt = _elm_util_text_to_mkup(text_data->text);
1501 /* Massive FIXME: this should be at the drag point */
1502 elm_entry_entry_insert(data, txt);
1507 wd->drag_selection_asked = EINA_FALSE;
1509 ecore_x_dnd_send_finished();
1512 return ECORE_CALLBACK_PASS_ON;
1516 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1519 Widget_Data *wd = elm_widget_data_get(data);
1520 Ecore_X_Event_Selection_Clear *ev = event;
1521 if (!wd) return ECORE_CALLBACK_PASS_ON;
1522 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1523 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1524 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1526 elm_entry_select_none(data);
1531 Evas_Object *top = elm_widget_top_get(data);
1532 Ecore_X_Event_Selection_Clear *ev = event;
1535 return ECORE_CALLBACK_PASS_ON;
1537 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1539 return ECORE_CALLBACK_PASS_ON;
1542 if (cnpwidgetdata == data)
1544 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
1548 return ECORE_CALLBACK_PASS_ON;
1553 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1558 wd = elm_widget_data_get(obj);
1560 if (!wd) return EINA_FALSE;
1561 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1563 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1564 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1565 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1566 EDJE_CURSOR_MAIN,drop->x,drop->y);
1567 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1568 elm_entry_entry_insert(obj, drop->data);
1569 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1570 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1576 static Evas_Object *
1577 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1579 Widget_Data *wd = elm_widget_data_get(data);
1582 Elm_Entry_Item_Provider *ip;
1584 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1586 o = ip->func(ip->data, data, item);
1589 if (!strncmp(item, "file://", 7))
1591 const char *fname = item + 7;
1593 o = evas_object_image_filled_add(evas_object_evas_get(data));
1594 evas_object_image_file_set(o, fname, NULL);
1595 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1597 evas_object_show(o);
1602 o = edje_object_add(evas_object_evas_get(data));
1603 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1607 o = edje_object_add(evas_object_evas_get(data));
1608 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1609 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1614 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1616 char *curlocater, *starttag, *endtag;
1617 int firstindex = 0, foundflag = -1;
1619 curlocater = strstr(oldstring, key);
1622 starttag = curlocater;
1623 endtag = curlocater + strlen(key);
1624 if (endtag == NULL || *endtag != '=')
1630 firstindex = abs(oldstring - curlocater);
1631 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1632 *value = (char*)(oldstring + firstindex);
1634 while (oldstring != starttag)
1636 if (*starttag == '>')
1641 if (*starttag == '<')
1645 if (starttag == NULL) break;
1648 while (NULL != endtag)
1659 if (endtag == NULL) break;
1662 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1672 if (foundflag == 1) return 0;
1678 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1680 const char *srcstring = NULL;
1681 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1682 char *curlocater, *replocater;
1683 char *starttag, *endtag;
1684 int tagtxtlen = 0, insertflag = 0;
1686 srcstring = eina_strbuf_string_get(srcbuf);
1687 curlocater = strstr(srcstring, key);
1689 if (!curlocater || !srcstring)
1697 starttag = strchr(srcstring, '<');
1698 endtag = strchr(srcstring, '>');
1699 tagtxtlen = endtag - starttag;
1700 if (tagtxtlen <= 0) tagtxtlen = 0;
1701 if (starttag < curlocater && curlocater < endtag) break;
1702 if (endtag != NULL && endtag+1 != NULL)
1703 srcstring = endtag+1;
1706 } while (strlen(srcstring) > 1);
1708 if (starttag && endtag && tagtxtlen > strlen(key))
1710 repbuf = eina_strbuf_new();
1711 diffbuf = eina_strbuf_new();
1712 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1713 srcstring = eina_strbuf_string_get(repbuf);
1714 curlocater = strstr(srcstring, key);
1716 if (curlocater != NULL)
1718 replocater = curlocater + strlen(key) + 1;
1720 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
1723 if (replocater-curlocater > strlen(key)+1)
1725 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1734 eina_strbuf_reset(repbuf);
1742 if (repbuf == NULL) repbuf = eina_strbuf_new();
1743 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1747 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1748 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1754 eina_strbuf_prepend(diffbuf, "<");
1755 eina_strbuf_append(diffbuf, ">");
1756 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1760 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1761 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1765 if (repbuf) eina_strbuf_free(repbuf);
1766 if (diffbuf) eina_strbuf_free(diffbuf);
1772 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1774 Eina_Strbuf *sharebuf = NULL;
1776 sharebuf = eina_strbuf_new();
1777 eina_strbuf_append(sharebuf, *srcstring);
1778 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1779 eina_stringshare_del(*srcstring);
1780 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1781 eina_strbuf_free(sharebuf);
1787 _is_width_over(Evas_Object *obj)
1789 Evas_Coord x, y, w, h;
1790 Evas_Coord vx, vy, vw, vh;
1791 Widget_Data *wd = elm_widget_data_get(obj);
1795 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1797 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1799 if (x >= 0 && y >= 0)
1802 if (4 < wd->wrap_w && w > wd->wrap_w)
1809 _reverse_ellipsis_entry(Evas_Object *obj)
1811 Widget_Data *wd = elm_widget_data_get(obj);
1812 int cur_fontsize = 0;
1813 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1814 char *kvalue = NULL;
1815 const char *minfont, *deffont, *maxfont;
1816 const char *ellipsis_string = "...";
1817 int minfontsize, maxfontsize, minshowcount;
1819 minshowcount = strlen(ellipsis_string) + 1;
1820 minfont = edje_object_data_get(wd->ent, "min_font_size");
1821 if (minfont) minfontsize = atoi(minfont);
1822 else minfontsize = 1;
1823 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1824 if (maxfont) maxfontsize = atoi(maxfont);
1825 else maxfontsize = 1;
1826 deffont = edje_object_data_get(wd->ent, "default_font_size");
1827 if (deffont) cur_fontsize = atoi(deffont);
1828 else cur_fontsize = 1;
1829 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1830 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1832 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1834 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1837 txtbuf = eina_strbuf_new();
1838 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1840 if (cur_fontsize >= atoi(deffont))
1842 if (txtbuf) eina_strbuf_free(txtbuf);
1846 if (_is_width_over(obj) != 1)
1848 int rev_fontsize = cur_fontsize;
1852 if (rev_fontsize > atoi(deffont))
1855 if (fontbuf != NULL)
1857 eina_strbuf_free(fontbuf);
1860 fontbuf = eina_strbuf_new();
1861 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1862 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1863 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1865 eina_strbuf_free(fontbuf);
1867 } while (_is_width_over(obj) != 1);
1869 while (_is_width_over(obj))
1872 if (rev_fontsize < atoi(deffont))
1875 if (fontbuf != NULL)
1877 eina_strbuf_free(fontbuf);
1880 fontbuf = eina_strbuf_new();
1881 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1882 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1883 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1884 eina_strbuf_free(fontbuf);
1889 if (txtbuf) eina_strbuf_free(txtbuf);
1895 _ellipsis_entry_to_width(Evas_Object *obj)
1897 Widget_Data *wd = elm_widget_data_get(obj);
1898 int cur_fontsize = 0, len, jumpcount;
1899 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1900 char *kvalue = NULL;
1901 const char *minfont, *deffont, *maxfont;
1902 const char *ellipsis_string = "...";
1903 int minfontsize, maxfontsize, minshowcount;
1904 int i, tagend, cur_len;
1907 minshowcount = strlen(ellipsis_string) + 1;
1908 minfont = edje_object_data_get(wd->ent, "min_font_size");
1909 if (minfont) minfontsize = atoi(minfont);
1910 else minfontsize = 1;
1911 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1912 if (maxfont) maxfontsize = atoi(maxfont);
1913 else maxfontsize = 1;
1914 deffont = edje_object_data_get(wd->ent, "default_font_size");
1915 if (deffont) cur_fontsize = atoi(deffont);
1916 else cur_fontsize = 1;
1917 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1918 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1920 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1922 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1925 txtbuf = eina_strbuf_new();
1926 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1928 while (_is_width_over(obj))
1930 if (wd->ellipsis_threshold == 0)
1931 wd->ellipsis_threshold = _entry_length_get(obj);
1932 if (cur_fontsize > minfontsize)
1935 if (fontbuf != NULL)
1937 eina_strbuf_free(fontbuf);
1940 fontbuf = eina_strbuf_new();
1941 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1942 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1943 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1944 eina_strbuf_free(fontbuf);
1946 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1950 len = _entry_length_get(obj);
1951 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1952 cur_len = strlen(cur_str);
1954 for (i = 0; i < len; i++)
1956 if(cur_str[i] == '>' && cur_str[i+1] != '\0' &&
1957 cur_str[i+1] != '<')
1964 while (jumpcount < len-strlen(ellipsis_string))
1966 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1970 eina_strbuf_free(txtbuf);
1973 txtbuf = eina_strbuf_new();
1974 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1975 eina_strbuf_append(txtbuf, ellipsis_string);
1976 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1977 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1978 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1980 if (_is_width_over(obj))
1988 if (txtbuf) eina_strbuf_free(txtbuf);
1993 static Eina_Bool *_textinput_control_function(void *data,void *input_data)
1995 /* calculate character count */
1996 Evas_Object *entry = (Evas_Object *)data;
1997 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
2000 size_t insert_text_len=0;
2001 char *text = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2003 size_t remain_bytes;
2006 byte_len = strlen(text); /* no of bytes */
2007 remain_bytes = wd->max_no_of_bytes - byte_len;
2008 sprintf(buf,"%d",remain_bytes);
2009 //edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
2012 insert_text = (char *)input_data;
2013 insert_text_len = strlen(insert_text);
2014 if (remain_bytes < insert_text_len)
2016 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2019 if (byte_len >= wd->max_no_of_bytes)
2021 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2031 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2033 Widget_Data *wd = elm_widget_data_get(data);
2035 Elm_Entry_Text_Filter *tf;
2037 if (type == EDJE_TEXT_FILTER_FORMAT)
2040 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2042 tf->func(tf->data, data, text);
2049 * This adds an entry to @p parent object.
2051 * @param parent The parent object
2052 * @return The new object or NULL if it cannot be created
2057 elm_entry_add(Evas_Object *parent)
2059 Evas_Object *obj, *top;
2063 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2065 wd = ELM_NEW(Widget_Data);
2066 e = evas_object_evas_get(parent);
2067 if (!e) return NULL;
2068 wd->bgcolor = EINA_FALSE;
2069 wd->bg = evas_object_rectangle_add(e);
2070 evas_object_color_set(wd->bg, 0, 0, 0, 0);
2071 obj = elm_widget_add(e);
2072 ELM_SET_WIDTYPE(widtype, "entry");
2073 elm_widget_type_set(obj, "entry");
2074 elm_widget_sub_object_add(parent, obj);
2075 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2076 elm_widget_data_set(obj, wd);
2077 elm_widget_del_hook_set(obj, _del_hook);
2078 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2079 elm_widget_theme_hook_set(obj, _theme_hook);
2080 elm_widget_disable_hook_set(obj, _disable_hook);
2081 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2082 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2083 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2084 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2085 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2086 elm_widget_can_focus_set(obj, EINA_TRUE);
2087 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2089 wd->linewrap = EINA_TRUE;
2090 wd->ellipsis = EINA_FALSE;
2091 wd->char_linewrap= EINA_FALSE;
2092 wd->editable = EINA_TRUE;
2093 wd->disabled = EINA_FALSE;
2094 wd->context_menu = EINA_TRUE;
2095 wd->autosave = EINA_TRUE;
2096 wd->autoperiod = EINA_TRUE;
2098 wd->ellipsis_threshold = 0;
2100 wd->ent = edje_object_add(e);
2101 edje_object_item_provider_set(wd->ent, _get_item, obj);
2102 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2103 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2104 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2105 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2107 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2109 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2112 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2113 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2114 _signal_entry_changed, obj);
2115 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2116 _signal_handler_move_start, obj);
2117 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2118 _signal_handler_move_end, obj);
2119 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2120 _signal_selection_start, obj);
2121 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2122 _signal_selection_end, obj);
2123 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2124 _signal_selection_changed, obj);
2125 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2126 _signal_selection_cleared, obj);
2127 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2128 _signal_entry_paste_request, obj);
2129 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2130 _signal_entry_copy_notify, obj);
2131 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2132 _signal_entry_cut_notify, obj);
2133 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2134 _signal_cursor_changed, obj);
2135 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2136 _signal_anchor_down, obj);
2137 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2138 _signal_anchor_up, obj);
2139 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2140 _signal_anchor_move, obj);
2141 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2142 _signal_anchor_in, obj);
2143 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2144 _signal_anchor_out, obj);
2145 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2146 _signal_key_enter, obj);
2147 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2148 _signal_mouse_down, obj);
2149 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2150 _signal_mouse_clicked, obj);
2151 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2152 _signal_mouse_double, obj);
2153 edje_object_part_text_set(wd->ent, "elm.text", "");
2154 elm_widget_resize_object_set(obj, wd->ent);
2157 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2159 #ifdef HAVE_ELEMENTARY_X
2160 top = elm_widget_top_get(obj);
2161 if ((top) && (elm_win_xwindow_get(top)))
2163 wd->sel_notify_handler =
2164 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2165 _event_selection_notify, obj);
2166 wd->sel_clear_handler =
2167 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2168 _event_selection_clear, obj);
2171 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2174 entries = eina_list_prepend(entries, obj);
2176 // module - find module for entry
2177 wd->api = _module(obj);
2178 // if found - hook in
2179 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2181 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2182 // TODO: and save some bytes, making descriptions per-class and not instance!
2183 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2187 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2189 ELM_CHECK_WIDTYPE(obj, widtype);
2190 Widget_Data *wd = elm_widget_data_get(obj);
2192 ext_mod->cancel = _cancel;
2193 ext_mod->copy = _copy;
2194 ext_mod->cut = _cut;
2195 ext_mod->paste = _paste;
2196 ext_mod->select = _select;
2197 ext_mod->selectall = _selectall;
2198 ext_mod->ent = wd->ent;
2199 ext_mod->items = wd->items;
2200 ext_mod->longpress_timer = wd->longpress_timer;
2201 ext_mod->editable = wd->editable;
2202 ext_mod->have_selection = wd->have_selection;
2203 ext_mod->password = wd->password;
2204 ext_mod->selmode = wd->selmode;
2205 ext_mod->cnpinit = _cnpinit;
2206 ext_mod->context_menu = wd->context_menu;
2210 * This sets the entry object not to line wrap. All input will
2211 * be on a single line, and the entry box will extend with user input.
2213 * @param obj The entry object
2214 * @param single_line If true, the text in the entry
2215 * will be on a single line.
2220 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2222 ELM_CHECK_WIDTYPE(obj, widtype);
2223 Widget_Data *wd = elm_widget_data_get(obj);
2225 Ecore_IMF_Context *ic;
2227 if (wd->single_line == single_line) return;
2228 wd->single_line = single_line;
2229 wd->linewrap = EINA_FALSE;
2230 wd->char_linewrap = EINA_FALSE;
2231 t = eina_stringshare_add(elm_entry_entry_get(obj));
2232 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2233 elm_entry_entry_set(obj, t);
2234 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2235 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2236 ic = elm_entry_imf_context_get(obj);
2239 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2242 eina_stringshare_del(t);
2247 * This returns true if the entry has been set to single line mode.
2248 * See also elm_entry_single_line_set().
2250 * @param obj The entry object
2251 * @return single_line If true, the text in the entry is set to display
2257 elm_entry_single_line_get(const Evas_Object *obj)
2259 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2260 Widget_Data *wd = elm_widget_data_get(obj);
2261 if (!wd) return EINA_FALSE;
2262 return wd->single_line;
2266 * This set's the maximum bytes that can be added in entry.
2268 * @param obj The entry object
2269 * @param max_no_of_bytes Maximum number of bytes entry can have.
2274 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2276 Widget_Data *wd = elm_widget_data_get(obj);
2278 wd->max_no_of_bytes = max_no_of_bytes;
2279 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2284 * This sets the entry object to password mode. All text entered
2285 * and/or displayed within the widget will be replaced with asterisks (*).
2287 * @param obj The entry object
2288 * @param password If true, password mode is enabled.
2293 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2295 ELM_CHECK_WIDTYPE(obj, widtype);
2296 Widget_Data *wd = elm_widget_data_get(obj);
2297 Ecore_IMF_Context *ic;
2300 if (wd->password == password) return;
2301 wd->password = password;
2302 wd->single_line = EINA_TRUE;
2303 wd->linewrap = EINA_FALSE;
2304 wd->char_linewrap = EINA_FALSE;
2305 if (_elm_config->password_show_last_character)
2306 wd->show_last_character = EINA_TRUE;
2307 t = eina_stringshare_add(elm_entry_entry_get(obj));
2308 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2309 elm_entry_entry_set(obj, t);
2314 elm_entry_autoperiod_set(obj, EINA_FALSE);
2316 if (wd->autocapital)
2317 elm_entry_autocapitalization_set(obj, EINA_FALSE);
2320 ic = elm_entry_imf_context_get(obj);
2322 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2324 eina_stringshare_del(t);
2330 * This returns whether password mode is enabled.
2331 * See also elm_entry_password_set().
2333 * @param obj The entry object
2334 * @return If true, the entry is set to display all characters
2340 elm_entry_password_get(const Evas_Object *obj)
2342 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2343 Widget_Data *wd = elm_widget_data_get(obj);
2344 if (!wd) return EINA_FALSE;
2345 return wd->password;
2349 * This sets the text displayed within the entry to @p entry.
2351 * @param obj The entry object
2352 * @param entry The text to be displayed
2357 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2359 ELM_CHECK_WIDTYPE(obj, widtype);
2360 Widget_Data *wd = elm_widget_data_get(obj);
2362 if (!entry) entry = "";
2363 if(wd->max_no_of_bytes)
2365 int len = strlen(entry);
2366 if(len > wd->max_no_of_bytes)
2368 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2372 edje_object_part_text_set(wd->ent, "elm.text", entry);
2373 if (wd->text) eina_stringshare_del(wd->text);
2375 wd->changed = EINA_TRUE;
2380 * This returns the text currently shown in object @p entry.
2381 * See also elm_entry_entry_set().
2383 * @param obj The entry object
2384 * @return The currently displayed text or NULL on failure
2389 elm_entry_entry_get(const Evas_Object *obj)
2391 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2392 Widget_Data *wd = elm_widget_data_get(obj);
2394 if (!wd) return NULL;
2396 if ((wd->text)&&(wd->password))
2397 return elm_entry_markup_to_utf8(wd->text);
2399 if (wd->text) return wd->text;
2400 text = edje_object_part_text_get(wd->ent, "elm.text");
2403 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2406 eina_stringshare_replace(&wd->text, text);
2407 if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2412 * This returns all selected text within the entry.
2414 * @param obj The entry object
2415 * @return The selected text within the entry or NULL on failure
2420 elm_entry_selection_get(const Evas_Object *obj)
2422 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2423 Widget_Data *wd = elm_widget_data_get(obj);
2424 if (!wd) return NULL;
2425 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2429 * This inserts text in @p entry where the current cursor position.
2431 * This inserts text at the cursor position is as if it was typed
2432 * by the user (note this also allows markup which a user
2433 * can't just "type" as it would be converted to escaped text, so this
2434 * call can be used to insert things like emoticon items or bold push/pop
2435 * tags, other font and color change tags etc.)
2437 * @param obj The entry object
2438 * @param entry The text to insert
2443 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2445 ELM_CHECK_WIDTYPE(obj, widtype);
2446 Widget_Data *wd = elm_widget_data_get(obj);
2448 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2450 if (cnpwidgetdata == obj)
2451 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2453 wd->changed = EINA_TRUE;
2458 * This enables word line wrapping in the entry object. It is the opposite
2459 * of elm_entry_single_line_set(). Additionally, setting this disables
2460 * character line wrapping.
2461 * See also elm_entry_line_char_wrap_set().
2463 * @param obj The entry object
2464 * @param wrap If true, the entry will be wrapped once it reaches the end
2465 * of the object. Wrapping will occur at the end of the word before the end of the
2471 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2473 ELM_CHECK_WIDTYPE(obj, widtype);
2474 Widget_Data *wd = elm_widget_data_get(obj);
2477 if (wd->linewrap == wrap) return;
2478 wd->linewrap = wrap;
2480 wd->char_linewrap = EINA_FALSE;
2481 t = eina_stringshare_add(elm_entry_entry_get(obj));
2482 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2483 elm_entry_entry_set(obj, t);
2484 eina_stringshare_del(t);
2489 * Set wrap width of the entry
2491 * @param obj The entry object
2492 * @param w The wrap width in pixels at a minimum where words need to wrap
2496 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2498 Widget_Data *wd = elm_widget_data_get(obj);
2499 if (wd->wrap_w == w) return;
2505 * get wrap width of the entry
2507 * @param obj The entry object
2508 * @return The wrap width in pixels at a minimum where words need to wrap
2512 elm_entry_wrap_width_get(const Evas_Object *obj)
2514 Widget_Data *wd = elm_widget_data_get(obj);
2519 * This enables character line wrapping in the entry object. It is the opposite
2520 * of elm_entry_single_line_set(). Additionally, setting this disables
2521 * word line wrapping.
2522 * See also elm_entry_line_wrap_set().
2524 * @param obj The entry object
2525 * @param wrap If true, the entry will be wrapped once it reaches the end
2526 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2531 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2533 ELM_CHECK_WIDTYPE(obj, widtype);
2534 Widget_Data *wd = elm_widget_data_get(obj);
2537 if (wd->char_linewrap == wrap) return;
2538 wd->char_linewrap = wrap;
2539 if(wd->char_linewrap)
2540 wd->linewrap = EINA_FALSE;
2541 t = eina_stringshare_add(elm_entry_entry_get(obj));
2542 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2543 elm_entry_entry_set(obj, t);
2544 eina_stringshare_del(t);
2549 * This sets the editable attribute of the entry.
2551 * @param obj The entry object
2552 * @param editable If true, the entry will be editable by the user.
2553 * If false, it will be set to the disabled state.
2558 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2560 ELM_CHECK_WIDTYPE(obj, widtype);
2561 Widget_Data *wd = elm_widget_data_get(obj);
2564 if (wd->editable == editable) return;
2565 wd->editable = editable;
2566 t = eina_stringshare_add(elm_entry_entry_get(obj));
2567 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2568 elm_entry_entry_set(obj, t);
2569 eina_stringshare_del(t);
2572 #ifdef HAVE_ELEMENTARY_X
2574 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2576 elm_drop_target_del(obj);
2581 * This gets the editable attribute of the entry.
2582 * See also elm_entry_editable_set().
2584 * @param obj The entry object
2585 * @return If true, the entry is editable by the user.
2586 * If false, it is not editable by the user
2591 elm_entry_editable_get(const Evas_Object *obj)
2593 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2594 Widget_Data *wd = elm_widget_data_get(obj);
2595 if (!wd) return EINA_FALSE;
2596 return wd->editable;
2600 * This drops any existing text selection within the entry.
2602 * @param obj The entry object
2607 elm_entry_select_none(Evas_Object *obj)
2609 ELM_CHECK_WIDTYPE(obj, widtype);
2610 Widget_Data *wd = elm_widget_data_get(obj);
2614 wd->selmode = EINA_FALSE;
2615 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2616 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2618 wd->have_selection = EINA_FALSE;
2619 edje_object_part_text_select_none(wd->ent, "elm.text");
2623 * This selects all text within the entry.
2625 * @param obj The entry object
2630 elm_entry_select_all(Evas_Object *obj)
2632 ELM_CHECK_WIDTYPE(obj, widtype);
2633 Widget_Data *wd = elm_widget_data_get(obj);
2637 wd->selmode = EINA_FALSE;
2638 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2639 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2641 wd->have_selection = EINA_TRUE;
2642 edje_object_part_text_select_all(wd->ent, "elm.text");
2646 * This moves the cursor one place to the right within the entry.
2648 * @param obj The entry object
2649 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2654 elm_entry_cursor_next(Evas_Object *obj)
2656 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2657 Widget_Data *wd = elm_widget_data_get(obj);
2658 if (!wd) return EINA_FALSE;
2659 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2663 * This moves the cursor one place to the left within the entry.
2665 * @param obj The entry object
2666 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2671 elm_entry_cursor_prev(Evas_Object *obj)
2673 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2674 Widget_Data *wd = elm_widget_data_get(obj);
2675 if (!wd) return EINA_FALSE;
2676 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2680 * This moves the cursor one line up within the entry.
2682 * @param obj The entry object
2683 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2688 elm_entry_cursor_up(Evas_Object *obj)
2690 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2691 Widget_Data *wd = elm_widget_data_get(obj);
2692 if (!wd) return EINA_FALSE;
2693 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2697 * This moves the cursor one line down within the entry.
2699 * @param obj The entry object
2700 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2705 elm_entry_cursor_down(Evas_Object *obj)
2707 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2708 Widget_Data *wd = elm_widget_data_get(obj);
2709 if (!wd) return EINA_FALSE;
2710 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2714 * This moves the cursor to the beginning of the entry.
2716 * @param obj The entry object
2721 elm_entry_cursor_begin_set(Evas_Object *obj)
2723 ELM_CHECK_WIDTYPE(obj, widtype);
2724 Widget_Data *wd = elm_widget_data_get(obj);
2726 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2730 * This moves the cursor to the end of the entry.
2732 * @param obj The entry object
2737 elm_entry_cursor_end_set(Evas_Object *obj)
2739 ELM_CHECK_WIDTYPE(obj, widtype);
2740 Widget_Data *wd = elm_widget_data_get(obj);
2742 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2746 * This moves the cursor to the beginning of the current line.
2748 * @param obj The entry object
2753 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2755 ELM_CHECK_WIDTYPE(obj, widtype);
2756 Widget_Data *wd = elm_widget_data_get(obj);
2758 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2762 * This moves the cursor to the end of the current line.
2764 * @param obj The entry object
2769 elm_entry_cursor_line_end_set(Evas_Object *obj)
2771 ELM_CHECK_WIDTYPE(obj, widtype);
2772 Widget_Data *wd = elm_widget_data_get(obj);
2774 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2778 * This begins a selection within the entry as though
2779 * the user were holding down the mouse button to make a selection.
2781 * @param obj The entry object
2786 elm_entry_cursor_selection_begin(Evas_Object *obj)
2788 ELM_CHECK_WIDTYPE(obj, widtype);
2789 Widget_Data *wd = elm_widget_data_get(obj);
2791 edje_object_part_text_select_begin(wd->ent, "elm.text");
2795 * This ends a selection within the entry as though
2796 * the user had just released the mouse button while making a selection.
2798 * @param obj The entry object
2803 elm_entry_cursor_selection_end(Evas_Object *obj)
2805 ELM_CHECK_WIDTYPE(obj, widtype);
2806 Widget_Data *wd = elm_widget_data_get(obj);
2808 edje_object_part_text_select_extend(wd->ent, "elm.text");
2812 * TODO: fill this in
2814 * @param obj The entry object
2815 * @return TODO: fill this in
2820 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2822 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2823 Widget_Data *wd = elm_widget_data_get(obj);
2824 if (!wd) return EINA_FALSE;
2825 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2829 * This returns whether the cursor is visible.
2831 * @param obj The entry object
2832 * @return If true, the cursor is visible.
2837 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2839 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2840 Widget_Data *wd = elm_widget_data_get(obj);
2841 if (!wd) return EINA_FALSE;
2842 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2846 * TODO: fill this in
2848 * @param obj The entry object
2849 * @return TODO: fill this in
2854 elm_entry_cursor_content_get(const Evas_Object *obj)
2856 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2857 Widget_Data *wd = elm_widget_data_get(obj);
2858 if (!wd) return NULL;
2859 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2863 * This executes a "cut" action on the selected text in the entry.
2865 * @param obj The entry object
2870 elm_entry_selection_cut(Evas_Object *obj)
2872 ELM_CHECK_WIDTYPE(obj, widtype);
2873 Widget_Data *wd = elm_widget_data_get(obj);
2875 _cut(obj, NULL, NULL);
2879 * This executes a "copy" action on the selected text in the entry.
2881 * @param obj The entry object
2886 elm_entry_selection_copy(Evas_Object *obj)
2888 ELM_CHECK_WIDTYPE(obj, widtype);
2889 Widget_Data *wd = elm_widget_data_get(obj);
2891 _copy(obj, NULL, NULL);
2895 * This executes a "paste" action in the entry.
2897 * @param obj The entry object
2902 elm_entry_selection_paste(Evas_Object *obj)
2904 ELM_CHECK_WIDTYPE(obj, widtype);
2905 Widget_Data *wd = elm_widget_data_get(obj);
2907 _paste(obj, NULL, NULL);
2911 * This clears and frees the items in a entry's contextual (right click) menu.
2913 * @param obj The entry object
2918 elm_entry_context_menu_clear(Evas_Object *obj)
2920 ELM_CHECK_WIDTYPE(obj, widtype);
2921 Widget_Data *wd = elm_widget_data_get(obj);
2922 Elm_Entry_Context_Menu_Item *it;
2924 EINA_LIST_FREE(wd->items, it)
2926 eina_stringshare_del(it->label);
2927 eina_stringshare_del(it->icon_file);
2928 eina_stringshare_del(it->icon_group);
2934 * This adds an item to the entry's contextual menu.
2936 * @param obj The entry object
2937 * @param label The item's text label
2938 * @param icon_file The item's icon file
2939 * @param icon_type The item's icon type
2940 * @param func The callback to execute when the item is clicked
2941 * @param data The data to associate with the item for related functions
2946 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)
2948 ELM_CHECK_WIDTYPE(obj, widtype);
2949 Widget_Data *wd = elm_widget_data_get(obj);
2950 Elm_Entry_Context_Menu_Item *it;
2952 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2954 wd->items = eina_list_append(wd->items, it);
2956 it->label = eina_stringshare_add(label);
2957 it->icon_file = eina_stringshare_add(icon_file);
2958 it->icon_type = icon_type;
2960 it->data = (void *)data;
2964 * This disables the entry's contextual (right click) menu.
2966 * @param obj The entry object
2967 * @param disabled If true, the menu is disabled
2972 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2974 ELM_CHECK_WIDTYPE(obj, widtype);
2975 Widget_Data *wd = elm_widget_data_get(obj);
2977 if (wd->context_menu == !disabled) return;
2978 wd->context_menu = !disabled;
2982 * This returns whether the entry's contextual (right click) menu is disabled.
2984 * @param obj The entry object
2985 * @return If true, the menu is disabled
2990 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2992 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2993 Widget_Data *wd = elm_widget_data_get(obj);
2994 if (!wd) return EINA_FALSE;
2995 return !wd->context_menu;
2999 * This appends a custom item provider to the list for that entry
3001 * This appends the given callback. The list is walked from beginning to end
3002 * with each function called given the item href string in the text. If the
3003 * function returns an object handle other than NULL (it should create an
3004 * and object to do this), then this object is used to replace that item. If
3005 * not the next provider is called until one provides an item object, or the
3006 * default provider in entry does.
3008 * @param obj The entry object
3009 * @param func The function called to provide the item object
3010 * @param data The data passed to @p func
3015 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3017 ELM_CHECK_WIDTYPE(obj, widtype);
3018 Widget_Data *wd = elm_widget_data_get(obj);
3020 EINA_SAFETY_ON_NULL_RETURN(func);
3021 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3025 wd->item_providers = eina_list_append(wd->item_providers, ip);
3029 * This prepends a custom item provider to the list for that entry
3031 * This prepends the given callback. See elm_entry_item_provider_append() for
3034 * @param obj The entry object
3035 * @param func The function called to provide the item object
3036 * @param data The data passed to @p func
3041 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3043 ELM_CHECK_WIDTYPE(obj, widtype);
3044 Widget_Data *wd = elm_widget_data_get(obj);
3046 EINA_SAFETY_ON_NULL_RETURN(func);
3047 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3051 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3055 * This removes a custom item provider to the list for that entry
3057 * This removes the given callback. See elm_entry_item_provider_append() for
3060 * @param obj The entry object
3061 * @param func The function called to provide the item object
3062 * @param data The data passed to @p func
3067 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3069 ELM_CHECK_WIDTYPE(obj, widtype);
3070 Widget_Data *wd = elm_widget_data_get(obj);
3072 Elm_Entry_Item_Provider *ip;
3074 EINA_SAFETY_ON_NULL_RETURN(func);
3075 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3077 if ((ip->func == func) && (ip->data == data))
3079 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3087 * Append a filter function for text inserted in the entry
3089 * Append the given callback to the list. This functions will be called
3090 * whenever any text is inserted into the entry, with the text to be inserted
3091 * as a parameter. The callback function is free to alter the text in any way
3092 * it wants, but it must remember to free the given pointer and update it.
3093 * If the new text is to be discarded, the function can free it and set it text
3094 * parameter to NULL. This will also prevent any following filters from being
3097 * @param obj The entry object
3098 * @param func The function to use as text filter
3099 * @param data User data to pass to @p func
3104 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3107 Elm_Entry_Text_Filter *tf;
3108 ELM_CHECK_WIDTYPE(obj, widtype);
3110 wd = elm_widget_data_get(obj);
3112 EINA_SAFETY_ON_NULL_RETURN(func);
3114 tf = ELM_NEW(Elm_Entry_Text_Filter);
3118 wd->text_filters = eina_list_append(wd->text_filters, tf);
3122 * Prepend a filter function for text insdrted in the entry
3124 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3125 * for more information
3127 * @param obj The entry object
3128 * @param func The function to use as text filter
3129 * @param data User data to pass to @p func
3134 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3137 Elm_Entry_Text_Filter *tf;
3138 ELM_CHECK_WIDTYPE(obj, widtype);
3140 wd = elm_widget_data_get(obj);
3142 EINA_SAFETY_ON_NULL_RETURN(func);
3144 tf = ELM_NEW(Elm_Entry_Text_Filter);
3148 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3152 * Remove a filter from the list
3154 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3155 * for more information.
3157 * @param obj The entry object
3158 * @param func The filter function to remove
3159 * @param data The user data passed when adding the function
3164 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3168 Elm_Entry_Text_Filter *tf;
3169 ELM_CHECK_WIDTYPE(obj, widtype);
3171 wd = elm_widget_data_get(obj);
3173 EINA_SAFETY_ON_NULL_RETURN(func);
3175 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3177 if ((tf->func == func) && (tf->data == data))
3179 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3187 * This converts a markup (HTML-like) string into UTF-8.
3189 * @param s The string (in markup) to be converted
3190 * @return The converted string (in UTF-8)
3195 elm_entry_markup_to_utf8(const char *s)
3197 char *ss = _elm_util_mkup_to_text(s);
3198 if (!ss) ss = strdup("");
3203 * This converts a UTF-8 string into markup (HTML-like).
3205 * @param s The string (in UTF-8) to be converted
3206 * @return The converted string (in markup)
3211 elm_entry_utf8_to_markup(const char *s)
3213 char *ss = _elm_util_text_to_mkup(s);
3214 if (!ss) ss = strdup("");
3219 * Get the input method context in the entry widget
3221 * @param obj The entry object
3222 * @return The input method context
3226 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3228 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3229 Widget_Data *wd = elm_widget_data_get(obj);
3230 if (!wd || !wd->ent) return NULL;
3232 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3236 * Set whether entry should enable the return key on soft keyboard automatically
3238 * @param obj The entry object
3239 * @param on If true, entry enables the return key on soft keyboard automatically.
3244 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3246 ELM_CHECK_WIDTYPE(obj, widtype);
3247 Widget_Data *wd = elm_widget_data_get(obj);
3250 wd->autoreturnkey = on;
3251 _check_enable_returnkey(obj);
3255 * Set whether entry should support auto capitalization
3257 * @param obj The entry object
3258 * @param on If true, entry suports auto capitalization.
3263 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3265 ELM_CHECK_WIDTYPE(obj, widtype);
3266 Widget_Data *wd = elm_widget_data_get(obj);
3270 wd->autocapital = EINA_FALSE;
3272 wd->autocapital = autocap;
3274 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3275 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3276 wd->autocapital = EINA_FALSE;
3278 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3282 * Set whether entry should support auto period
3284 * @param obj The entry object
3285 * @param on If true, entry suports auto period.
3290 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3292 ELM_CHECK_WIDTYPE(obj, widtype);
3293 Widget_Data *wd = elm_widget_data_get(obj);
3297 wd->autoperiod = EINA_FALSE;
3299 wd->autoperiod = autoperiod;
3301 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3302 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3303 wd->autoperiod = EINA_FALSE;
3305 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3309 * Set the font size on the entry object
3311 * @param obj The entry object
3312 * @param size font size
3317 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3319 ELM_CHECK_WIDTYPE(obj, widtype);
3320 Widget_Data *wd = elm_widget_data_get(obj);
3321 Eina_Strbuf *fontbuf = NULL;
3326 t = eina_stringshare_add(elm_entry_entry_get(obj));
3327 fontbuf = eina_strbuf_new();
3328 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3330 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3332 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3334 elm_entry_entry_set(obj, t);
3338 eina_strbuf_free(fontbuf);
3339 eina_stringshare_del(t);
3343 * Set the text align on the entry object
3345 * @param obj The entry object
3346 * @param align align mode
3351 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3353 ELM_CHECK_WIDTYPE(obj, widtype);
3354 Widget_Data *wd = elm_widget_data_get(obj);
3359 t = eina_stringshare_add(elm_entry_entry_get(obj));
3361 if (len <= 0) return;
3363 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3364 elm_entry_entry_set(obj, t);
3368 eina_stringshare_del(t);
3372 * Set the text color on the entry object
3374 * @param obj The entry object
3375 * @param r Red property background color of The entry object
3376 * @param g Green property background color of The entry object
3377 * @param b Blue property background color of The entry object
3378 * @param a Alpha property background alpha of The entry object
3383 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3385 ELM_CHECK_WIDTYPE(obj, widtype);
3386 Widget_Data *wd = elm_widget_data_get(obj);
3387 Eina_Strbuf *colorbuf = NULL;
3392 t = eina_stringshare_add(elm_entry_entry_get(obj));
3394 if (len <= 0) return;
3395 colorbuf = eina_strbuf_new();
3396 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3398 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3400 elm_entry_entry_set(obj, t);
3404 eina_strbuf_free(colorbuf);
3405 eina_stringshare_del(t);
3409 * Set background color of the entry
3411 * @param obj The entry object
3412 * @param r Red property background color of The entry object
3413 * @param g Green property background color of The entry object
3414 * @param b Blue property background color of The entry object
3415 * @param a Alpha property background alpha of The entry object
3419 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3421 ELM_CHECK_WIDTYPE(obj, widtype);
3422 Widget_Data *wd = elm_widget_data_get(obj);
3423 evas_object_color_set(wd->bg, r, g, b, a);
3425 if (wd->bgcolor == EINA_FALSE)
3428 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3433 * Set the ellipsis behavior of the entry
3435 * @param obj The entry object
3436 * @param ellipsis To ellipsis text or not
3440 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3442 ELM_CHECK_WIDTYPE(obj, widtype);
3443 Widget_Data *wd = elm_widget_data_get(obj);
3444 if (wd->ellipsis == ellipsis) return;
3445 wd->ellipsis = ellipsis;
3451 * Filter inserted text based on user defined character and byte limits
3453 * Add this filter to an entry to limit the characters that it will accept
3454 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3455 * The funtion works on the UTF-8 representation of the string, converting
3456 * it from the set markup, thus not accounting for any format in it.
3458 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3459 * it as data when setting the filter. In it it's possible to set limits
3460 * by character count or bytes (any of them is disabled if 0), and both can
3461 * be set at the same time. In that case, it first checks for characters,
3464 * The function will cut the inserted text in order to allow only the first
3465 * number of characters that are still allowed. The cut is made in
3466 * characters, even when limiting by bytes, in order to always contain
3467 * valid ones and avoid half unicode characters making it in.
3472 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3474 Elm_Entry_Filter_Limit_Size *lim = data;
3477 const char *(*text_get)(const Evas_Object *);
3478 const char *widget_type;
3480 EINA_SAFETY_ON_NULL_RETURN(data);
3481 EINA_SAFETY_ON_NULL_RETURN(entry);
3482 EINA_SAFETY_ON_NULL_RETURN(text);
3484 /* hack. I don't want to copy the entire function to work with
3486 widget_type = elm_widget_type_get(entry);
3487 if (!strcmp(widget_type, "entry"))
3488 text_get = elm_entry_entry_get;
3489 else if (!strcmp(widget_type, "scrolled_entry"))
3490 text_get = elm_scrolled_entry_entry_get;
3494 current = elm_entry_markup_to_utf8(text_get(entry));
3496 if (lim->max_char_count > 0)
3499 len = evas_string_char_len_get(current);
3500 if (len >= lim->max_char_count)
3507 newlen = evas_string_char_len_get(*text);
3508 cut = strlen(*text);
3509 while ((len + newlen) > lim->max_char_count)
3511 cut = evas_string_char_prev_get(*text, cut, NULL);
3517 if (lim->max_byte_count > 0)
3519 len = strlen(current);
3520 if (len >= lim->max_byte_count)
3527 newlen = strlen(*text);
3528 while ((len + newlen) > lim->max_byte_count)
3530 int p = evas_string_char_prev_get(*text, newlen, NULL);
3531 newlen -= (newlen - p);
3534 (*text)[newlen] = 0;
3545 * Filter inserted text based on accepted or rejected sets of characters
3547 * Add this filter to an entry to restrict the set of accepted characters
3548 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3549 * This structure contains both accepted and rejected sets, but they are
3550 * mutually exclusive. If accepted is set, it will be used, otherwise it
3551 * goes on to the rejected set.
3554 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3556 Elm_Entry_Filter_Accept_Set *as = data;
3560 int read_idx, last_read_idx = 0, read_char;
3562 EINA_SAFETY_ON_NULL_RETURN(data);
3563 EINA_SAFETY_ON_NULL_RETURN(text);
3565 if ((!as->accepted) && (!as->rejected))
3571 goes_in = EINA_TRUE;
3576 goes_in = EINA_FALSE;
3580 read_idx = evas_string_char_next_get(*text, 0, &read_char);
3583 int cmp_idx, cmp_char;
3584 Eina_Bool in_set = EINA_FALSE;
3586 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3589 if (read_char == cmp_char)
3594 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3596 if (in_set == goes_in)
3598 int size = read_idx - last_read_idx;
3599 const char *src = (*text) + last_read_idx;
3601 memcpy(insert, *text + last_read_idx, size);
3604 last_read_idx = read_idx;
3605 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3611 * This sets the file (and implicitly loads it) for the text to display and
3612 * then edit. All changes are written back to the file after a short delay if
3613 * the entry object is set to autosave.
3615 * @param obj The entry object
3616 * @param file The path to the file to load and save
3617 * @param format The file format
3622 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3624 ELM_CHECK_WIDTYPE(obj, widtype);
3625 Widget_Data *wd = elm_widget_data_get(obj);
3627 if (wd->delay_write)
3629 ecore_timer_del(wd->delay_write);
3630 wd->delay_write = NULL;
3632 if (wd->autosave) _save(obj);
3633 eina_stringshare_replace(&wd->file, file);
3634 wd->format = format;
3639 * Gets the file to load and save and the file format
3641 * @param obj The entry object
3642 * @param file The path to the file to load and save
3643 * @param format The file format
3648 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3650 ELM_CHECK_WIDTYPE(obj, widtype);
3651 Widget_Data *wd = elm_widget_data_get(obj);
3653 if (file) *file = wd->file;
3654 if (format) *format = wd->format;
3658 * This function writes any changes made to the file set with
3659 * elm_entry_file_set()
3661 * @param obj The entry object
3666 elm_entry_file_save(Evas_Object *obj)
3668 ELM_CHECK_WIDTYPE(obj, widtype);
3669 Widget_Data *wd = elm_widget_data_get(obj);
3671 if (wd->delay_write)
3673 ecore_timer_del(wd->delay_write);
3674 wd->delay_write = NULL;
3677 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3681 * This sets the entry object to 'autosave' the loaded text file or not.
3683 * @param obj The entry object
3684 * @param autosave Autosave the loaded file or not
3689 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3691 ELM_CHECK_WIDTYPE(obj, widtype);
3692 Widget_Data *wd = elm_widget_data_get(obj);
3694 wd->autosave = !!autosave;
3698 * This gets the entry object's 'autosave' status.
3700 * @param obj The entry object
3701 * @return Autosave the loaded file or not
3706 elm_entry_autosave_get(const Evas_Object *obj)
3708 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3709 Widget_Data *wd = elm_widget_data_get(obj);
3710 if (!wd) return EINA_FALSE;
3711 return wd->autosave;
3715 * This sets the attribute to show the input panel automatically.
3717 * @param obj The entry object
3718 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3723 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3725 ELM_CHECK_WIDTYPE(obj, widtype);
3726 Widget_Data *wd = elm_widget_data_get(obj);
3729 wd->input_panel_enable = enabled;
3730 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3734 * Set the input panel layout of the entry
3736 * @param obj The entry object
3737 * @param layout the layout to set
3742 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3744 ELM_CHECK_WIDTYPE(obj, widtype);
3745 Widget_Data *wd = elm_widget_data_get(obj);
3748 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3751 wd->input_panel_layout = layout;
3753 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);