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;
110 Evas_Object *mgf_proxy;
111 Evas_Object *mgf_clip;
113 Evas_Coord mgf_height;
116 Ecore_Job *deferred_recalc_job;
117 Ecore_Event_Handler *sel_notify_handler;
118 Ecore_Event_Handler *sel_clear_handler;
119 Ecore_Timer *longpress_timer;
120 Ecore_Timer *delay_write;
121 /* Only for clipboard */
125 int ellipsis_threshold;
127 Elm_Text_Format format;
129 Evas_Coord downx, downy;
130 Evas_Coord cx, cy, cw, ch;
132 Eina_List *item_providers;
133 Eina_List *text_filters;
134 Eina_List *match_list;
135 Ecore_Job *matchlist_job;
136 Ecore_Job *hovdeljob;
137 Mod_Api *api; // module api if supplied
139 Eina_Bool changed : 1;
140 Eina_Bool linewrap : 1;
141 Eina_Bool char_linewrap : 1;
142 Eina_Bool single_line : 1;
143 Eina_Bool password : 1;
144 Eina_Bool show_last_character : 1;
145 Eina_Bool editable : 1;
146 Eina_Bool selection_asked : 1;
147 Eina_Bool have_selection : 1;
148 Eina_Bool selmode : 1;
149 Eina_Bool deferred_cur : 1;
150 Eina_Bool disabled : 1;
151 Eina_Bool double_clicked : 1;
152 Eina_Bool long_pressed : 1;
153 Eina_Bool context_menu : 1;
154 Eina_Bool drag_selection_asked : 1;
155 Eina_Bool bgcolor : 1;
156 Eina_Bool ellipsis : 1;
157 Eina_Bool can_write : 1;
158 Eina_Bool autosave : 1;
159 Eina_Bool textonly : 1;
160 Eina_Bool autoreturnkey : 1;
161 Eina_Bool input_panel_enable : 1;
162 Eina_Bool autocapital : 1;
163 Elm_Input_Panel_Layout input_panel_layout;
164 Eina_Bool autoperiod : 1;
165 Eina_Bool matchlist_list_clicked : 1;
166 Eina_Bool matchlist_case_sensitive : 1;
167 int matchlist_threshold;
170 struct _Elm_Entry_Context_Menu_Item
174 const char *icon_file;
175 const char *icon_group;
176 Elm_Icon_Type icon_type;
181 struct _Elm_Entry_Item_Provider
183 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
187 struct _Elm_Entry_Text_Filter
189 void (*func) (void *data, Evas_Object *entry, char **text);
193 static const char *widtype = NULL;
195 static Evas_Object *cnpwidgetdata = NULL;
198 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
199 static void _del_hook(Evas_Object *obj);
200 static void _theme_hook(Evas_Object *obj);
201 static void _disable_hook(Evas_Object *obj);
202 static void _sizing_eval(Evas_Object *obj);
203 static void _on_focus_hook(void *data, Evas_Object *obj);
204 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
205 static const char *_getbase(Evas_Object *obj);
206 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
207 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
208 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
209 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
210 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
211 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
212 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
213 static void _signal_handler_moving(void *data, Evas_Object *obj, const char *emission, const char *source);
214 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
215 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
216 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
217 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
218 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
219 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
220 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
221 static int _is_width_over(Evas_Object *obj);
222 static void _ellipsis_entry_to_width(Evas_Object *obj);
223 static void _reverse_ellipsis_entry(Evas_Object *obj);
224 static int _entry_length_get(Evas_Object *obj);
225 static void _magnifier_create(void *data);
226 static void _magnifier_show(void *data);
227 static void _magnifier_hide(void *data);
228 static void _magnifier_move(void *data);
229 static void _long_pressed(void *data);
231 static const char SIG_CHANGED[] = "changed";
232 static const char SIG_ACTIVATED[] = "activated";
233 static const char SIG_PRESS[] = "press";
234 static const char SIG_LONGPRESSED[] = "longpressed";
235 static const char SIG_CLICKED[] = "clicked";
236 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
237 static const char SIG_FOCUSED[] = "focused";
238 static const char SIG_UNFOCUSED[] = "unfocused";
239 static const char SIG_SELECTION_PASTE[] = "selection,paste";
240 static const char SIG_SELECTION_COPY[] = "selection,copy";
241 static const char SIG_SELECTION_CUT[] = "selection,cut";
242 static const char SIG_SELECTION_START[] = "selection,start";
243 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
244 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
245 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
246 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
247 static const char SIG_MATCHLIST_CLICKED[] = "matchlist,clicked";
248 static const Evas_Smart_Cb_Description _signals[] = {
252 {SIG_LONGPRESSED, ""},
254 {SIG_CLICKED_DOUBLE, ""},
257 {SIG_SELECTION_PASTE, ""},
258 {SIG_SELECTION_COPY, ""},
259 {SIG_SELECTION_CUT, ""},
260 {SIG_SELECTION_START, ""},
261 {SIG_SELECTION_CHANGED, ""},
262 {SIG_SELECTION_CLEARED, ""},
263 {SIG_CURSOR_CHANGED, ""},
264 {SIG_ANCHOR_CLICKED, ""},
265 {SIG_MATCHLIST_CLICKED, ""},
269 typedef enum _Elm_Entry_Magnifier_Type
271 _ENTRY_MAGNIFIER_FIXEDSIZE = 0,
272 _ENTRY_MAGNIFIER_FILLWIDTH,
273 _ENTRY_MAGNIFIER_CIRCULAR,
274 } Elm_Entry_Magnifier_Type;
277 static Eina_List *entries = NULL;
281 void (*obj_hook) (Evas_Object *obj);
282 void (*obj_unhook) (Evas_Object *obj);
283 void (*obj_longpress) (Evas_Object *obj);
284 void (*obj_hidemenu) (Evas_Object *obj);
285 void (*obj_mouseup) (Evas_Object *obj);
289 _module(Evas_Object *obj __UNUSED__)
291 static Elm_Module *m = NULL;
292 if (m) goto ok; // already found - just use
293 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
295 m->api = malloc(sizeof(Mod_Api));
296 if (!m->api) return NULL;
297 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
298 _elm_module_symbol_get(m, "obj_hook");
299 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
300 _elm_module_symbol_get(m, "obj_unhook");
301 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
302 _elm_module_symbol_get(m, "obj_longpress");
303 ((Mod_Api *)(m->api) )->obj_hidemenu = // called on hide menu
304 _elm_module_symbol_get(m, "obj_hidemenu");
305 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
306 _elm_module_symbol_get(m, "obj_mouseup");
307 ok: // ok - return api
312 _buf_append(char *buf, const char *str, int *len, int *alloc)
314 int len2 = strlen(str);
315 if ((*len + len2) >= *alloc)
317 char *buf2 = realloc(buf, *alloc + len2 + 512);
318 if (!buf2) return NULL;
320 *alloc += (512 + len2);
322 strcpy(buf + *len, str);
328 _load_file(const char *file)
332 int alloc = 0, len = 0;
333 char *text = NULL, buf[PATH_MAX];
335 f = fopen(file, "rb");
337 while ((size = fread(buf, 1, sizeof(buf), f)))
341 tmp_text = _buf_append(text, buf, &len, &alloc);
342 if (!tmp_text) break;
350 _load_plain(const char *file)
354 text = _load_file(file);
359 text2 = elm_entry_utf8_to_markup(text);
367 _load(Evas_Object *obj)
369 Widget_Data *wd = elm_widget_data_get(obj);
374 elm_entry_entry_set(obj, "");
379 case ELM_TEXT_FORMAT_PLAIN_UTF8:
380 text = _load_plain(wd->file);
382 case ELM_TEXT_FORMAT_MARKUP_UTF8:
383 text = _load_file(wd->file);
391 elm_entry_entry_set(obj, text);
395 elm_entry_entry_set(obj, "");
399 _save_markup_utf8(const char *file, const char *text)
403 if ((!text) || (!text[0]))
405 ecore_file_unlink(file);
408 f = fopen(file, "wb");
411 // FIXME: report a write error
414 fputs(text, f); // FIXME: catch error
419 _save_plain_utf8(const char *file, const char *text)
423 text2 = elm_entry_markup_to_utf8(text);
426 _save_markup_utf8(file, text2);
431 _save(Evas_Object *obj)
433 Widget_Data *wd = elm_widget_data_get(obj);
435 if (!wd->file) return;
438 case ELM_TEXT_FORMAT_PLAIN_UTF8:
439 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
441 case ELM_TEXT_FORMAT_MARKUP_UTF8:
442 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
450 _delay_write(void *data)
452 Widget_Data *wd = elm_widget_data_get(data);
453 if (!wd) return ECORE_CALLBACK_CANCEL;
455 wd->delay_write = NULL;
456 return ECORE_CALLBACK_CANCEL;
460 _del_pre_hook(Evas_Object *obj)
462 Widget_Data *wd = elm_widget_data_get(obj);
466 ecore_timer_del(wd->delay_write);
467 wd->delay_write = NULL;
468 if (wd->autosave) _save(obj);
473 _del_hook(Evas_Object *obj)
475 Widget_Data *wd = elm_widget_data_get(obj);
476 Elm_Entry_Context_Menu_Item *it;
477 Elm_Entry_Item_Provider *ip;
478 Elm_Entry_Text_Filter *tf;
480 if (wd->file) eina_stringshare_del(wd->file);
482 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
483 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
485 entries = eina_list_remove(entries, obj);
486 #ifdef HAVE_ELEMENTARY_X
487 ecore_event_handler_del(wd->sel_notify_handler);
488 ecore_event_handler_del(wd->sel_clear_handler);
490 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
491 if (wd->text) eina_stringshare_del(wd->text);
492 if (wd->bg) evas_object_del(wd->bg);
493 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
494 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
495 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
496 if (wd->mgf_proxy) evas_object_del(wd->mgf_proxy);
497 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
498 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
500 EINA_LIST_FREE(wd->items, it)
502 eina_stringshare_del(it->label);
503 eina_stringshare_del(it->icon_file);
504 eina_stringshare_del(it->icon_group);
507 EINA_LIST_FREE(wd->item_providers, ip)
511 EINA_LIST_FREE(wd->text_filters, tf)
519 _theme_hook(Evas_Object *obj)
521 Widget_Data *wd = elm_widget_data_get(obj);
523 Ecore_IMF_Context *ic;
525 t = eina_stringshare_add(elm_entry_entry_get(obj));
526 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
527 elm_entry_entry_set(obj, t);
528 eina_stringshare_del(t);
529 if (elm_widget_disabled_get(obj))
530 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
531 edje_object_message_signal_process(wd->ent);
532 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
533 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
534 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
535 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
537 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
540 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
547 _disable_hook(Evas_Object *obj)
549 Widget_Data *wd = elm_widget_data_get(obj);
551 if (elm_widget_disabled_get(obj))
553 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
554 wd->disabled = EINA_TRUE;
558 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
559 wd->disabled = EINA_FALSE;
564 _elm_win_recalc_job(void *data)
566 Widget_Data *wd = elm_widget_data_get(data);
567 Evas_Coord minw = -1, minh = -1, maxh = -1;
568 Evas_Coord resw, resh, minminw;
570 wd->deferred_recalc_job = NULL;
571 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
573 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
574 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
576 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
577 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
578 evas_object_size_hint_min_set(data, minminw, minh);
579 if (wd->single_line) maxh = minh;
580 evas_object_size_hint_max_set(data, -1, maxh);
581 if (wd->deferred_cur)
582 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
586 _sizing_eval(Evas_Object *obj)
588 Widget_Data *wd = elm_widget_data_get(obj);
589 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
590 Evas_Coord resw, resh;
592 if ((wd->linewrap) || (wd->char_linewrap))
594 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
595 if ((resw == wd->lastw) && (!wd->changed)) return;
596 wd->changed = EINA_FALSE;
598 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
599 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
603 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
604 edje_object_size_min_calc(wd->ent, &minw, &minh);
605 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
606 evas_object_size_hint_min_set(obj, minw, minh);
607 if (wd->single_line) maxh = minh;
608 evas_object_size_hint_max_set(obj, maxw, maxh);
610 if (wd->ellipsis && wd->single_line)
612 if (_is_width_over(obj))
613 _ellipsis_entry_to_width(obj);
614 else if (wd->ellipsis_threshold > 1 && _entry_length_get(obj) < wd->ellipsis_threshold)
615 _reverse_ellipsis_entry(obj);
621 _check_enable_returnkey(Evas_Object *obj)
623 Widget_Data *wd = elm_widget_data_get(obj);
626 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
629 if (!wd->autoreturnkey) return;
631 if (_entry_length_get(obj) == 0)
633 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
637 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
642 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
644 Widget_Data *wd = elm_widget_data_get(obj);
645 Evas_Object *top = elm_widget_top_get(obj);
648 if (!wd->editable) return;
649 if (elm_widget_focus_get(obj))
651 evas_object_focus_set(wd->ent, EINA_TRUE);
652 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
653 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
654 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
655 _check_enable_returnkey(obj);
656 wd->mgf_type = _ENTRY_MAGNIFIER_FILLWIDTH;
657 _magnifier_create(obj);
661 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
662 evas_object_focus_set(wd->ent, EINA_FALSE);
663 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
664 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
666 if ((wd->api) && (wd->api->obj_hidemenu))
668 wd->api->obj_hidemenu(obj);
674 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
676 Widget_Data *wd = elm_widget_data_get(obj);
678 edje_object_signal_emit(wd->ent, emission, source);
682 _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)
684 Widget_Data *wd = elm_widget_data_get(obj);
686 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
690 _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)
692 Widget_Data *wd = elm_widget_data_get(obj);
693 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
698 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
700 Widget_Data *wd = elm_widget_data_get(obj);
701 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
705 _hoversel_position(Evas_Object *obj)
707 Widget_Data *wd = elm_widget_data_get(obj);
708 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
710 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
711 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
713 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
724 evas_object_move(wd->hoversel, x + cx, y + cy);
725 evas_object_resize(wd->hoversel, cw, ch);
729 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
731 Widget_Data *wd = elm_widget_data_get(data);
733 if (wd->hoversel) _hoversel_position(data);
737 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
739 Widget_Data *wd = elm_widget_data_get(data);
741 if ((wd->linewrap) || (wd->char_linewrap))
745 if (wd->hoversel) _hoversel_position(data);
746 // Evas_Coord ww, hh;
747 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
751 _hover_del(void *data)
753 Widget_Data *wd = elm_widget_data_get(data);
758 evas_object_del(wd->hoversel);
761 wd->hovdeljob = NULL;
765 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
767 Widget_Data *wd = elm_widget_data_get(data);
769 if (wd->hoversel) evas_object_hide(wd->hoversel);
773 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
775 elm_widget_scroll_freeze_pop(data);
776 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
777 wd->hovdeljob = ecore_job_add(_hover_del, data);
781 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
783 Widget_Data *wd = elm_widget_data_get(data);
785 wd->selmode = EINA_TRUE;
787 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
788 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
789 edje_object_part_text_select_all(wd->ent, "elm.text");
790 //elm_widget_scroll_hold_push(data);
791 elm_object_scroll_freeze_pop(data);
795 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
797 Widget_Data *wd = elm_widget_data_get(data);
799 wd->selmode = EINA_TRUE;
800 edje_object_part_text_select_none(wd->ent, "elm.text");
802 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
803 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
804 elm_object_scroll_freeze_pop(data);
805 //elm_widget_scroll_hold_push(data);
809 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
811 Widget_Data *wd = elm_widget_data_get(data);
813 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
814 if (wd->sel_notify_handler)
816 #ifdef HAVE_ELEMENTARY_X
817 wd->selection_asked = EINA_TRUE;
818 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data, NULL, NULL);
824 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
826 Widget_Data *wd = elm_widget_data_get(obj);
830 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
831 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
832 if (seltype == ELM_SEL_CLIPBOARD)
833 eina_stringshare_replace(&wd->cut_sel, sel);
837 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
839 Widget_Data *wd = elm_widget_data_get(data);
842 wd->selmode = EINA_FALSE;
843 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
844 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
845 elm_widget_scroll_hold_pop(data);
846 _store_selection(ELM_SEL_CLIPBOARD, data);
847 edje_object_part_text_insert(wd->ent, "elm.text", "");
848 edje_object_part_text_select_none(wd->ent, "elm.text");
852 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
854 Widget_Data *wd = elm_widget_data_get(data);
856 //wd->selmode = EINA_FALSE;
857 //edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
858 //edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
859 elm_widget_scroll_hold_pop(data);
860 _store_selection(ELM_SEL_CLIPBOARD, data);
861 //edje_object_part_text_select_none(wd->ent, "elm.text");
865 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
867 Widget_Data *wd = elm_widget_data_get(data);
869 wd->selmode = EINA_FALSE;
870 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
871 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
872 elm_widget_scroll_hold_pop(data);
873 edje_object_part_text_select_none(wd->ent, "elm.text");
877 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
879 Widget_Data *wd = elm_widget_data_get(data);
883 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
884 cnpwidgetdata = data;
885 elm_cbhm_helper_init(obj);
886 if (elm_entry_cnp_textonly_get(obj))
887 elm_cbhm_send_raw_data("show0");
889 elm_cbhm_send_raw_data("show1");
895 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
897 Widget_Data *wd = elm_widget_data_get(data);
899 cnpwidgetdata = data;
905 _item_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
907 Elm_Entry_Context_Menu_Item *it = data;
908 Evas_Object *obj2 = it->obj;
909 if (it->func) it->func(it->data, obj2, NULL);
913 _long_pressed(void *data)
915 Widget_Data *wd = elm_widget_data_get(data);
918 const Elm_Entry_Context_Menu_Item *it;
920 if ((wd->api) && (wd->api->obj_longpress))
922 wd->api->obj_longpress(data);
924 else if (wd->context_menu)
926 const char *context_menu_orientation;
928 if (wd->hoversel) evas_object_del(wd->hoversel);
929 else elm_widget_scroll_freeze_push(data);
930 wd->hoversel = elm_hoversel_add(data);
931 context_menu_orientation = edje_object_data_get
932 (wd->ent, "context_menu_orientation");
933 if ((context_menu_orientation) &&
934 (!strcmp(context_menu_orientation, "horizontal")))
935 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
936 elm_object_style_set(wd->hoversel, "entry");
937 elm_widget_sub_object_add(data, wd->hoversel);
938 elm_hoversel_label_set(wd->hoversel, "Text");
939 top = elm_widget_top_get(data);
940 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
941 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
945 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
947 if (1) // need way to detect if someone has a selection
950 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
955 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
956 _clipboard_menu, data);
963 if (wd->have_selection)
965 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
968 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
971 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
974 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
975 _clipboard_menu, data);
979 EINA_LIST_FOREACH(wd->items, l, it)
981 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
982 it->icon_type, _item_clicked, it);
986 _hoversel_position(data);
987 evas_object_show(wd->hoversel);
988 elm_hoversel_hover_begin(wd->hoversel);
990 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
991 edje_object_part_text_select_abort(wd->ent, "elm.text");
994 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
998 _magnifier_hide(void *data)
1000 Widget_Data *wd = elm_widget_data_get(data);
1002 if (evas_version->major < 2 && evas_version->minor < 1) return;
1004 evas_object_hide(wd->mgf_bg);
1005 evas_object_hide(wd->mgf_clip);
1009 _magnifier_show(void *data)
1011 Widget_Data *wd = elm_widget_data_get(data);
1013 if (evas_version->major < 2 && evas_version->minor < 1) return;
1015 evas_object_show(wd->mgf_bg);
1016 evas_object_show(wd->mgf_clip);
1020 _magnifier_move(void *data)
1022 Widget_Data *wd = elm_widget_data_get(data);
1024 if (evas_version->major < 2 && evas_version->minor < 1) return;
1026 Evas_Coord x, y, w, h, fs;
1027 Evas_Coord cx, cy, cw, ch, ox, oy;
1029 evas_object_geometry_get(data, &x, &y, &w, &h);
1030 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1033 fs = elm_finger_size_get();
1035 if ((cy + y) - wd->mgf_height - fs < 0)
1036 oy = -1 * ((cy + y) - wd->mgf_height - fs);
1038 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1039 evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1040 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1041 evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1045 evas_object_move(wd->mgf_proxy, (1 - wd->mgf_scale) * cx + x + ox, (1 - wd->mgf_scale) * cy + y - wd->mgf_height/2 - ch/2 - fs + oy);
1049 _magnifier_create(void *data)
1051 Widget_Data *wd = elm_widget_data_get(data);
1052 Evas_Coord x, y, w, h;
1053 const char* key_data = NULL;
1056 if (evas_version->major < 2 && evas_version->minor < 1) return;
1060 evas_object_image_source_unset(wd->mgf_proxy);
1061 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1062 evas_object_hide(wd->mgf_proxy);
1063 evas_object_clip_unset(wd->mgf_proxy);
1064 evas_object_del(wd->mgf_proxy);
1066 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1067 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1069 evas_object_geometry_get(data, &x, &y, &w, &h);
1070 wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1072 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1073 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1074 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1075 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1079 wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1080 evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1081 edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1083 key_data = edje_object_data_get(wd->mgf_bg, "height");
1084 if (key_data) wd->mgf_height = atoi(key_data);
1085 key_data = edje_object_data_get(wd->mgf_bg, "scale");
1086 if (key_data) wd->mgf_scale = atof(key_data);
1088 if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1089 evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1091 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1092 evas_object_image_source_set(wd->mgf_proxy, data);
1093 evas_object_resize(wd->mgf_proxy, w * wd->mgf_scale, h * wd->mgf_scale);
1094 evas_object_image_fill_set(wd->mgf_proxy, 0, 0, w * wd->mgf_scale, h * wd->mgf_scale);
1095 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1096 evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1097 evas_object_show(wd->mgf_proxy);
1098 evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1100 evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1101 evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1105 _long_press(void *data)
1107 Widget_Data *wd = elm_widget_data_get(data);
1108 if (!wd) return ECORE_CALLBACK_CANCEL;
1110 wd->long_pressed = EINA_TRUE;
1112 if (wd->longpress_timer)
1114 ecore_timer_del(wd->longpress_timer);
1115 wd->longpress_timer = NULL;
1118 _cancel(data, NULL, NULL);
1120 _magnifier_create(data);
1121 _magnifier_move(data);
1122 _magnifier_show(data);
1123 elm_object_scroll_freeze_push(data);
1125 wd->longpress_timer = NULL;
1126 return ECORE_CALLBACK_CANCEL;
1130 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1132 Widget_Data *wd = elm_widget_data_get(data);
1133 Evas_Event_Mouse_Down *ev = event_info;
1135 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1136 if (ev->button != 1) return;
1137 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1138 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1139 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1140 wd->downx = ev->canvas.x;
1141 wd->downy = ev->canvas.y;
1143 wd->long_pressed = EINA_FALSE;
1147 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1149 Widget_Data *wd = elm_widget_data_get(data);
1150 Evas_Event_Mouse_Up *ev = event_info;
1152 if (ev->button != 1) return;
1154 if (!wd->double_clicked)
1156 if ((wd->api) && (wd->api->obj_mouseup))
1158 wd->api->obj_mouseup(data);
1161 if (wd->longpress_timer)
1163 ecore_timer_del(wd->longpress_timer);
1164 wd->longpress_timer = NULL;
1167 _magnifier_hide(data);
1168 elm_object_scroll_freeze_pop(data);
1170 if (wd->long_pressed)
1172 _long_pressed(data);
1177 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1179 Widget_Data *wd = elm_widget_data_get(data);
1180 Evas_Event_Mouse_Move *ev = event_info;
1184 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1186 if (wd->longpress_timer)
1188 ecore_timer_del(wd->longpress_timer);
1189 wd->longpress_timer = NULL;
1192 else if (wd->longpress_timer)
1196 dx = wd->downx - ev->cur.canvas.x;
1198 dy = wd->downy - ev->cur.canvas.y;
1201 ((_elm_config->finger_size / 2) *
1202 (_elm_config->finger_size / 2)))
1204 ecore_timer_del(wd->longpress_timer);
1205 wd->longpress_timer = NULL;
1209 else if (wd->longpress_timer)
1213 dx = wd->downx - ev->cur.canvas.x;
1215 dy = wd->downy - ev->cur.canvas.y;
1218 ((_elm_config->finger_size / 2) *
1219 (_elm_config->finger_size / 2)))
1221 ecore_timer_del(wd->longpress_timer);
1222 wd->longpress_timer = NULL;
1226 if (ev->buttons != 1) return;
1228 if (wd->long_pressed)
1230 _magnifier_show(data);
1231 _magnifier_move(data);
1236 _getbase(Evas_Object *obj)
1238 Widget_Data *wd = elm_widget_data_get(obj);
1239 if (!wd) return "base";
1244 if (wd->show_last_character) return "custom-password";
1245 else return "base-password";
1249 if (wd->single_line) return "base-single";
1252 if (wd->linewrap) return "base";
1253 else if (wd->char_linewrap) return "base-charwrap";
1254 else return "base-nowrap";
1262 if (wd->show_last_character) return "custom-password";
1263 else return "base-password";
1267 if (wd->single_line) return "base-single-noedit";
1270 if (wd->linewrap) return "base-noedit";
1271 else if (wd->char_linewrap) return "base-noedit-charwrap";
1272 else return "base-nowrap-noedit";
1280 _entry_length_get(Evas_Object *obj)
1283 const char *str = elm_entry_entry_get(obj);
1286 char *plain_str = _elm_util_mkup_to_text(str);
1287 if (!plain_str) return 0;
1289 len = strlen(plain_str);
1296 _matchlist_show(void *data)
1298 Widget_Data *wd = elm_widget_data_get(data);
1299 const char *text = NULL;
1301 char *str_list = NULL, *str_result = NULL;
1302 char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1305 Eina_Bool textfound = EINA_FALSE;
1308 if (elm_widget_disabled_get(data)) return;
1310 wd->matchlist_job = NULL;
1312 if (wd->matchlist_list_clicked)
1314 evas_object_hide(wd->hover);
1315 wd->matchlist_list_clicked = EINA_FALSE;
1318 text = elm_entry_entry_get(data);
1321 textlen = strlen(text);
1323 if (textlen < wd->matchlist_threshold)
1325 evas_object_hide(wd->hover);
1329 evas_object_hide(wd->hover);
1333 elm_list_clear(wd->list);
1334 EINA_LIST_FOREACH(wd->match_list, l, str_list)
1336 if (wd->matchlist_case_sensitive)
1337 str_result = strstr(str_list, text);
1339 str_result = strcasestr(str_list, text);
1343 str_mkup = malloc(strlen(str_list) + 16);
1345 textlen = strlen(str_list) - strlen(str_result);
1346 str_front = malloc(textlen + 1);
1347 memset(str_front, 0, textlen + 1);
1348 strncpy(str_front, str_list, textlen);
1350 textlen = strlen(text);
1351 str_mid = malloc(textlen + 1);
1352 memset(str_mid, 0, textlen + 1);
1353 strncpy(str_mid, str_list + strlen(str_front), textlen);
1355 sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1357 elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1359 if (str_mkup) free(str_mkup);
1360 if (str_front) free(str_front);
1361 if (str_mid) free(str_mid);
1363 textfound=EINA_TRUE;
1372 elm_list_go(wd->list);
1373 evas_object_show(wd->hover);
1374 evas_object_raise(wd->hover);
1378 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1380 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1381 Widget_Data *wd = elm_widget_data_get(data);
1382 if ((it == NULL) || (wd == NULL))
1385 const char *text = elm_list_item_label_get(it);
1386 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1391 elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1392 elm_entry_cursor_end_set(data);
1393 wd->matchlist_list_clicked = EINA_TRUE;
1395 evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1398 elm_widget_focus_set(data, EINA_TRUE);
1402 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
1404 Widget_Data *wd = elm_widget_data_get(obj);
1409 Evas_Coord max_w = 9999, max_h = 9999;
1410 const char* key_data = NULL;
1412 wd->matchlist_threshold = 1;
1413 wd->hover = elm_hover_add(elm_widget_parent_get(obj));
1414 elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
1415 elm_hover_target_set(wd->hover, obj);
1416 elm_object_style_set(wd->hover, "matchlist");
1418 wd->layout = elm_layout_add(wd->hover);
1419 elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
1420 wd->list = elm_list_add(wd->layout);
1421 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
1422 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1423 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1424 elm_object_style_set(wd->list, "matchlist");
1426 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
1427 if (key_data) max_w = atoi(key_data);
1428 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
1429 if (key_data) max_h = atoi(key_data);
1431 elm_list_go(wd->list);
1432 evas_object_size_hint_max_set(wd->list, max_w, max_h);
1433 evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
1434 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
1435 elm_hover_content_set(wd->hover, "bottom", wd->layout);
1437 wd->match_list = match_list;
1442 evas_object_del(wd->hover);
1444 wd->match_list = NULL;
1447 wd->matchlist_case_sensitive = case_sensitive;
1452 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1454 Widget_Data *wd = elm_widget_data_get(data);
1456 wd->changed = EINA_TRUE;
1458 if (wd->text) eina_stringshare_del(wd->text);
1460 _check_enable_returnkey(data);
1461 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1462 if (wd->delay_write)
1464 ecore_timer_del(wd->delay_write);
1465 wd->delay_write = NULL;
1468 if ((wd->single_line) && (wd->match_list))
1470 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1471 wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1473 if ((!wd->autosave) || (!wd->file)) return;
1474 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1478 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1480 Widget_Data *wd = elm_widget_data_get(data);
1481 elm_object_scroll_freeze_push(data);
1483 if ((wd->api) && (wd->api->obj_hidemenu))
1485 wd->api->obj_hidemenu(data);
1488 _magnifier_create(data);
1489 _magnifier_move(data);
1490 _magnifier_show(data);
1494 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1496 Widget_Data *wd = elm_widget_data_get(data);
1497 elm_object_scroll_freeze_pop(data);
1499 if (wd->have_selection)
1501 _magnifier_hide(data);
1502 _long_pressed(data);
1507 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1509 _magnifier_move(data);
1510 _magnifier_show(data);
1514 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1516 _magnifier_hide(data);
1517 _long_pressed(data);
1521 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1523 Widget_Data *wd = elm_widget_data_get(data);
1527 EINA_LIST_FOREACH(entries, l, entry)
1529 if (entry != data) elm_entry_select_none(entry);
1531 wd->have_selection = EINA_TRUE;
1532 wd->selmode = EINA_TRUE;
1533 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1534 #ifdef HAVE_ELEMENTARY_X
1535 if (wd->sel_notify_handler)
1537 const char *txt = elm_entry_selection_get(data);
1540 top = elm_widget_top_get(data);
1541 if ((top) && (elm_win_xwindow_get(top)))
1542 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1548 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1550 Evas_Coord cx, cy, cw, ch;
1551 Widget_Data *wd = elm_widget_data_get(data);
1554 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1555 if (!wd->deferred_recalc_job)
1556 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get());
1559 wd->deferred_cur = EINA_TRUE;
1563 wd->ch = ch + elm_finger_size_get();
1568 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1570 Evas_Coord cx, cy, cw, ch;
1571 Widget_Data *wd = elm_widget_data_get(data);
1573 wd->have_selection = EINA_TRUE;
1574 wd->selmode = EINA_TRUE;
1575 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1576 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1577 elm_entry_selection_get(data));
1579 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1580 if (!wd->deferred_recalc_job)
1581 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get());
1584 wd->deferred_cur = EINA_TRUE;
1588 wd->ch = ch + elm_finger_size_get();
1593 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1595 Widget_Data *wd = elm_widget_data_get(data);
1597 if (!wd->have_selection) return;
1598 wd->have_selection = EINA_FALSE;
1599 wd->selmode = EINA_FALSE;
1600 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1601 if (wd->sel_notify_handler)
1605 #ifdef HAVE_ELEMENTARY_X
1608 top = elm_widget_top_get(data);
1609 if ((top) && (elm_win_xwindow_get(top)))
1610 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1613 eina_stringshare_del(wd->cut_sel);
1618 #ifdef HAVE_ELEMENTARY_X
1621 top = elm_widget_top_get(data);
1622 if ((top) && (elm_win_xwindow_get(top)))
1623 elm_selection_clear(ELM_SEL_PRIMARY, data);
1628 if ((wd->api) && (wd->api->obj_hidemenu))
1630 wd->api->obj_hidemenu(data);
1635 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1637 Widget_Data *wd = elm_widget_data_get(data);
1639 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1640 if (wd->sel_notify_handler)
1642 #ifdef HAVE_ELEMENTARY_X
1645 top = elm_widget_top_get(data);
1646 if ((top) && (elm_win_xwindow_get(top)))
1648 wd->selection_asked = EINA_TRUE;
1649 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1657 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1659 Widget_Data *wd = elm_widget_data_get(data);
1661 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1662 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1663 elm_entry_selection_get(data));
1667 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1669 Widget_Data *wd = elm_widget_data_get(data);
1671 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1672 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1673 elm_entry_selection_get(data));
1674 edje_object_part_text_insert(wd->ent, "elm.text", "");
1675 wd->changed = EINA_TRUE;
1680 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1682 Widget_Data *wd = elm_widget_data_get(data);
1683 Evas_Coord cx, cy, cw, ch;
1685 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1686 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1687 &cx, &cy, &cw, &ch);
1688 if (!wd->deferred_recalc_job)
1689 elm_widget_show_region_set(data, cx, cy, cw, ch);
1692 wd->deferred_cur = EINA_TRUE;
1701 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1703 Widget_Data *wd = elm_widget_data_get(data);
1708 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1710 Widget_Data *wd = elm_widget_data_get(data);
1711 Elm_Entry_Anchor_Info ei;
1712 char *buf2, *p, *p2, *n;
1714 p = strrchr(emission, ',');
1717 const Eina_List *geoms;
1721 while (p2 >= emission)
1723 if (*p2 == ',') break;
1727 buf2 = alloca(5 + p - p2);
1728 strncpy(buf2, p2, p - p2);
1731 ei.button = atoi(buf2);
1732 ei.x = ei.y = ei.w = ei.h = 0;
1734 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1737 Evas_Textblock_Rectangle *r;
1739 Evas_Coord px, py, x, y;
1741 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1742 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1743 EINA_LIST_FOREACH(geoms, l, r)
1745 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1746 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1757 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1762 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1764 Widget_Data *wd = elm_widget_data_get(data);
1769 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1771 Widget_Data *wd = elm_widget_data_get(data);
1776 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1778 Widget_Data *wd = elm_widget_data_get(data);
1783 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1785 Widget_Data *wd = elm_widget_data_get(data);
1787 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1791 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1793 Widget_Data *wd = elm_widget_data_get(data);
1795 wd->double_clicked = EINA_FALSE;
1796 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1798 if ((wd->api) && (wd->api->obj_hidemenu))
1800 wd->api->obj_hidemenu(data);
1805 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1807 Widget_Data *wd = elm_widget_data_get(data);
1809 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1813 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1815 Widget_Data *wd = elm_widget_data_get(data);
1817 wd->double_clicked = EINA_TRUE;
1818 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1821 #ifdef HAVE_ELEMENTARY_X
1823 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1825 Widget_Data *wd = elm_widget_data_get(data);
1826 Ecore_X_Event_Selection_Notify *ev = event;
1827 if (!wd) return ECORE_CALLBACK_PASS_ON;
1828 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1829 return ECORE_CALLBACK_PASS_ON;
1831 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1832 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1834 Ecore_X_Selection_Data_Text *text_data;
1836 text_data = ev->data;
1837 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1839 if (text_data->text)
1841 char *txt = _elm_util_text_to_mkup(text_data->text);
1845 elm_entry_entry_insert(data, txt);
1850 wd->selection_asked = EINA_FALSE;
1852 else if (ev->selection == ECORE_X_SELECTION_XDND)
1854 Ecore_X_Selection_Data_Text *text_data;
1856 text_data = ev->data;
1857 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1859 if (text_data->text)
1861 char *txt = _elm_util_text_to_mkup(text_data->text);
1865 /* Massive FIXME: this should be at the drag point */
1866 elm_entry_entry_insert(data, txt);
1871 wd->drag_selection_asked = EINA_FALSE;
1873 ecore_x_dnd_send_finished();
1876 return ECORE_CALLBACK_PASS_ON;
1880 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1883 Widget_Data *wd = elm_widget_data_get(data);
1884 Ecore_X_Event_Selection_Clear *ev = event;
1885 if (!wd) return ECORE_CALLBACK_PASS_ON;
1886 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1887 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1888 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1890 elm_entry_select_none(data);
1895 Evas_Object *top = elm_widget_top_get(data);
1896 Ecore_X_Event_Selection_Clear *ev = event;
1899 return ECORE_CALLBACK_PASS_ON;
1901 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1903 return ECORE_CALLBACK_PASS_ON;
1906 if (cnpwidgetdata == data)
1908 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
1912 return ECORE_CALLBACK_PASS_ON;
1917 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1922 wd = elm_widget_data_get(obj);
1924 if (!wd) return EINA_FALSE;
1925 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1927 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1928 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1929 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1930 EDJE_CURSOR_MAIN,drop->x,drop->y);
1931 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1932 elm_entry_entry_insert(obj, drop->data);
1933 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1934 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1940 static Evas_Object *
1941 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1943 Widget_Data *wd = elm_widget_data_get(data);
1946 Elm_Entry_Item_Provider *ip;
1948 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1950 o = ip->func(ip->data, data, item);
1953 if (!strncmp(item, "file://", 7))
1955 const char *fname = item + 7;
1957 o = evas_object_image_filled_add(evas_object_evas_get(data));
1958 evas_object_image_file_set(o, fname, NULL);
1959 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1961 evas_object_show(o);
1966 o = edje_object_add(evas_object_evas_get(data));
1967 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1971 o = edje_object_add(evas_object_evas_get(data));
1972 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1973 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1978 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1980 char *curlocater, *starttag, *endtag;
1981 int firstindex = 0, foundflag = -1;
1983 curlocater = strstr(oldstring, key);
1986 starttag = curlocater;
1987 endtag = curlocater + strlen(key);
1988 if (endtag == NULL || *endtag != '=')
1994 firstindex = abs(oldstring - curlocater);
1995 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1996 *value = (char*)(oldstring + firstindex);
1998 while (oldstring != starttag)
2000 if (*starttag == '>')
2005 if (*starttag == '<')
2009 if (starttag == NULL) break;
2012 while (NULL != endtag)
2023 if (endtag == NULL) break;
2026 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
2036 if (foundflag == 1) return 0;
2042 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2044 const char *srcstring = NULL;
2045 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2046 char *curlocater, *replocater;
2047 char *starttag, *endtag;
2048 int tagtxtlen = 0, insertflag = 0;
2050 srcstring = eina_strbuf_string_get(srcbuf);
2051 curlocater = strstr(srcstring, key);
2053 if (!curlocater || !srcstring)
2061 starttag = strchr(srcstring, '<');
2062 endtag = strchr(srcstring, '>');
2063 tagtxtlen = endtag - starttag;
2064 if (tagtxtlen <= 0) tagtxtlen = 0;
2065 if (starttag < curlocater && curlocater < endtag) break;
2066 if (endtag != NULL && endtag+1 != NULL)
2067 srcstring = endtag+1;
2070 } while (strlen(srcstring) > 1);
2072 if (starttag && endtag && tagtxtlen > strlen(key))
2074 repbuf = eina_strbuf_new();
2075 diffbuf = eina_strbuf_new();
2076 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2077 srcstring = eina_strbuf_string_get(repbuf);
2078 curlocater = strstr(srcstring, key);
2080 if (curlocater != NULL)
2082 replocater = curlocater + strlen(key) + 1;
2084 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2087 if (replocater-curlocater > strlen(key)+1)
2089 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2098 eina_strbuf_reset(repbuf);
2106 if (repbuf == NULL) repbuf = eina_strbuf_new();
2107 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2111 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2112 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2118 eina_strbuf_prepend(diffbuf, "<");
2119 eina_strbuf_append(diffbuf, ">");
2120 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2124 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2125 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2129 if (repbuf) eina_strbuf_free(repbuf);
2130 if (diffbuf) eina_strbuf_free(diffbuf);
2136 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2138 Eina_Strbuf *sharebuf = NULL;
2140 sharebuf = eina_strbuf_new();
2141 eina_strbuf_append(sharebuf, *srcstring);
2142 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2143 eina_stringshare_del(*srcstring);
2144 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2145 eina_strbuf_free(sharebuf);
2151 _is_width_over(Evas_Object *obj)
2153 Evas_Coord x, y, w, h;
2154 Evas_Coord vx, vy, vw, vh;
2155 Widget_Data *wd = elm_widget_data_get(obj);
2159 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
2161 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
2163 if (x >= 0 && y >= 0)
2166 if (4 < wd->wrap_w && w > wd->wrap_w)
2173 _reverse_ellipsis_entry(Evas_Object *obj)
2175 Widget_Data *wd = elm_widget_data_get(obj);
2176 int cur_fontsize = 0;
2177 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
2178 char *kvalue = NULL;
2179 const char *minfont, *deffont, *maxfont;
2180 const char *ellipsis_string = "...";
2181 int minfontsize, maxfontsize, minshowcount;
2183 minshowcount = strlen(ellipsis_string) + 1;
2184 minfont = edje_object_data_get(wd->ent, "min_font_size");
2185 if (minfont) minfontsize = atoi(minfont);
2186 else minfontsize = 1;
2187 maxfont = edje_object_data_get(wd->ent, "max_font_size");
2188 if (maxfont) maxfontsize = atoi(maxfont);
2189 else maxfontsize = 1;
2190 deffont = edje_object_data_get(wd->ent, "default_font_size");
2191 if (deffont) cur_fontsize = atoi(deffont);
2192 else cur_fontsize = 1;
2193 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
2194 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
2196 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
2198 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
2201 txtbuf = eina_strbuf_new();
2202 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
2204 if (cur_fontsize >= atoi(deffont))
2206 if (txtbuf) eina_strbuf_free(txtbuf);
2210 if (_is_width_over(obj) != 1)
2212 int rev_fontsize = cur_fontsize;
2216 if (rev_fontsize > atoi(deffont))
2219 if (fontbuf != NULL)
2221 eina_strbuf_free(fontbuf);
2224 fontbuf = eina_strbuf_new();
2225 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
2226 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2227 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2229 eina_strbuf_free(fontbuf);
2231 } while (_is_width_over(obj) != 1);
2233 while (_is_width_over(obj))
2236 if (rev_fontsize < atoi(deffont))
2239 if (fontbuf != NULL)
2241 eina_strbuf_free(fontbuf);
2244 fontbuf = eina_strbuf_new();
2245 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
2246 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2247 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2248 eina_strbuf_free(fontbuf);
2253 if (txtbuf) eina_strbuf_free(txtbuf);
2259 _ellipsis_entry_to_width(Evas_Object *obj)
2261 Widget_Data *wd = elm_widget_data_get(obj);
2262 int cur_fontsize = 0, len, jumpcount;
2263 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
2264 char *kvalue = NULL;
2265 const char *minfont, *deffont, *maxfont;
2266 const char *ellipsis_string = "...";
2267 int minfontsize, maxfontsize, minshowcount;
2268 int i, tagend, cur_len;
2271 minshowcount = strlen(ellipsis_string) + 1;
2272 minfont = edje_object_data_get(wd->ent, "min_font_size");
2273 if (minfont) minfontsize = atoi(minfont);
2274 else minfontsize = 1;
2275 maxfont = edje_object_data_get(wd->ent, "max_font_size");
2276 if (maxfont) maxfontsize = atoi(maxfont);
2277 else maxfontsize = 1;
2278 deffont = edje_object_data_get(wd->ent, "default_font_size");
2279 if (deffont) cur_fontsize = atoi(deffont);
2280 else cur_fontsize = 1;
2281 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
2282 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
2284 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
2286 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
2289 txtbuf = eina_strbuf_new();
2290 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
2292 while (_is_width_over(obj))
2294 if (wd->ellipsis_threshold == 0)
2295 wd->ellipsis_threshold = _entry_length_get(obj);
2296 if (cur_fontsize > minfontsize)
2299 if (fontbuf != NULL)
2301 eina_strbuf_free(fontbuf);
2304 fontbuf = eina_strbuf_new();
2305 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
2306 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2307 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2308 eina_strbuf_free(fontbuf);
2310 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2314 len = _entry_length_get(obj);
2315 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2316 cur_len = strlen(cur_str);
2318 for (i = 0; i < len; i++)
2320 if(cur_str[i] == '>' && cur_str[i+1] != '\0' &&
2321 cur_str[i+1] != '<')
2328 while (jumpcount < len-strlen(ellipsis_string))
2330 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2334 eina_strbuf_free(txtbuf);
2337 txtbuf = eina_strbuf_new();
2338 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
2339 eina_strbuf_append(txtbuf, ellipsis_string);
2340 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
2341 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2342 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2344 if (_is_width_over(obj))
2352 if (txtbuf) eina_strbuf_free(txtbuf);
2357 static Eina_Bool *_textinput_control_function(void *data,void *input_data)
2359 /* calculate character count */
2360 Evas_Object *entry = (Evas_Object *)data;
2361 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
2364 size_t insert_text_len=0;
2365 char *text = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2367 size_t remain_bytes;
2370 byte_len = strlen(text); /* no of bytes */
2371 remain_bytes = wd->max_no_of_bytes - byte_len;
2372 sprintf(buf,"%d",remain_bytes);
2373 //edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
2376 insert_text = (char *)input_data;
2377 insert_text_len = strlen(insert_text);
2378 if (remain_bytes < insert_text_len)
2380 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2383 if (byte_len >= wd->max_no_of_bytes)
2385 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2395 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2397 Widget_Data *wd = elm_widget_data_get(data);
2399 Elm_Entry_Text_Filter *tf;
2401 if (type == EDJE_TEXT_FILTER_FORMAT)
2404 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2406 tf->func(tf->data, data, text);
2413 * This adds an entry to @p parent object.
2415 * @param parent The parent object
2416 * @return The new object or NULL if it cannot be created
2421 elm_entry_add(Evas_Object *parent)
2423 Evas_Object *obj, *top;
2427 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2429 wd = ELM_NEW(Widget_Data);
2430 e = evas_object_evas_get(parent);
2431 if (!e) return NULL;
2432 wd->bgcolor = EINA_FALSE;
2433 wd->bg = evas_object_rectangle_add(e);
2434 evas_object_color_set(wd->bg, 0, 0, 0, 0);
2435 obj = elm_widget_add(e);
2436 ELM_SET_WIDTYPE(widtype, "entry");
2437 elm_widget_type_set(obj, "entry");
2438 elm_widget_sub_object_add(parent, obj);
2439 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2440 elm_widget_data_set(obj, wd);
2441 elm_widget_del_hook_set(obj, _del_hook);
2442 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2443 elm_widget_theme_hook_set(obj, _theme_hook);
2444 elm_widget_disable_hook_set(obj, _disable_hook);
2445 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2446 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2447 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2448 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2449 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2450 elm_widget_can_focus_set(obj, EINA_TRUE);
2451 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2453 wd->linewrap = EINA_TRUE;
2454 wd->ellipsis = EINA_FALSE;
2455 wd->char_linewrap= EINA_FALSE;
2456 wd->editable = EINA_TRUE;
2457 wd->disabled = EINA_FALSE;
2458 wd->context_menu = EINA_TRUE;
2459 wd->autosave = EINA_TRUE;
2460 wd->textonly = EINA_FALSE;
2461 wd->autoperiod = EINA_TRUE;
2463 wd->ellipsis_threshold = 0;
2465 wd->ent = edje_object_add(e);
2466 edje_object_item_provider_set(wd->ent, _get_item, obj);
2467 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2468 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2469 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2470 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2472 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2474 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2477 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2478 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2479 _signal_entry_changed, obj);
2480 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2481 _signal_handler_move_start, obj);
2482 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2483 _signal_handler_move_end, obj);
2484 edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2485 _signal_handler_moving, obj);
2486 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2487 _signal_selection_start, obj);
2488 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2489 _signal_selection_end, obj);
2490 edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2491 _signal_magnifier_changed, obj);
2492 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2493 _signal_selection_changed, obj);
2494 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2495 _signal_selection_cleared, obj);
2496 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2497 _signal_entry_paste_request, obj);
2498 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2499 _signal_entry_copy_notify, obj);
2500 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2501 _signal_entry_cut_notify, obj);
2502 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2503 _signal_cursor_changed, obj);
2504 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2505 _signal_anchor_down, obj);
2506 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2507 _signal_anchor_up, obj);
2508 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2509 _signal_anchor_move, obj);
2510 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2511 _signal_anchor_in, obj);
2512 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2513 _signal_anchor_out, obj);
2514 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2515 _signal_key_enter, obj);
2516 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2517 _signal_mouse_down, obj);
2518 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2519 _signal_mouse_clicked, obj);
2520 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2521 _signal_mouse_double, obj);
2522 edje_object_part_text_set(wd->ent, "elm.text", "");
2523 elm_widget_resize_object_set(obj, wd->ent);
2526 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2528 #ifdef HAVE_ELEMENTARY_X
2529 top = elm_widget_top_get(obj);
2530 if ((top) && (elm_win_xwindow_get(top)))
2532 wd->sel_notify_handler =
2533 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2534 _event_selection_notify, obj);
2535 wd->sel_clear_handler =
2536 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2537 _event_selection_clear, obj);
2540 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2543 entries = eina_list_prepend(entries, obj);
2545 // module - find module for entry
2546 wd->api = _module(obj);
2547 // if found - hook in
2548 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2550 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2551 // TODO: and save some bytes, making descriptions per-class and not instance!
2552 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2556 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2558 ELM_CHECK_WIDTYPE(obj, widtype);
2559 Widget_Data *wd = elm_widget_data_get(obj);
2561 ext_mod->cancel = _cancel;
2562 ext_mod->copy = _copy;
2563 ext_mod->cut = _cut;
2564 ext_mod->paste = _paste;
2565 ext_mod->select = _select;
2566 ext_mod->selectall = _selectall;
2567 ext_mod->ent = wd->ent;
2568 ext_mod->items = wd->items;
2569 ext_mod->longpress_timer = wd->longpress_timer;
2570 ext_mod->editable = wd->editable;
2571 ext_mod->have_selection = wd->have_selection;
2572 ext_mod->password = wd->password;
2573 ext_mod->selmode = wd->selmode;
2574 ext_mod->cnpinit = _cnpinit;
2575 ext_mod->context_menu = wd->context_menu;
2576 ext_mod->textonly = wd->textonly;
2580 * This sets the entry object not to line wrap. All input will
2581 * be on a single line, and the entry box will extend with user input.
2583 * @param obj The entry object
2584 * @param single_line If true, the text in the entry
2585 * will be on a single line.
2590 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2592 ELM_CHECK_WIDTYPE(obj, widtype);
2593 Widget_Data *wd = elm_widget_data_get(obj);
2595 Ecore_IMF_Context *ic;
2597 if (wd->single_line == single_line) return;
2598 wd->single_line = single_line;
2599 wd->linewrap = EINA_FALSE;
2600 wd->char_linewrap = EINA_FALSE;
2601 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2602 t = eina_stringshare_add(elm_entry_entry_get(obj));
2603 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2604 elm_entry_entry_set(obj, t);
2605 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2606 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2607 ic = elm_entry_imf_context_get(obj);
2610 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2613 eina_stringshare_del(t);
2618 * This returns true if the entry has been set to single line mode.
2619 * See also elm_entry_single_line_set().
2621 * @param obj The entry object
2622 * @return single_line If true, the text in the entry is set to display
2628 elm_entry_single_line_get(const Evas_Object *obj)
2630 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2631 Widget_Data *wd = elm_widget_data_get(obj);
2632 if (!wd) return EINA_FALSE;
2633 return wd->single_line;
2637 * This sets the entry object to password mode. All text entered
2638 * and/or displayed within the widget will be replaced with asterisks (*).
2640 * @param obj The entry object
2641 * @param password If true, password mode is enabled.
2646 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2648 ELM_CHECK_WIDTYPE(obj, widtype);
2649 Widget_Data *wd = elm_widget_data_get(obj);
2650 Ecore_IMF_Context *ic;
2653 if (wd->password == password) return;
2654 wd->password = password;
2655 wd->single_line = EINA_TRUE;
2656 wd->linewrap = EINA_FALSE;
2657 wd->char_linewrap = EINA_FALSE;
2658 if (_elm_config->password_show_last_character)
2659 wd->show_last_character = EINA_TRUE;
2660 t = eina_stringshare_add(elm_entry_entry_get(obj));
2661 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2662 elm_entry_entry_set(obj, t);
2667 elm_entry_autoperiod_set(obj, EINA_FALSE);
2669 if (wd->autocapital)
2670 elm_entry_autocapitalization_set(obj, EINA_FALSE);
2673 ic = elm_entry_imf_context_get(obj);
2675 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2677 eina_stringshare_del(t);
2683 * This returns whether password mode is enabled.
2684 * See also elm_entry_password_set().
2686 * @param obj The entry object
2687 * @return If true, the entry is set to display all characters
2693 elm_entry_password_get(const Evas_Object *obj)
2695 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2696 Widget_Data *wd = elm_widget_data_get(obj);
2697 if (!wd) return EINA_FALSE;
2698 return wd->password;
2702 * This sets the text displayed within the entry to @p entry.
2704 * @param obj The entry object
2705 * @param entry The text to be displayed
2710 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2712 ELM_CHECK_WIDTYPE(obj, widtype);
2713 Widget_Data *wd = elm_widget_data_get(obj);
2715 if (!entry) entry = "";
2716 if(wd->max_no_of_bytes)
2718 int len = strlen(entry);
2719 if(len > wd->max_no_of_bytes)
2721 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2725 edje_object_part_text_set(wd->ent, "elm.text", entry);
2726 if (wd->text) eina_stringshare_del(wd->text);
2728 wd->changed = EINA_TRUE;
2733 * This returns the text currently shown in object @p entry.
2734 * See also elm_entry_entry_set().
2736 * @param obj The entry object
2737 * @return The currently displayed text or NULL on failure
2742 elm_entry_entry_get(const Evas_Object *obj)
2744 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2745 Widget_Data *wd = elm_widget_data_get(obj);
2747 if (!wd) return NULL;
2749 if ((wd->text)&&(wd->password))
2750 return elm_entry_markup_to_utf8(wd->text);
2752 if (wd->text) return wd->text;
2753 text = edje_object_part_text_get(wd->ent, "elm.text");
2756 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2759 eina_stringshare_replace(&wd->text, text);
2760 if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2766 * This returns EINA_TRUE if the entry is empty/there was an error
2767 * and EINA_FALSE if it is not empty.
2769 * @param obj The entry object
2770 * @return If the entry is empty or not.
2775 elm_entry_is_empty(const Evas_Object *obj)
2777 /* FIXME: until there's support for that in textblock, we just check
2778 * to see if the there is text or not. */
2779 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2780 Widget_Data *wd = elm_widget_data_get(obj);
2781 const Evas_Object *tb;
2782 Evas_Textblock_Cursor *cur;
2784 if (!wd) return EINA_TRUE;
2785 /* It's a hack until we get the support suggested above.
2786 * We just create a cursor, point it to the begining, and then
2787 * try to advance it, if it can advance, the tb is not empty,
2788 * otherwise it is. */
2789 tb = edje_object_part_object_get(wd->ent, "elm.text");
2790 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2791 actually, ok for the time being, thsese hackish stuff will be removed
2792 once evas 1.0 is out*/
2793 evas_textblock_cursor_pos_set(cur, 0);
2794 ret = evas_textblock_cursor_char_next(cur);
2795 evas_textblock_cursor_free(cur);
2801 * This returns all selected text within the entry.
2803 * @param obj The entry object
2804 * @return The selected text within the entry or NULL on failure
2809 elm_entry_selection_get(const Evas_Object *obj)
2811 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2812 Widget_Data *wd = elm_widget_data_get(obj);
2813 if (!wd) return NULL;
2814 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2818 * This inserts text in @p entry where the current cursor position.
2820 * This inserts text at the cursor position is as if it was typed
2821 * by the user (note this also allows markup which a user
2822 * can't just "type" as it would be converted to escaped text, so this
2823 * call can be used to insert things like emoticon items or bold push/pop
2824 * tags, other font and color change tags etc.)
2826 * @param obj The entry object
2827 * @param entry The text to insert
2832 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2834 ELM_CHECK_WIDTYPE(obj, widtype);
2835 Widget_Data *wd = elm_widget_data_get(obj);
2837 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2839 if (cnpwidgetdata == obj)
2840 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2842 wd->changed = EINA_TRUE;
2847 * This enables word line wrapping in the entry object. It is the opposite
2848 * of elm_entry_single_line_set(). Additionally, setting this disables
2849 * character line wrapping.
2850 * See also elm_entry_line_char_wrap_set().
2852 * @param obj The entry object
2853 * @param wrap If true, the entry will be wrapped once it reaches the end
2854 * of the object. Wrapping will occur at the end of the word before the end of the
2860 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2862 ELM_CHECK_WIDTYPE(obj, widtype);
2863 Widget_Data *wd = elm_widget_data_get(obj);
2866 if (wd->linewrap == wrap) return;
2867 wd->linewrap = wrap;
2869 wd->char_linewrap = EINA_FALSE;
2870 t = eina_stringshare_add(elm_entry_entry_get(obj));
2871 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2872 elm_entry_entry_set(obj, t);
2873 eina_stringshare_del(t);
2878 * Set wrap width of the entry
2880 * @param obj The entry object
2881 * @param w The wrap width in pixels at a minimum where words need to wrap
2885 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2887 Widget_Data *wd = elm_widget_data_get(obj);
2888 if (wd->wrap_w == w) return;
2894 * get wrap width of the entry
2896 * @param obj The entry object
2897 * @return The wrap width in pixels at a minimum where words need to wrap
2901 elm_entry_wrap_width_get(const Evas_Object *obj)
2903 Widget_Data *wd = elm_widget_data_get(obj);
2908 * This enables character line wrapping in the entry object. It is the opposite
2909 * of elm_entry_single_line_set(). Additionally, setting this disables
2910 * word line wrapping.
2911 * See also elm_entry_line_wrap_set().
2913 * @param obj The entry object
2914 * @param wrap If true, the entry will be wrapped once it reaches the end
2915 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2920 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2922 ELM_CHECK_WIDTYPE(obj, widtype);
2923 Widget_Data *wd = elm_widget_data_get(obj);
2926 if (wd->char_linewrap == wrap) return;
2927 wd->char_linewrap = wrap;
2928 if(wd->char_linewrap)
2929 wd->linewrap = EINA_FALSE;
2930 t = eina_stringshare_add(elm_entry_entry_get(obj));
2931 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2932 elm_entry_entry_set(obj, t);
2933 eina_stringshare_del(t);
2938 * This sets the editable attribute of the entry.
2940 * @param obj The entry object
2941 * @param editable If true, the entry will be editable by the user.
2942 * If false, it will be set to the disabled state.
2947 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2949 ELM_CHECK_WIDTYPE(obj, widtype);
2950 Widget_Data *wd = elm_widget_data_get(obj);
2953 if (wd->editable == editable) return;
2954 wd->editable = editable;
2955 t = eina_stringshare_add(elm_entry_entry_get(obj));
2956 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2957 elm_entry_entry_set(obj, t);
2958 eina_stringshare_del(t);
2961 #ifdef HAVE_ELEMENTARY_X
2963 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2965 elm_drop_target_del(obj);
2970 * This gets the editable attribute of the entry.
2971 * See also elm_entry_editable_set().
2973 * @param obj The entry object
2974 * @return If true, the entry is editable by the user.
2975 * If false, it is not editable by the user
2980 elm_entry_editable_get(const Evas_Object *obj)
2982 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2983 Widget_Data *wd = elm_widget_data_get(obj);
2984 if (!wd) return EINA_FALSE;
2985 return wd->editable;
2989 * This drops any existing text selection within the entry.
2991 * @param obj The entry object
2996 elm_entry_select_none(Evas_Object *obj)
2998 ELM_CHECK_WIDTYPE(obj, widtype);
2999 Widget_Data *wd = elm_widget_data_get(obj);
3003 wd->selmode = EINA_FALSE;
3004 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3005 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3007 wd->have_selection = EINA_FALSE;
3008 edje_object_part_text_select_none(wd->ent, "elm.text");
3012 * This selects all text within the entry.
3014 * @param obj The entry object
3019 elm_entry_select_all(Evas_Object *obj)
3021 ELM_CHECK_WIDTYPE(obj, widtype);
3022 Widget_Data *wd = elm_widget_data_get(obj);
3026 wd->selmode = EINA_FALSE;
3027 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3028 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3030 wd->have_selection = EINA_TRUE;
3031 edje_object_part_text_select_all(wd->ent, "elm.text");
3035 * This function returns the geometry of the cursor.
3037 * It's useful if you want to draw something on the cursor (or where it is),
3038 * or for example in the case of scrolled entry where you want to show the
3041 * @param obj The entry object
3042 * @param x returned geometry
3043 * @param y returned geometry
3044 * @param w returned geometry
3045 * @param h returned geometry
3046 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3051 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3053 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3054 Widget_Data *wd = elm_widget_data_get(obj);
3055 if (!wd) return EINA_FALSE;
3056 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3061 * This moves the cursor one place to the right within the entry.
3063 * @param obj The entry object
3064 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3069 elm_entry_cursor_next(Evas_Object *obj)
3071 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3072 Widget_Data *wd = elm_widget_data_get(obj);
3073 if (!wd) return EINA_FALSE;
3074 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3078 * This moves the cursor one place to the left within the entry.
3080 * @param obj The entry object
3081 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3086 elm_entry_cursor_prev(Evas_Object *obj)
3088 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3089 Widget_Data *wd = elm_widget_data_get(obj);
3090 if (!wd) return EINA_FALSE;
3091 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3095 * This moves the cursor one line up within the entry.
3097 * @param obj The entry object
3098 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3103 elm_entry_cursor_up(Evas_Object *obj)
3105 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3106 Widget_Data *wd = elm_widget_data_get(obj);
3107 if (!wd) return EINA_FALSE;
3108 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3112 * This moves the cursor one line down within the entry.
3114 * @param obj The entry object
3115 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3120 elm_entry_cursor_down(Evas_Object *obj)
3122 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3123 Widget_Data *wd = elm_widget_data_get(obj);
3124 if (!wd) return EINA_FALSE;
3125 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3129 * This moves the cursor to the beginning of the entry.
3131 * @param obj The entry object
3136 elm_entry_cursor_begin_set(Evas_Object *obj)
3138 ELM_CHECK_WIDTYPE(obj, widtype);
3139 Widget_Data *wd = elm_widget_data_get(obj);
3141 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3145 * This moves the cursor to the end of the entry.
3147 * @param obj The entry object
3152 elm_entry_cursor_end_set(Evas_Object *obj)
3154 ELM_CHECK_WIDTYPE(obj, widtype);
3155 Widget_Data *wd = elm_widget_data_get(obj);
3157 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3161 * This moves the cursor to the beginning of the current line.
3163 * @param obj The entry object
3168 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3170 ELM_CHECK_WIDTYPE(obj, widtype);
3171 Widget_Data *wd = elm_widget_data_get(obj);
3173 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3177 * This moves the cursor to the end of the current line.
3179 * @param obj The entry object
3184 elm_entry_cursor_line_end_set(Evas_Object *obj)
3186 ELM_CHECK_WIDTYPE(obj, widtype);
3187 Widget_Data *wd = elm_widget_data_get(obj);
3189 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3193 * This begins a selection within the entry as though
3194 * the user were holding down the mouse button to make a selection.
3196 * @param obj The entry object
3201 elm_entry_cursor_selection_begin(Evas_Object *obj)
3203 ELM_CHECK_WIDTYPE(obj, widtype);
3204 Widget_Data *wd = elm_widget_data_get(obj);
3206 edje_object_part_text_select_begin(wd->ent, "elm.text");
3210 * This ends a selection within the entry as though
3211 * the user had just released the mouse button while making a selection.
3213 * @param obj The entry object
3218 elm_entry_cursor_selection_end(Evas_Object *obj)
3220 ELM_CHECK_WIDTYPE(obj, widtype);
3221 Widget_Data *wd = elm_widget_data_get(obj);
3223 edje_object_part_text_select_extend(wd->ent, "elm.text");
3227 * TODO: fill this in
3229 * @param obj The entry object
3230 * @return TODO: fill this in
3235 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3237 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3238 Widget_Data *wd = elm_widget_data_get(obj);
3239 if (!wd) return EINA_FALSE;
3240 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3244 * This returns whether the cursor is visible.
3246 * @param obj The entry object
3247 * @return If true, the cursor is visible.
3252 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3254 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3255 Widget_Data *wd = elm_widget_data_get(obj);
3256 if (!wd) return EINA_FALSE;
3257 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3261 * TODO: fill this in
3263 * @param obj The entry object
3264 * @return TODO: fill this in
3269 elm_entry_cursor_content_get(const Evas_Object *obj)
3271 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3272 Widget_Data *wd = elm_widget_data_get(obj);
3273 if (!wd) return NULL;
3274 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3278 * This executes a "cut" action on the selected text in the entry.
3280 * @param obj The entry object
3285 elm_entry_selection_cut(Evas_Object *obj)
3287 ELM_CHECK_WIDTYPE(obj, widtype);
3288 Widget_Data *wd = elm_widget_data_get(obj);
3290 _cut(obj, NULL, NULL);
3294 * This executes a "copy" action on the selected text in the entry.
3296 * @param obj The entry object
3301 elm_entry_selection_copy(Evas_Object *obj)
3303 ELM_CHECK_WIDTYPE(obj, widtype);
3304 Widget_Data *wd = elm_widget_data_get(obj);
3306 _copy(obj, NULL, NULL);
3310 * This executes a "paste" action in the entry.
3312 * @param obj The entry object
3317 elm_entry_selection_paste(Evas_Object *obj)
3319 ELM_CHECK_WIDTYPE(obj, widtype);
3320 Widget_Data *wd = elm_widget_data_get(obj);
3322 _paste(obj, NULL, NULL);
3326 * This clears and frees the items in a entry's contextual (right click) menu.
3328 * @param obj The entry object
3333 elm_entry_context_menu_clear(Evas_Object *obj)
3335 ELM_CHECK_WIDTYPE(obj, widtype);
3336 Widget_Data *wd = elm_widget_data_get(obj);
3337 Elm_Entry_Context_Menu_Item *it;
3339 EINA_LIST_FREE(wd->items, it)
3341 eina_stringshare_del(it->label);
3342 eina_stringshare_del(it->icon_file);
3343 eina_stringshare_del(it->icon_group);
3349 * This adds an item to the entry's contextual menu.
3351 * @param obj The entry object
3352 * @param label The item's text label
3353 * @param icon_file The item's icon file
3354 * @param icon_type The item's icon type
3355 * @param func The callback to execute when the item is clicked
3356 * @param data The data to associate with the item for related functions
3361 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)
3363 ELM_CHECK_WIDTYPE(obj, widtype);
3364 Widget_Data *wd = elm_widget_data_get(obj);
3365 Elm_Entry_Context_Menu_Item *it;
3367 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3369 wd->items = eina_list_append(wd->items, it);
3371 it->label = eina_stringshare_add(label);
3372 it->icon_file = eina_stringshare_add(icon_file);
3373 it->icon_type = icon_type;
3375 it->data = (void *)data;
3379 * This disables the entry's contextual (right click) menu.
3381 * @param obj The entry object
3382 * @param disabled If true, the menu is disabled
3387 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3389 ELM_CHECK_WIDTYPE(obj, widtype);
3390 Widget_Data *wd = elm_widget_data_get(obj);
3392 if (wd->context_menu == !disabled) return;
3393 wd->context_menu = !disabled;
3397 * This returns whether the entry's contextual (right click) menu is disabled.
3399 * @param obj The entry object
3400 * @return If true, the menu is disabled
3405 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3407 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3408 Widget_Data *wd = elm_widget_data_get(obj);
3409 if (!wd) return EINA_FALSE;
3410 return !wd->context_menu;
3414 * This appends a custom item provider to the list for that entry
3416 * This appends the given callback. The list is walked from beginning to end
3417 * with each function called given the item href string in the text. If the
3418 * function returns an object handle other than NULL (it should create an
3419 * and object to do this), then this object is used to replace that item. If
3420 * not the next provider is called until one provides an item object, or the
3421 * default provider in entry does.
3423 * @param obj The entry object
3424 * @param func The function called to provide the item object
3425 * @param data The data passed to @p func
3430 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3432 ELM_CHECK_WIDTYPE(obj, widtype);
3433 Widget_Data *wd = elm_widget_data_get(obj);
3435 EINA_SAFETY_ON_NULL_RETURN(func);
3436 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3440 wd->item_providers = eina_list_append(wd->item_providers, ip);
3444 * This prepends a custom item provider to the list for that entry
3446 * This prepends the given callback. See elm_entry_item_provider_append() for
3449 * @param obj The entry object
3450 * @param func The function called to provide the item object
3451 * @param data The data passed to @p func
3456 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3458 ELM_CHECK_WIDTYPE(obj, widtype);
3459 Widget_Data *wd = elm_widget_data_get(obj);
3461 EINA_SAFETY_ON_NULL_RETURN(func);
3462 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3466 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3470 * This removes a custom item provider to the list for that entry
3472 * This removes the given callback. See elm_entry_item_provider_append() for
3475 * @param obj The entry object
3476 * @param func The function called to provide the item object
3477 * @param data The data passed to @p func
3482 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3484 ELM_CHECK_WIDTYPE(obj, widtype);
3485 Widget_Data *wd = elm_widget_data_get(obj);
3487 Elm_Entry_Item_Provider *ip;
3489 EINA_SAFETY_ON_NULL_RETURN(func);
3490 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3492 if ((ip->func == func) && (ip->data == data))
3494 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3502 * Append a filter function for text inserted in the entry
3504 * Append the given callback to the list. This functions will be called
3505 * whenever any text is inserted into the entry, with the text to be inserted
3506 * as a parameter. The callback function is free to alter the text in any way
3507 * it wants, but it must remember to free the given pointer and update it.
3508 * If the new text is to be discarded, the function can free it and set it text
3509 * parameter to NULL. This will also prevent any following filters from being
3512 * @param obj The entry object
3513 * @param func The function to use as text filter
3514 * @param data User data to pass to @p func
3519 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3522 Elm_Entry_Text_Filter *tf;
3523 ELM_CHECK_WIDTYPE(obj, widtype);
3525 wd = elm_widget_data_get(obj);
3527 EINA_SAFETY_ON_NULL_RETURN(func);
3529 tf = ELM_NEW(Elm_Entry_Text_Filter);
3533 wd->text_filters = eina_list_append(wd->text_filters, tf);
3537 * Prepend a filter function for text insdrted in the entry
3539 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3540 * for more information
3542 * @param obj The entry object
3543 * @param func The function to use as text filter
3544 * @param data User data to pass to @p func
3549 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3552 Elm_Entry_Text_Filter *tf;
3553 ELM_CHECK_WIDTYPE(obj, widtype);
3555 wd = elm_widget_data_get(obj);
3557 EINA_SAFETY_ON_NULL_RETURN(func);
3559 tf = ELM_NEW(Elm_Entry_Text_Filter);
3563 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3567 * Remove a filter from the list
3569 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3570 * for more information.
3572 * @param obj The entry object
3573 * @param func The filter function to remove
3574 * @param data The user data passed when adding the function
3579 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3583 Elm_Entry_Text_Filter *tf;
3584 ELM_CHECK_WIDTYPE(obj, widtype);
3586 wd = elm_widget_data_get(obj);
3588 EINA_SAFETY_ON_NULL_RETURN(func);
3590 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3592 if ((tf->func == func) && (tf->data == data))
3594 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3602 * This converts a markup (HTML-like) string into UTF-8.
3604 * @param s The string (in markup) to be converted
3605 * @return The converted string (in UTF-8)
3610 elm_entry_markup_to_utf8(const char *s)
3612 char *ss = _elm_util_mkup_to_text(s);
3613 if (!ss) ss = strdup("");
3618 * This converts a UTF-8 string into markup (HTML-like).
3620 * @param s The string (in UTF-8) to be converted
3621 * @return The converted string (in markup)
3626 elm_entry_utf8_to_markup(const char *s)
3628 char *ss = _elm_util_text_to_mkup(s);
3629 if (!ss) ss = strdup("");
3634 * Get the input method context in the entry widget
3636 * @param obj The entry object
3637 * @return The input method context
3641 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3643 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3644 Widget_Data *wd = elm_widget_data_get(obj);
3645 if (!wd || !wd->ent) return NULL;
3647 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3651 * Set whether entry should enable the return key on soft keyboard automatically
3653 * @param obj The entry object
3654 * @param on If true, entry enables the return key on soft keyboard automatically.
3659 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3661 ELM_CHECK_WIDTYPE(obj, widtype);
3662 Widget_Data *wd = elm_widget_data_get(obj);
3665 wd->autoreturnkey = on;
3666 _check_enable_returnkey(obj);
3670 * Set whether entry should support auto capitalization
3672 * @param obj The entry object
3673 * @param on If true, entry suports auto capitalization.
3678 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3680 ELM_CHECK_WIDTYPE(obj, widtype);
3681 Widget_Data *wd = elm_widget_data_get(obj);
3685 wd->autocapital = EINA_FALSE;
3687 wd->autocapital = autocap;
3689 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3690 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3691 wd->autocapital = EINA_FALSE;
3693 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3697 * Set whether entry should support auto period
3699 * @param obj The entry object
3700 * @param on If true, entry suports auto period.
3705 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3707 ELM_CHECK_WIDTYPE(obj, widtype);
3708 Widget_Data *wd = elm_widget_data_get(obj);
3712 wd->autoperiod = EINA_FALSE;
3714 wd->autoperiod = autoperiod;
3716 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3717 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3718 wd->autoperiod = EINA_FALSE;
3720 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3724 * Set the font size on the entry object
3726 * @param obj The entry object
3727 * @param size font size
3732 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3734 ELM_CHECK_WIDTYPE(obj, widtype);
3735 Widget_Data *wd = elm_widget_data_get(obj);
3736 Eina_Strbuf *fontbuf = NULL;
3741 t = eina_stringshare_add(elm_entry_entry_get(obj));
3742 fontbuf = eina_strbuf_new();
3743 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3745 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3747 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3749 elm_entry_entry_set(obj, t);
3753 eina_strbuf_free(fontbuf);
3754 eina_stringshare_del(t);
3758 * Set the text align on the entry object
3760 * @param obj The entry object
3761 * @param align align mode
3766 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3768 ELM_CHECK_WIDTYPE(obj, widtype);
3769 Widget_Data *wd = elm_widget_data_get(obj);
3774 t = eina_stringshare_add(elm_entry_entry_get(obj));
3776 if (len <= 0) return;
3778 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3779 elm_entry_entry_set(obj, t);
3783 eina_stringshare_del(t);
3787 * Set the text color on the entry object
3789 * @param obj The entry object
3790 * @param r Red property background color of The entry object
3791 * @param g Green property background color of The entry object
3792 * @param b Blue property background color of The entry object
3793 * @param a Alpha property background alpha of The entry object
3798 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3800 ELM_CHECK_WIDTYPE(obj, widtype);
3801 Widget_Data *wd = elm_widget_data_get(obj);
3802 Eina_Strbuf *colorbuf = NULL;
3807 t = eina_stringshare_add(elm_entry_entry_get(obj));
3809 if (len <= 0) return;
3810 colorbuf = eina_strbuf_new();
3811 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3813 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3815 elm_entry_entry_set(obj, t);
3819 eina_strbuf_free(colorbuf);
3820 eina_stringshare_del(t);
3824 * Set background color of the entry
3826 * @param obj The entry object
3827 * @param r Red property background color of The entry object
3828 * @param g Green property background color of The entry object
3829 * @param b Blue property background color of The entry object
3830 * @param a Alpha property background alpha of The entry object
3834 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3836 ELM_CHECK_WIDTYPE(obj, widtype);
3837 Widget_Data *wd = elm_widget_data_get(obj);
3838 evas_object_color_set(wd->bg, r, g, b, a);
3840 if (wd->bgcolor == EINA_FALSE)
3843 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3848 * Set the ellipsis behavior of the entry
3850 * @param obj The entry object
3851 * @param ellipsis To ellipsis text or not
3855 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3857 ELM_CHECK_WIDTYPE(obj, widtype);
3858 Widget_Data *wd = elm_widget_data_get(obj);
3859 if (wd->ellipsis == ellipsis) return;
3860 wd->ellipsis = ellipsis;
3866 * Filter inserted text based on user defined character and byte limits
3868 * Add this filter to an entry to limit the characters that it will accept
3869 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3870 * The funtion works on the UTF-8 representation of the string, converting
3871 * it from the set markup, thus not accounting for any format in it.
3873 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3874 * it as data when setting the filter. In it it's possible to set limits
3875 * by character count or bytes (any of them is disabled if 0), and both can
3876 * be set at the same time. In that case, it first checks for characters,
3879 * The function will cut the inserted text in order to allow only the first
3880 * number of characters that are still allowed. The cut is made in
3881 * characters, even when limiting by bytes, in order to always contain
3882 * valid ones and avoid half unicode characters making it in.
3887 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3889 Elm_Entry_Filter_Limit_Size *lim = data;
3892 const char *(*text_get)(const Evas_Object *);
3893 const char *widget_type;
3895 EINA_SAFETY_ON_NULL_RETURN(data);
3896 EINA_SAFETY_ON_NULL_RETURN(entry);
3897 EINA_SAFETY_ON_NULL_RETURN(text);
3899 /* hack. I don't want to copy the entire function to work with
3901 widget_type = elm_widget_type_get(entry);
3902 if (!strcmp(widget_type, "entry"))
3903 text_get = elm_entry_entry_get;
3904 else if (!strcmp(widget_type, "scrolled_entry"))
3905 text_get = elm_scrolled_entry_entry_get;
3909 current = elm_entry_markup_to_utf8(text_get(entry));
3911 if (lim->max_char_count > 0)
3914 len = evas_string_char_len_get(current);
3915 if (len >= lim->max_char_count)
3917 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3923 newlen = evas_string_char_len_get(*text);
3924 cut = strlen(*text);
3925 while ((len + newlen) > lim->max_char_count)
3927 cut = evas_string_char_prev_get(*text, cut, NULL);
3933 if (lim->max_byte_count > 0)
3935 len = strlen(current);
3936 if (len >= lim->max_byte_count)
3938 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3944 newlen = strlen(*text);
3945 while ((len + newlen) > lim->max_byte_count)
3947 int p = evas_string_char_prev_get(*text, newlen, NULL);
3948 newlen -= (newlen - p);
3951 (*text)[newlen] = 0;
3962 * Filter inserted text based on accepted or rejected sets of characters
3964 * Add this filter to an entry to restrict the set of accepted characters
3965 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3966 * This structure contains both accepted and rejected sets, but they are
3967 * mutually exclusive. If accepted is set, it will be used, otherwise it
3968 * goes on to the rejected set.
3971 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3973 Elm_Entry_Filter_Accept_Set *as = data;
3977 int read_idx, last_read_idx = 0, read_char;
3979 EINA_SAFETY_ON_NULL_RETURN(data);
3980 EINA_SAFETY_ON_NULL_RETURN(text);
3982 if ((!as->accepted) && (!as->rejected))
3988 goes_in = EINA_TRUE;
3993 goes_in = EINA_FALSE;
3997 read_idx = evas_string_char_next_get(*text, 0, &read_char);
4000 int cmp_idx, cmp_char;
4001 Eina_Bool in_set = EINA_FALSE;
4003 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4006 if (read_char == cmp_char)
4011 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4013 if (in_set == goes_in)
4015 int size = read_idx - last_read_idx;
4016 const char *src = (*text) + last_read_idx;
4018 memcpy(insert, *text + last_read_idx, size);
4021 last_read_idx = read_idx;
4022 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4028 * This sets the file (and implicitly loads it) for the text to display and
4029 * then edit. All changes are written back to the file after a short delay if
4030 * the entry object is set to autosave.
4032 * @param obj The entry object
4033 * @param file The path to the file to load and save
4034 * @param format The file format
4039 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4041 ELM_CHECK_WIDTYPE(obj, widtype);
4042 Widget_Data *wd = elm_widget_data_get(obj);
4044 if (wd->delay_write)
4046 ecore_timer_del(wd->delay_write);
4047 wd->delay_write = NULL;
4049 if (wd->autosave) _save(obj);
4050 eina_stringshare_replace(&wd->file, file);
4051 wd->format = format;
4056 * Gets the file to load and save and the file format
4058 * @param obj The entry object
4059 * @param file The path to the file to load and save
4060 * @param format The file format
4065 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4067 ELM_CHECK_WIDTYPE(obj, widtype);
4068 Widget_Data *wd = elm_widget_data_get(obj);
4070 if (file) *file = wd->file;
4071 if (format) *format = wd->format;
4075 * This function writes any changes made to the file set with
4076 * elm_entry_file_set()
4078 * @param obj The entry object
4083 elm_entry_file_save(Evas_Object *obj)
4085 ELM_CHECK_WIDTYPE(obj, widtype);
4086 Widget_Data *wd = elm_widget_data_get(obj);
4088 if (wd->delay_write)
4090 ecore_timer_del(wd->delay_write);
4091 wd->delay_write = NULL;
4094 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4098 * This sets the entry object to 'autosave' the loaded text file or not.
4100 * @param obj The entry object
4101 * @param autosave Autosave the loaded file or not
4106 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4108 ELM_CHECK_WIDTYPE(obj, widtype);
4109 Widget_Data *wd = elm_widget_data_get(obj);
4111 wd->autosave = !!autosave;
4115 * This gets the entry object's 'autosave' status.
4117 * @param obj The entry object
4118 * @return Autosave the loaded file or not
4123 elm_entry_autosave_get(const Evas_Object *obj)
4125 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4126 Widget_Data *wd = elm_widget_data_get(obj);
4127 if (!wd) return EINA_FALSE;
4128 return wd->autosave;
4132 * Control pasting of text and images for the widget.
4134 * Normally the entry allows both text and images to be pasted. By setting
4135 * textonly to be true, this prevents images from being pasted.
4137 * Note this only changes the behaviour of text.
4139 * @param obj The entry object
4140 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
4145 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4147 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4148 ELM_CHECK_WIDTYPE(obj, widtype);
4149 Widget_Data *wd = elm_widget_data_get(obj);
4151 textonly = !!textonly;
4152 if (wd->textonly == textonly) return;
4153 wd->textonly = !!textonly;
4157 * Getting elm_entry text paste/drop mode.
4159 * In textonly mode, only text may be pasted or dropped into the widget.
4161 * @param obj The entry object
4162 * @return If the widget only accepts text from pastes.
4167 elm_entry_cnp_textonly_get(Evas_Object *obj)
4169 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4170 Widget_Data *wd = elm_widget_data_get(obj);
4171 if (!wd) return EINA_FALSE;
4172 return wd->textonly;
4176 * This sets the attribute to show the input panel automatically.
4178 * @param obj The entry object
4179 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4184 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4186 ELM_CHECK_WIDTYPE(obj, widtype);
4187 Widget_Data *wd = elm_widget_data_get(obj);
4190 wd->input_panel_enable = enabled;
4191 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4195 * Set the input panel layout of the entry
4197 * @param obj The entry object
4198 * @param layout the layout to set
4203 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4205 ELM_CHECK_WIDTYPE(obj, widtype);
4206 Widget_Data *wd = elm_widget_data_get(obj);
4209 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4212 wd->input_panel_layout = layout;
4214 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4218 * Set the magnifier style of the entry
4220 * @param obj The entry object
4221 * @param type the magnifier style to set
4226 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4228 ELM_CHECK_WIDTYPE(obj, widtype);
4229 Widget_Data *wd = elm_widget_data_get(obj);
4232 wd->mgf_type = type;
4233 _magnifier_create(obj);