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 printf("[Elm_entry::Focused] obj : %p\n", obj);
652 evas_object_focus_set(wd->ent, EINA_TRUE);
653 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
654 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
655 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
656 _check_enable_returnkey(obj);
657 wd->mgf_type = _ENTRY_MAGNIFIER_FILLWIDTH;
658 _magnifier_create(obj);
662 printf("[Elm_entry::Unfocused] obj : %p\n", obj);
663 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
664 evas_object_focus_set(wd->ent, EINA_FALSE);
665 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
666 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
668 if ((wd->api) && (wd->api->obj_hidemenu))
670 wd->api->obj_hidemenu(obj);
676 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
678 Widget_Data *wd = elm_widget_data_get(obj);
680 edje_object_signal_emit(wd->ent, emission, source);
684 _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)
686 Widget_Data *wd = elm_widget_data_get(obj);
688 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
692 _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)
694 Widget_Data *wd = elm_widget_data_get(obj);
695 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
700 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
702 Widget_Data *wd = elm_widget_data_get(obj);
703 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
707 _hoversel_position(Evas_Object *obj)
709 Widget_Data *wd = elm_widget_data_get(obj);
710 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
712 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
713 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
715 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
726 evas_object_move(wd->hoversel, x + cx, y + cy);
727 evas_object_resize(wd->hoversel, cw, ch);
731 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
733 Widget_Data *wd = elm_widget_data_get(data);
735 if (wd->hoversel) _hoversel_position(data);
739 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
741 Widget_Data *wd = elm_widget_data_get(data);
743 if ((wd->linewrap) || (wd->char_linewrap))
747 if (wd->hoversel) _hoversel_position(data);
748 // Evas_Coord ww, hh;
749 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
753 _hover_del(void *data)
755 Widget_Data *wd = elm_widget_data_get(data);
760 evas_object_del(wd->hoversel);
763 wd->hovdeljob = NULL;
767 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
769 Widget_Data *wd = elm_widget_data_get(data);
771 if (wd->hoversel) evas_object_hide(wd->hoversel);
775 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
777 elm_widget_scroll_freeze_pop(data);
778 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
779 wd->hovdeljob = ecore_job_add(_hover_del, data);
783 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
785 Widget_Data *wd = elm_widget_data_get(data);
787 wd->selmode = EINA_TRUE;
788 edje_object_part_text_select_none(wd->ent, "elm.text");
789 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
790 edje_object_part_text_select_all(wd->ent, "elm.text");
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);
808 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
810 Widget_Data *wd = elm_widget_data_get(data);
812 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
813 if (wd->sel_notify_handler)
815 #ifdef HAVE_ELEMENTARY_X
816 wd->selection_asked = EINA_TRUE;
817 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data, NULL, NULL);
823 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
825 Widget_Data *wd = elm_widget_data_get(obj);
829 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
830 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
831 if (seltype == ELM_SEL_CLIPBOARD)
832 eina_stringshare_replace(&wd->cut_sel, sel);
836 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
838 Widget_Data *wd = elm_widget_data_get(data);
841 wd->selmode = EINA_FALSE;
842 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
843 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
844 elm_widget_scroll_hold_pop(data);
845 _store_selection(ELM_SEL_CLIPBOARD, data);
846 edje_object_part_text_insert(wd->ent, "elm.text", "");
847 edje_object_part_text_select_none(wd->ent, "elm.text");
851 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
853 Widget_Data *wd = elm_widget_data_get(data);
855 //wd->selmode = EINA_FALSE;
856 //edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
857 //edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
858 elm_widget_scroll_hold_pop(data);
859 _store_selection(ELM_SEL_CLIPBOARD, data);
860 //edje_object_part_text_select_none(wd->ent, "elm.text");
864 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
866 Widget_Data *wd = elm_widget_data_get(data);
868 wd->selmode = EINA_FALSE;
869 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
870 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
871 elm_widget_scroll_hold_pop(data);
872 edje_object_part_text_select_none(wd->ent, "elm.text");
876 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
878 Widget_Data *wd = elm_widget_data_get(data);
882 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
883 cnpwidgetdata = data;
884 elm_cbhm_helper_init(obj);
885 if (elm_entry_cnp_textonly_get(obj))
886 elm_cbhm_send_raw_data("show0");
888 elm_cbhm_send_raw_data("show1");
894 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
896 Widget_Data *wd = elm_widget_data_get(data);
898 cnpwidgetdata = data;
904 _item_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
906 Elm_Entry_Context_Menu_Item *it = data;
907 Evas_Object *obj2 = it->obj;
908 if (it->func) it->func(it->data, obj2, NULL);
912 _long_pressed(void *data)
914 Widget_Data *wd = elm_widget_data_get(data);
917 const Elm_Entry_Context_Menu_Item *it;
919 if ((wd->api) && (wd->api->obj_longpress))
921 wd->api->obj_longpress(data);
923 else if (wd->context_menu)
925 const char *context_menu_orientation;
927 if (wd->hoversel) evas_object_del(wd->hoversel);
928 else elm_widget_scroll_freeze_push(data);
929 wd->hoversel = elm_hoversel_add(data);
930 context_menu_orientation = edje_object_data_get
931 (wd->ent, "context_menu_orientation");
932 if ((context_menu_orientation) &&
933 (!strcmp(context_menu_orientation, "horizontal")))
934 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
935 elm_object_style_set(wd->hoversel, "entry");
936 elm_widget_sub_object_add(data, wd->hoversel);
937 elm_hoversel_label_set(wd->hoversel, "Text");
938 top = elm_widget_top_get(data);
939 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
940 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
944 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
946 if (1) // need way to detect if someone has a selection
949 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
953 if ((!wd->password) && (wd->editable))
954 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
955 _clipboard_menu, data);
962 if (wd->have_selection)
964 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
967 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
970 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);
1003 evas_object_hide(wd->mgf_bg);
1004 evas_object_hide(wd->mgf_clip);
1008 _magnifier_show(void *data)
1010 Widget_Data *wd = elm_widget_data_get(data);
1013 evas_object_show(wd->mgf_bg);
1014 evas_object_show(wd->mgf_clip);
1018 _magnifier_move(void *data)
1020 Widget_Data *wd = elm_widget_data_get(data);
1023 Evas_Coord x, y, w, h, fs;
1024 Evas_Coord cx, cy, cw, ch, ox, oy;
1026 evas_object_geometry_get(data, &x, &y, &w, &h);
1027 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1030 fs = elm_finger_size_get();
1032 if ((cy + y) - wd->mgf_height - fs < 0)
1033 oy = -1 * ((cy + y) - wd->mgf_height - fs);
1035 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1036 evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1037 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1038 evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1042 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);
1046 _magnifier_create(void *data)
1048 Widget_Data *wd = elm_widget_data_get(data);
1049 Evas_Coord x, y, w, h;
1050 const char* key_data = NULL;
1056 evas_object_image_source_unset(wd->mgf_proxy);
1057 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1058 evas_object_hide(wd->mgf_proxy);
1059 evas_object_clip_unset(wd->mgf_proxy);
1060 evas_object_del(wd->mgf_proxy);
1062 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1063 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1065 evas_object_geometry_get(data, &x, &y, &w, &h);
1066 wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1068 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1069 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1070 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1071 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1075 wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1076 evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1077 edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1079 key_data = edje_object_data_get(wd->mgf_bg, "height");
1080 if (key_data) wd->mgf_height = atoi(key_data);
1081 key_data = edje_object_data_get(wd->mgf_bg, "scale");
1082 if (key_data) wd->mgf_scale = atof(key_data);
1084 if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1085 evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1087 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1088 evas_object_image_source_set(wd->mgf_proxy, data);
1089 evas_object_resize(wd->mgf_proxy, w * wd->mgf_scale, h * wd->mgf_scale);
1090 evas_object_image_fill_set(wd->mgf_proxy, 0, 0, w * wd->mgf_scale, h * wd->mgf_scale);
1091 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1092 evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1093 evas_object_show(wd->mgf_proxy);
1094 evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1096 evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1097 evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1101 _long_press(void *data)
1103 Widget_Data *wd = elm_widget_data_get(data);
1104 if (!wd) return ECORE_CALLBACK_CANCEL;
1106 wd->long_pressed = EINA_TRUE;
1108 if (wd->longpress_timer)
1110 ecore_timer_del(wd->longpress_timer);
1111 wd->longpress_timer = NULL;
1114 _cancel(data, NULL, NULL);
1116 _magnifier_create(data);
1117 _magnifier_move(data);
1118 _magnifier_show(data);
1119 elm_object_scroll_freeze_push(data);
1121 wd->longpress_timer = NULL;
1122 return ECORE_CALLBACK_CANCEL;
1126 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1128 Widget_Data *wd = elm_widget_data_get(data);
1129 Evas_Event_Mouse_Down *ev = event_info;
1131 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1132 if (ev->button != 1) return;
1133 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1134 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1135 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1136 wd->downx = ev->canvas.x;
1137 wd->downy = ev->canvas.y;
1139 wd->long_pressed = EINA_FALSE;
1143 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1145 Widget_Data *wd = elm_widget_data_get(data);
1146 Evas_Event_Mouse_Up *ev = event_info;
1148 if (ev->button != 1) return;
1150 if (!wd->double_clicked)
1152 if ((wd->api) && (wd->api->obj_mouseup))
1154 wd->api->obj_mouseup(data);
1157 if (wd->longpress_timer)
1159 ecore_timer_del(wd->longpress_timer);
1160 wd->longpress_timer = NULL;
1163 _magnifier_hide(data);
1164 elm_object_scroll_freeze_pop(data);
1166 if (wd->long_pressed)
1168 _long_pressed(data);
1173 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1175 Widget_Data *wd = elm_widget_data_get(data);
1176 Evas_Event_Mouse_Move *ev = event_info;
1180 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1182 if (wd->longpress_timer)
1184 ecore_timer_del(wd->longpress_timer);
1185 wd->longpress_timer = NULL;
1188 else if (wd->longpress_timer)
1192 dx = wd->downx - ev->cur.canvas.x;
1194 dy = wd->downy - ev->cur.canvas.y;
1197 ((_elm_config->finger_size / 2) *
1198 (_elm_config->finger_size / 2)))
1200 ecore_timer_del(wd->longpress_timer);
1201 wd->longpress_timer = NULL;
1205 else if (wd->longpress_timer)
1209 dx = wd->downx - ev->cur.canvas.x;
1211 dy = wd->downy - ev->cur.canvas.y;
1214 ((_elm_config->finger_size / 2) *
1215 (_elm_config->finger_size / 2)))
1217 ecore_timer_del(wd->longpress_timer);
1218 wd->longpress_timer = NULL;
1222 if (ev->buttons != 1) return;
1224 if (wd->long_pressed)
1226 _magnifier_show(data);
1227 _magnifier_move(data);
1232 _getbase(Evas_Object *obj)
1234 Widget_Data *wd = elm_widget_data_get(obj);
1235 if (!wd) return "base";
1240 if (wd->show_last_character) return "custom-password";
1241 else return "base-password";
1245 if (wd->single_line) return "base-single";
1248 if (wd->linewrap) return "base";
1249 else if (wd->char_linewrap) return "base-charwrap";
1250 else return "base-nowrap";
1258 if (wd->show_last_character) return "custom-password";
1259 else return "base-password";
1263 if (wd->single_line) return "base-single-noedit";
1266 if (wd->linewrap) return "base-noedit";
1267 else if (wd->char_linewrap) return "base-noedit-charwrap";
1268 else return "base-nowrap-noedit";
1276 _entry_length_get(Evas_Object *obj)
1279 const char *str = elm_entry_entry_get(obj);
1282 char *plain_str = _elm_util_mkup_to_text(str);
1283 if (!plain_str) return 0;
1285 len = strlen(plain_str);
1292 _matchlist_show(void *data)
1294 Widget_Data *wd = elm_widget_data_get(data);
1295 const char *text = NULL;
1297 char *str_list = NULL, *str_result = NULL;
1298 char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1301 Eina_Bool textfound = EINA_FALSE;
1304 if (elm_widget_disabled_get(data)) return;
1306 wd->matchlist_job = NULL;
1308 if (wd->matchlist_list_clicked)
1310 evas_object_hide(wd->hover);
1311 wd->matchlist_list_clicked = EINA_FALSE;
1314 text = elm_entry_entry_get(data);
1317 textlen = strlen(text);
1319 if (textlen < wd->matchlist_threshold)
1321 evas_object_hide(wd->hover);
1325 evas_object_hide(wd->hover);
1329 elm_list_clear(wd->list);
1330 EINA_LIST_FOREACH(wd->match_list, l, str_list)
1332 if (wd->matchlist_case_sensitive)
1333 str_result = strstr(str_list, text);
1335 str_result = strcasestr(str_list, text);
1339 str_mkup = malloc(strlen(str_list) + 16);
1341 textlen = strlen(str_list) - strlen(str_result);
1342 str_front = malloc(textlen + 1);
1343 memset(str_front, 0, textlen + 1);
1344 strncpy(str_front, str_list, textlen);
1346 textlen = strlen(text);
1347 str_mid = malloc(textlen + 1);
1348 memset(str_mid, 0, textlen + 1);
1349 strncpy(str_mid, str_list + strlen(str_front), textlen);
1351 sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1353 elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1355 if (str_mkup) free(str_mkup);
1356 if (str_front) free(str_front);
1357 if (str_mid) free(str_mid);
1359 textfound=EINA_TRUE;
1368 elm_list_go(wd->list);
1369 evas_object_show(wd->hover);
1370 evas_object_raise(wd->hover);
1374 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1376 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1377 Widget_Data *wd = elm_widget_data_get(data);
1378 if ((it == NULL) || (wd == NULL))
1381 const char *text = elm_list_item_label_get(it);
1382 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1387 elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1388 elm_entry_cursor_end_set(data);
1389 wd->matchlist_list_clicked = EINA_TRUE;
1391 evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1394 elm_widget_focus_set(data, EINA_TRUE);
1398 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
1400 Widget_Data *wd = elm_widget_data_get(obj);
1405 Evas_Coord max_w = 9999, max_h = 9999;
1406 const char* key_data = NULL;
1408 wd->matchlist_threshold = 1;
1409 wd->hover = elm_hover_add(elm_widget_parent_get(obj));
1410 elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
1411 elm_hover_target_set(wd->hover, obj);
1412 elm_object_style_set(wd->hover, "matchlist");
1414 wd->layout = elm_layout_add(wd->hover);
1415 elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
1416 wd->list = elm_list_add(wd->layout);
1417 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
1418 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1419 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1420 elm_object_style_set(wd->list, "matchlist");
1422 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
1423 if (key_data) max_w = atoi(key_data);
1424 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
1425 if (key_data) max_h = atoi(key_data);
1427 elm_list_go(wd->list);
1428 evas_object_size_hint_max_set(wd->list, max_w, max_h);
1429 evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
1430 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
1431 elm_hover_content_set(wd->hover, "bottom", wd->layout);
1433 wd->match_list = match_list;
1438 evas_object_del(wd->hover);
1440 wd->match_list = NULL;
1443 wd->matchlist_case_sensitive = case_sensitive;
1448 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1450 Widget_Data *wd = elm_widget_data_get(data);
1452 wd->changed = EINA_TRUE;
1454 if (wd->text) eina_stringshare_del(wd->text);
1456 _check_enable_returnkey(data);
1457 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1458 if (wd->delay_write)
1460 ecore_timer_del(wd->delay_write);
1461 wd->delay_write = NULL;
1464 if ((wd->single_line) && (wd->match_list))
1466 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1467 wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1469 if ((!wd->autosave) || (!wd->file)) return;
1470 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1474 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1476 Widget_Data *wd = elm_widget_data_get(data);
1477 elm_object_scroll_freeze_push(data);
1479 if ((wd->api) && (wd->api->obj_hidemenu))
1481 wd->api->obj_hidemenu(data);
1484 _magnifier_create(data);
1485 _magnifier_move(data);
1486 _magnifier_show(data);
1490 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1492 Widget_Data *wd = elm_widget_data_get(data);
1493 elm_object_scroll_freeze_pop(data);
1495 if (wd->have_selection)
1497 _magnifier_hide(data);
1498 _long_pressed(data);
1503 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1505 _magnifier_move(data);
1506 _magnifier_show(data);
1510 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1512 _magnifier_hide(data);
1513 _long_pressed(data);
1517 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1519 Widget_Data *wd = elm_widget_data_get(data);
1523 EINA_LIST_FOREACH(entries, l, entry)
1525 if (entry != data) elm_entry_select_none(entry);
1527 wd->have_selection = EINA_TRUE;
1528 wd->selmode = EINA_TRUE;
1529 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1530 #ifdef HAVE_ELEMENTARY_X
1531 if (wd->sel_notify_handler)
1533 const char *txt = elm_entry_selection_get(data);
1536 top = elm_widget_top_get(data);
1537 if ((top) && (elm_win_xwindow_get(top)))
1538 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1544 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1546 Evas_Coord cx, cy, cw, ch;
1547 Widget_Data *wd = elm_widget_data_get(data);
1550 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1551 if (!wd->deferred_recalc_job)
1552 elm_widget_show_region_set(data, cx, cy, cw, ch);
1555 wd->deferred_cur = EINA_TRUE;
1559 wd->ch = ch + elm_finger_size_get();
1564 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1566 Evas_Coord cx, cy, cw, ch;
1567 Widget_Data *wd = elm_widget_data_get(data);
1569 wd->have_selection = EINA_TRUE;
1570 wd->selmode = EINA_TRUE;
1571 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1572 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1573 elm_entry_selection_get(data));
1575 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1576 if (!wd->deferred_recalc_job)
1577 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get());
1580 wd->deferred_cur = EINA_TRUE;
1584 wd->ch = ch + elm_finger_size_get();
1589 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1591 Widget_Data *wd = elm_widget_data_get(data);
1593 if (!wd->have_selection) return;
1594 wd->have_selection = EINA_FALSE;
1595 wd->selmode = EINA_FALSE;
1596 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1597 if (wd->sel_notify_handler)
1601 #ifdef HAVE_ELEMENTARY_X
1604 top = elm_widget_top_get(data);
1605 if ((top) && (elm_win_xwindow_get(top)))
1606 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1609 eina_stringshare_del(wd->cut_sel);
1614 #ifdef HAVE_ELEMENTARY_X
1617 top = elm_widget_top_get(data);
1618 if ((top) && (elm_win_xwindow_get(top)))
1619 elm_selection_clear(ELM_SEL_PRIMARY, data);
1624 if ((wd->api) && (wd->api->obj_hidemenu))
1626 wd->api->obj_hidemenu(data);
1631 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1633 Widget_Data *wd = elm_widget_data_get(data);
1635 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1636 if (wd->sel_notify_handler)
1638 #ifdef HAVE_ELEMENTARY_X
1641 top = elm_widget_top_get(data);
1642 if ((top) && (elm_win_xwindow_get(top)))
1644 wd->selection_asked = EINA_TRUE;
1645 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1653 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1655 Widget_Data *wd = elm_widget_data_get(data);
1657 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1658 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1659 elm_entry_selection_get(data));
1663 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1665 Widget_Data *wd = elm_widget_data_get(data);
1667 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1668 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1669 elm_entry_selection_get(data));
1670 edje_object_part_text_insert(wd->ent, "elm.text", "");
1671 wd->changed = EINA_TRUE;
1676 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1678 Widget_Data *wd = elm_widget_data_get(data);
1679 Evas_Coord cx, cy, cw, ch;
1681 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1682 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1683 &cx, &cy, &cw, &ch);
1684 if (!wd->deferred_recalc_job)
1685 elm_widget_show_region_set(data, cx, cy, cw, ch);
1688 wd->deferred_cur = EINA_TRUE;
1697 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1699 Widget_Data *wd = elm_widget_data_get(data);
1704 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1706 Widget_Data *wd = elm_widget_data_get(data);
1711 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1713 Widget_Data *wd = elm_widget_data_get(data);
1714 Elm_Entry_Anchor_Info ei;
1715 char *buf2, *p, *p2, *n;
1717 p = strrchr(emission, ',');
1720 const Eina_List *geoms;
1724 while (p2 >= emission)
1726 if (*p2 == ',') break;
1730 buf2 = alloca(5 + p - p2);
1731 strncpy(buf2, p2, p - p2);
1734 ei.button = atoi(buf2);
1735 ei.x = ei.y = ei.w = ei.h = 0;
1737 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1740 Evas_Textblock_Rectangle *r;
1742 Evas_Coord px, py, x, y;
1744 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1745 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1746 EINA_LIST_FOREACH(geoms, l, r)
1748 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1749 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1760 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1765 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1767 Widget_Data *wd = elm_widget_data_get(data);
1772 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1774 Widget_Data *wd = elm_widget_data_get(data);
1779 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1781 Widget_Data *wd = elm_widget_data_get(data);
1786 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1788 Widget_Data *wd = elm_widget_data_get(data);
1790 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1794 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1796 Widget_Data *wd = elm_widget_data_get(data);
1798 wd->double_clicked = EINA_FALSE;
1799 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1801 if ((wd->api) && (wd->api->obj_hidemenu))
1803 wd->api->obj_hidemenu(data);
1808 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1810 Widget_Data *wd = elm_widget_data_get(data);
1812 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1816 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1818 Widget_Data *wd = elm_widget_data_get(data);
1820 wd->double_clicked = EINA_TRUE;
1821 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1824 #ifdef HAVE_ELEMENTARY_X
1826 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1828 Widget_Data *wd = elm_widget_data_get(data);
1829 Ecore_X_Event_Selection_Notify *ev = event;
1830 if (!wd) return ECORE_CALLBACK_PASS_ON;
1831 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1832 return ECORE_CALLBACK_PASS_ON;
1834 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1835 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1837 Ecore_X_Selection_Data_Text *text_data;
1839 text_data = ev->data;
1840 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1842 if (text_data->text)
1844 char *txt = _elm_util_text_to_mkup(text_data->text);
1848 elm_entry_entry_insert(data, txt);
1853 wd->selection_asked = EINA_FALSE;
1855 else if (ev->selection == ECORE_X_SELECTION_XDND)
1857 Ecore_X_Selection_Data_Text *text_data;
1859 text_data = ev->data;
1860 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1862 if (text_data->text)
1864 char *txt = _elm_util_text_to_mkup(text_data->text);
1868 /* Massive FIXME: this should be at the drag point */
1869 elm_entry_entry_insert(data, txt);
1874 wd->drag_selection_asked = EINA_FALSE;
1876 ecore_x_dnd_send_finished();
1879 return ECORE_CALLBACK_PASS_ON;
1883 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1886 Widget_Data *wd = elm_widget_data_get(data);
1887 Ecore_X_Event_Selection_Clear *ev = event;
1888 if (!wd) return ECORE_CALLBACK_PASS_ON;
1889 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1890 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1891 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1893 elm_entry_select_none(data);
1898 Evas_Object *top = elm_widget_top_get(data);
1899 Ecore_X_Event_Selection_Clear *ev = event;
1902 return ECORE_CALLBACK_PASS_ON;
1904 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1906 return ECORE_CALLBACK_PASS_ON;
1909 if (cnpwidgetdata == data)
1911 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
1915 return ECORE_CALLBACK_PASS_ON;
1920 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1925 wd = elm_widget_data_get(obj);
1927 if (!wd) return EINA_FALSE;
1928 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1930 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1931 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1932 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1933 EDJE_CURSOR_MAIN,drop->x,drop->y);
1934 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1935 elm_entry_entry_insert(obj, drop->data);
1936 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1937 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1943 static Evas_Object *
1944 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1946 Widget_Data *wd = elm_widget_data_get(data);
1949 Elm_Entry_Item_Provider *ip;
1951 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1953 o = ip->func(ip->data, data, item);
1956 if (!strncmp(item, "file://", 7))
1958 const char *fname = item + 7;
1960 o = evas_object_image_filled_add(evas_object_evas_get(data));
1961 evas_object_image_file_set(o, fname, NULL);
1962 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1964 evas_object_show(o);
1969 o = edje_object_add(evas_object_evas_get(data));
1970 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1974 o = edje_object_add(evas_object_evas_get(data));
1975 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1976 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1981 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1983 char *curlocater, *starttag, *endtag;
1984 int firstindex = 0, foundflag = -1;
1986 curlocater = strstr(oldstring, key);
1989 starttag = curlocater;
1990 endtag = curlocater + strlen(key);
1991 if (endtag == NULL || *endtag != '=')
1997 firstindex = abs(oldstring - curlocater);
1998 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1999 *value = (char*)(oldstring + firstindex);
2001 while (oldstring != starttag)
2003 if (*starttag == '>')
2008 if (*starttag == '<')
2012 if (starttag == NULL) break;
2015 while (NULL != endtag)
2026 if (endtag == NULL) break;
2029 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
2039 if (foundflag == 1) return 0;
2045 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2047 const char *srcstring = NULL;
2048 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2049 char *curlocater, *replocater;
2050 char *starttag, *endtag;
2051 int tagtxtlen = 0, insertflag = 0;
2053 srcstring = eina_strbuf_string_get(srcbuf);
2054 curlocater = strstr(srcstring, key);
2056 if (!curlocater || !srcstring)
2064 starttag = strchr(srcstring, '<');
2065 endtag = strchr(srcstring, '>');
2066 tagtxtlen = endtag - starttag;
2067 if (tagtxtlen <= 0) tagtxtlen = 0;
2068 if (starttag < curlocater && curlocater < endtag) break;
2069 if (endtag != NULL && endtag+1 != NULL)
2070 srcstring = endtag+1;
2073 } while (strlen(srcstring) > 1);
2075 if (starttag && endtag && tagtxtlen > strlen(key))
2077 repbuf = eina_strbuf_new();
2078 diffbuf = eina_strbuf_new();
2079 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2080 srcstring = eina_strbuf_string_get(repbuf);
2081 curlocater = strstr(srcstring, key);
2083 if (curlocater != NULL)
2085 replocater = curlocater + strlen(key) + 1;
2087 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2090 if (replocater-curlocater > strlen(key)+1)
2092 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2101 eina_strbuf_reset(repbuf);
2109 if (repbuf == NULL) repbuf = eina_strbuf_new();
2110 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2114 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2115 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2121 eina_strbuf_prepend(diffbuf, "<");
2122 eina_strbuf_append(diffbuf, ">");
2123 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2127 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2128 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2132 if (repbuf) eina_strbuf_free(repbuf);
2133 if (diffbuf) eina_strbuf_free(diffbuf);
2139 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2141 Eina_Strbuf *sharebuf = NULL;
2143 sharebuf = eina_strbuf_new();
2144 eina_strbuf_append(sharebuf, *srcstring);
2145 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2146 eina_stringshare_del(*srcstring);
2147 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2148 eina_strbuf_free(sharebuf);
2154 _is_width_over(Evas_Object *obj)
2156 Evas_Coord x, y, w, h;
2157 Evas_Coord vx, vy, vw, vh;
2158 Widget_Data *wd = elm_widget_data_get(obj);
2162 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
2164 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
2166 if (x >= 0 && y >= 0)
2169 if (4 < wd->wrap_w && w > wd->wrap_w)
2176 _reverse_ellipsis_entry(Evas_Object *obj)
2178 Widget_Data *wd = elm_widget_data_get(obj);
2179 int cur_fontsize = 0;
2180 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
2181 char *kvalue = NULL;
2182 const char *minfont, *deffont, *maxfont;
2183 const char *ellipsis_string = "...";
2184 int minfontsize, maxfontsize, minshowcount;
2186 minshowcount = strlen(ellipsis_string) + 1;
2187 minfont = edje_object_data_get(wd->ent, "min_font_size");
2188 if (minfont) minfontsize = atoi(minfont);
2189 else minfontsize = 1;
2190 maxfont = edje_object_data_get(wd->ent, "max_font_size");
2191 if (maxfont) maxfontsize = atoi(maxfont);
2192 else maxfontsize = 1;
2193 deffont = edje_object_data_get(wd->ent, "default_font_size");
2194 if (deffont) cur_fontsize = atoi(deffont);
2195 else cur_fontsize = 1;
2196 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
2197 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
2199 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
2201 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
2204 txtbuf = eina_strbuf_new();
2205 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
2207 if (cur_fontsize >= atoi(deffont))
2209 if (txtbuf) eina_strbuf_free(txtbuf);
2213 if (_is_width_over(obj) != 1)
2215 int rev_fontsize = cur_fontsize;
2219 if (rev_fontsize > atoi(deffont))
2222 if (fontbuf != NULL)
2224 eina_strbuf_free(fontbuf);
2227 fontbuf = eina_strbuf_new();
2228 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
2229 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2230 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2232 eina_strbuf_free(fontbuf);
2234 } while (_is_width_over(obj) != 1);
2236 while (_is_width_over(obj))
2239 if (rev_fontsize < atoi(deffont))
2242 if (fontbuf != NULL)
2244 eina_strbuf_free(fontbuf);
2247 fontbuf = eina_strbuf_new();
2248 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
2249 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2250 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2251 eina_strbuf_free(fontbuf);
2256 if (txtbuf) eina_strbuf_free(txtbuf);
2262 _ellipsis_entry_to_width(Evas_Object *obj)
2264 Widget_Data *wd = elm_widget_data_get(obj);
2265 int cur_fontsize = 0, len, jumpcount;
2266 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
2267 char *kvalue = NULL;
2268 const char *minfont, *deffont, *maxfont;
2269 const char *ellipsis_string = "...";
2270 int minfontsize, maxfontsize, minshowcount;
2271 int i, tagend, cur_len;
2274 minshowcount = strlen(ellipsis_string) + 1;
2275 minfont = edje_object_data_get(wd->ent, "min_font_size");
2276 if (minfont) minfontsize = atoi(minfont);
2277 else minfontsize = 1;
2278 maxfont = edje_object_data_get(wd->ent, "max_font_size");
2279 if (maxfont) maxfontsize = atoi(maxfont);
2280 else maxfontsize = 1;
2281 deffont = edje_object_data_get(wd->ent, "default_font_size");
2282 if (deffont) cur_fontsize = atoi(deffont);
2283 else cur_fontsize = 1;
2284 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
2285 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
2287 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
2289 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
2292 txtbuf = eina_strbuf_new();
2293 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
2295 while (_is_width_over(obj))
2297 if (wd->ellipsis_threshold == 0)
2298 wd->ellipsis_threshold = _entry_length_get(obj);
2299 if (cur_fontsize > minfontsize)
2302 if (fontbuf != NULL)
2304 eina_strbuf_free(fontbuf);
2307 fontbuf = eina_strbuf_new();
2308 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
2309 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2310 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2311 eina_strbuf_free(fontbuf);
2313 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2317 len = _entry_length_get(obj);
2318 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2319 cur_len = strlen(cur_str);
2321 for (i = 0; i < len; i++)
2323 if(cur_str[i] == '>' && cur_str[i+1] != '\0' &&
2324 cur_str[i+1] != '<')
2331 while (jumpcount < len-strlen(ellipsis_string))
2333 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2337 eina_strbuf_free(txtbuf);
2340 txtbuf = eina_strbuf_new();
2341 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
2342 eina_strbuf_append(txtbuf, ellipsis_string);
2343 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
2344 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2345 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2347 if (_is_width_over(obj))
2355 if (txtbuf) eina_strbuf_free(txtbuf);
2360 static Eina_Bool *_textinput_control_function(void *data,void *input_data)
2362 /* calculate character count */
2363 Evas_Object *entry = (Evas_Object *)data;
2364 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
2367 size_t insert_text_len=0;
2368 char *text = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2370 size_t remain_bytes;
2373 byte_len = strlen(text); /* no of bytes */
2374 remain_bytes = wd->max_no_of_bytes - byte_len;
2375 sprintf(buf,"%d",remain_bytes);
2376 //edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
2379 insert_text = (char *)input_data;
2380 insert_text_len = strlen(insert_text);
2381 if (remain_bytes < insert_text_len)
2383 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2386 if (byte_len >= wd->max_no_of_bytes)
2388 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2398 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2400 Widget_Data *wd = elm_widget_data_get(data);
2402 Elm_Entry_Text_Filter *tf;
2404 if (type == EDJE_TEXT_FILTER_FORMAT)
2407 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2409 tf->func(tf->data, data, text);
2416 * This adds an entry to @p parent object.
2418 * @param parent The parent object
2419 * @return The new object or NULL if it cannot be created
2424 elm_entry_add(Evas_Object *parent)
2426 Evas_Object *obj, *top;
2430 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2432 wd = ELM_NEW(Widget_Data);
2433 e = evas_object_evas_get(parent);
2434 if (!e) return NULL;
2435 wd->bgcolor = EINA_FALSE;
2436 wd->bg = evas_object_rectangle_add(e);
2437 evas_object_color_set(wd->bg, 0, 0, 0, 0);
2438 obj = elm_widget_add(e);
2439 ELM_SET_WIDTYPE(widtype, "entry");
2440 elm_widget_type_set(obj, "entry");
2441 elm_widget_sub_object_add(parent, obj);
2442 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2443 elm_widget_data_set(obj, wd);
2444 elm_widget_del_hook_set(obj, _del_hook);
2445 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2446 elm_widget_theme_hook_set(obj, _theme_hook);
2447 elm_widget_disable_hook_set(obj, _disable_hook);
2448 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2449 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2450 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2451 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2452 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2453 elm_widget_can_focus_set(obj, EINA_TRUE);
2454 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2456 wd->linewrap = EINA_TRUE;
2457 wd->ellipsis = EINA_FALSE;
2458 wd->char_linewrap= EINA_FALSE;
2459 wd->editable = EINA_TRUE;
2460 wd->disabled = EINA_FALSE;
2461 wd->context_menu = EINA_TRUE;
2462 wd->autosave = EINA_TRUE;
2463 wd->textonly = EINA_FALSE;
2464 wd->autoperiod = EINA_TRUE;
2466 wd->ellipsis_threshold = 0;
2468 wd->ent = edje_object_add(e);
2469 edje_object_item_provider_set(wd->ent, _get_item, obj);
2470 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2471 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2472 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2473 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2475 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2477 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2480 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2481 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2482 _signal_entry_changed, obj);
2483 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2484 _signal_handler_move_start, obj);
2485 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2486 _signal_handler_move_end, obj);
2487 edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2488 _signal_handler_moving, obj);
2489 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2490 _signal_selection_start, obj);
2491 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2492 _signal_selection_end, obj);
2493 edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2494 _signal_magnifier_changed, obj);
2495 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2496 _signal_selection_changed, obj);
2497 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2498 _signal_selection_cleared, obj);
2499 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2500 _signal_entry_paste_request, obj);
2501 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2502 _signal_entry_copy_notify, obj);
2503 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2504 _signal_entry_cut_notify, obj);
2505 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2506 _signal_cursor_changed, obj);
2507 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2508 _signal_anchor_down, obj);
2509 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2510 _signal_anchor_up, obj);
2511 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2512 _signal_anchor_clicked, obj);
2513 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2514 _signal_anchor_move, obj);
2515 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2516 _signal_anchor_in, obj);
2517 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2518 _signal_anchor_out, obj);
2519 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2520 _signal_key_enter, obj);
2521 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2522 _signal_mouse_down, obj);
2523 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2524 _signal_mouse_clicked, obj);
2525 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2526 _signal_mouse_double, obj);
2527 edje_object_part_text_set(wd->ent, "elm.text", "");
2528 elm_widget_resize_object_set(obj, wd->ent);
2531 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2533 #ifdef HAVE_ELEMENTARY_X
2534 top = elm_widget_top_get(obj);
2535 if ((top) && (elm_win_xwindow_get(top)))
2537 wd->sel_notify_handler =
2538 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2539 _event_selection_notify, obj);
2540 wd->sel_clear_handler =
2541 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2542 _event_selection_clear, obj);
2545 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2548 entries = eina_list_prepend(entries, obj);
2550 // module - find module for entry
2551 wd->api = _module(obj);
2552 // if found - hook in
2553 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2555 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2556 // TODO: and save some bytes, making descriptions per-class and not instance!
2557 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2561 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2563 ELM_CHECK_WIDTYPE(obj, widtype);
2564 Widget_Data *wd = elm_widget_data_get(obj);
2566 ext_mod->cancel = _cancel;
2567 ext_mod->copy = _copy;
2568 ext_mod->cut = _cut;
2569 ext_mod->paste = _paste;
2570 ext_mod->select = _select;
2571 ext_mod->selectall = _selectall;
2572 ext_mod->ent = wd->ent;
2573 ext_mod->items = wd->items;
2574 ext_mod->longpress_timer = wd->longpress_timer;
2575 ext_mod->editable = wd->editable;
2576 ext_mod->have_selection = wd->have_selection;
2577 ext_mod->password = wd->password;
2578 ext_mod->selmode = wd->selmode;
2579 ext_mod->cnpinit = _cnpinit;
2580 ext_mod->context_menu = wd->context_menu;
2581 ext_mod->textonly = wd->textonly;
2585 * This sets the entry object not to line wrap. All input will
2586 * be on a single line, and the entry box will extend with user input.
2588 * @param obj The entry object
2589 * @param single_line If true, the text in the entry
2590 * will be on a single line.
2595 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2597 ELM_CHECK_WIDTYPE(obj, widtype);
2598 Widget_Data *wd = elm_widget_data_get(obj);
2600 Ecore_IMF_Context *ic;
2602 if (wd->single_line == single_line) return;
2603 wd->single_line = single_line;
2604 wd->linewrap = EINA_FALSE;
2605 wd->char_linewrap = EINA_FALSE;
2606 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2607 t = eina_stringshare_add(elm_entry_entry_get(obj));
2608 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2609 elm_entry_entry_set(obj, t);
2610 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2611 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2612 ic = elm_entry_imf_context_get(obj);
2615 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2618 eina_stringshare_del(t);
2623 * This returns true if the entry has been set to single line mode.
2624 * See also elm_entry_single_line_set().
2626 * @param obj The entry object
2627 * @return single_line If true, the text in the entry is set to display
2633 elm_entry_single_line_get(const Evas_Object *obj)
2635 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2636 Widget_Data *wd = elm_widget_data_get(obj);
2637 if (!wd) return EINA_FALSE;
2638 return wd->single_line;
2642 * This sets the entry object to password mode. All text entered
2643 * and/or displayed within the widget will be replaced with asterisks (*).
2645 * @param obj The entry object
2646 * @param password If true, password mode is enabled.
2651 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2653 ELM_CHECK_WIDTYPE(obj, widtype);
2654 Widget_Data *wd = elm_widget_data_get(obj);
2655 Ecore_IMF_Context *ic;
2658 if (wd->password == password) return;
2659 wd->password = password;
2660 wd->single_line = EINA_TRUE;
2661 wd->linewrap = EINA_FALSE;
2662 wd->char_linewrap = EINA_FALSE;
2663 if (_elm_config->password_show_last_character)
2664 wd->show_last_character = EINA_TRUE;
2665 t = eina_stringshare_add(elm_entry_entry_get(obj));
2666 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2667 elm_entry_entry_set(obj, t);
2672 elm_entry_autoperiod_set(obj, EINA_FALSE);
2674 if (wd->autocapital)
2675 elm_entry_autocapitalization_set(obj, EINA_FALSE);
2678 ic = elm_entry_imf_context_get(obj);
2680 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2682 eina_stringshare_del(t);
2688 * This returns whether password mode is enabled.
2689 * See also elm_entry_password_set().
2691 * @param obj The entry object
2692 * @return If true, the entry is set to display all characters
2698 elm_entry_password_get(const Evas_Object *obj)
2700 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2701 Widget_Data *wd = elm_widget_data_get(obj);
2702 if (!wd) return EINA_FALSE;
2703 return wd->password;
2707 * This sets the text displayed within the entry to @p entry.
2709 * @param obj The entry object
2710 * @param entry The text to be displayed
2715 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2717 ELM_CHECK_WIDTYPE(obj, widtype);
2718 Widget_Data *wd = elm_widget_data_get(obj);
2720 if (!entry) entry = "";
2721 if(wd->max_no_of_bytes)
2723 int len = strlen(entry);
2724 if(len > wd->max_no_of_bytes)
2726 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2730 edje_object_part_text_set(wd->ent, "elm.text", entry);
2731 if (wd->text) eina_stringshare_del(wd->text);
2733 wd->changed = EINA_TRUE;
2738 * This returns the text currently shown in object @p entry.
2739 * See also elm_entry_entry_set().
2741 * @param obj The entry object
2742 * @return The currently displayed text or NULL on failure
2747 elm_entry_entry_get(const Evas_Object *obj)
2749 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2750 Widget_Data *wd = elm_widget_data_get(obj);
2752 if (!wd) return NULL;
2754 if ((wd->text)&&(wd->password))
2755 return elm_entry_markup_to_utf8(wd->text);
2757 if (wd->text) return wd->text;
2758 text = edje_object_part_text_get(wd->ent, "elm.text");
2761 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2764 eina_stringshare_replace(&wd->text, text);
2765 if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2771 * This returns EINA_TRUE if the entry is empty/there was an error
2772 * and EINA_FALSE if it is not empty.
2774 * @param obj The entry object
2775 * @return If the entry is empty or not.
2780 elm_entry_is_empty(const Evas_Object *obj)
2782 /* FIXME: until there's support for that in textblock, we just check
2783 * to see if the there is text or not. */
2784 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2785 Widget_Data *wd = elm_widget_data_get(obj);
2786 const Evas_Object *tb;
2787 Evas_Textblock_Cursor *cur;
2789 if (!wd) return EINA_TRUE;
2792 /* It's a hack until we get the support suggested above.
2793 * We just create a cursor, point it to the begining, and then
2794 * try to advance it, if it can advance, the tb is not empty,
2795 * otherwise it is. */
2796 tb = edje_object_part_object_get(wd->ent, "elm.text");
2797 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2798 actually, ok for the time being, thsese hackish stuff will be removed
2799 once evas 1.0 is out*/
2800 evas_textblock_cursor_pos_set(cur, 0);
2801 ret = evas_textblock_cursor_char_next(cur);
2802 evas_textblock_cursor_free(cur);
2807 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
2808 if (!str) return EINA_TRUE;
2810 ret = (strlen(str) == 0);
2816 * This returns all selected text within the entry.
2818 * @param obj The entry object
2819 * @return The selected text within the entry or NULL on failure
2824 elm_entry_selection_get(const Evas_Object *obj)
2826 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2827 Widget_Data *wd = elm_widget_data_get(obj);
2828 if (!wd) return NULL;
2829 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2833 * This inserts text in @p entry where the current cursor position.
2835 * This inserts text at the cursor position is as if it was typed
2836 * by the user (note this also allows markup which a user
2837 * can't just "type" as it would be converted to escaped text, so this
2838 * call can be used to insert things like emoticon items or bold push/pop
2839 * tags, other font and color change tags etc.)
2841 * @param obj The entry object
2842 * @param entry The text to insert
2847 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2849 ELM_CHECK_WIDTYPE(obj, widtype);
2850 Widget_Data *wd = elm_widget_data_get(obj);
2852 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2854 if (cnpwidgetdata == obj)
2855 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2857 wd->changed = EINA_TRUE;
2862 * This enables word line wrapping in the entry object. It is the opposite
2863 * of elm_entry_single_line_set(). Additionally, setting this disables
2864 * character line wrapping.
2865 * See also elm_entry_line_char_wrap_set().
2867 * @param obj The entry object
2868 * @param wrap If true, the entry will be wrapped once it reaches the end
2869 * of the object. Wrapping will occur at the end of the word before the end of the
2875 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2877 ELM_CHECK_WIDTYPE(obj, widtype);
2878 Widget_Data *wd = elm_widget_data_get(obj);
2881 if (wd->linewrap == wrap) return;
2882 wd->linewrap = wrap;
2884 wd->char_linewrap = EINA_FALSE;
2885 t = eina_stringshare_add(elm_entry_entry_get(obj));
2886 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2887 elm_entry_entry_set(obj, t);
2888 eina_stringshare_del(t);
2893 * Set wrap width of the entry
2895 * @param obj The entry object
2896 * @param w The wrap width in pixels at a minimum where words need to wrap
2900 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2902 Widget_Data *wd = elm_widget_data_get(obj);
2903 if (wd->wrap_w == w) return;
2909 * get wrap width of the entry
2911 * @param obj The entry object
2912 * @return The wrap width in pixels at a minimum where words need to wrap
2916 elm_entry_wrap_width_get(const Evas_Object *obj)
2918 Widget_Data *wd = elm_widget_data_get(obj);
2923 * This enables character line wrapping in the entry object. It is the opposite
2924 * of elm_entry_single_line_set(). Additionally, setting this disables
2925 * word line wrapping.
2926 * See also elm_entry_line_wrap_set().
2928 * @param obj The entry object
2929 * @param wrap If true, the entry will be wrapped once it reaches the end
2930 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2935 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2937 ELM_CHECK_WIDTYPE(obj, widtype);
2938 Widget_Data *wd = elm_widget_data_get(obj);
2941 if (wd->char_linewrap == wrap) return;
2942 wd->char_linewrap = wrap;
2943 if(wd->char_linewrap)
2944 wd->linewrap = EINA_FALSE;
2945 t = eina_stringshare_add(elm_entry_entry_get(obj));
2946 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2947 elm_entry_entry_set(obj, t);
2948 eina_stringshare_del(t);
2953 * This sets the editable attribute of the entry.
2955 * @param obj The entry object
2956 * @param editable If true, the entry will be editable by the user.
2957 * If false, it will be set to the disabled state.
2962 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2964 ELM_CHECK_WIDTYPE(obj, widtype);
2965 Widget_Data *wd = elm_widget_data_get(obj);
2968 if (wd->editable == editable) return;
2969 wd->editable = editable;
2970 t = eina_stringshare_add(elm_entry_entry_get(obj));
2971 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2972 elm_entry_entry_set(obj, t);
2973 eina_stringshare_del(t);
2976 #ifdef HAVE_ELEMENTARY_X
2978 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2980 elm_drop_target_del(obj);
2985 * This gets the editable attribute of the entry.
2986 * See also elm_entry_editable_set().
2988 * @param obj The entry object
2989 * @return If true, the entry is editable by the user.
2990 * If false, it is not editable by the user
2995 elm_entry_editable_get(const Evas_Object *obj)
2997 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2998 Widget_Data *wd = elm_widget_data_get(obj);
2999 if (!wd) return EINA_FALSE;
3000 return wd->editable;
3004 * This drops any existing text selection within the entry.
3006 * @param obj The entry object
3011 elm_entry_select_none(Evas_Object *obj)
3013 ELM_CHECK_WIDTYPE(obj, widtype);
3014 Widget_Data *wd = elm_widget_data_get(obj);
3018 wd->selmode = EINA_FALSE;
3019 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3020 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3022 wd->have_selection = EINA_FALSE;
3023 edje_object_part_text_select_none(wd->ent, "elm.text");
3027 * This selects all text within the entry.
3029 * @param obj The entry object
3034 elm_entry_select_all(Evas_Object *obj)
3036 ELM_CHECK_WIDTYPE(obj, widtype);
3037 Widget_Data *wd = elm_widget_data_get(obj);
3041 wd->selmode = EINA_FALSE;
3042 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3043 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3045 wd->have_selection = EINA_TRUE;
3046 edje_object_part_text_select_all(wd->ent, "elm.text");
3050 * This function returns the geometry of the cursor.
3052 * It's useful if you want to draw something on the cursor (or where it is),
3053 * or for example in the case of scrolled entry where you want to show the
3056 * @param obj The entry object
3057 * @param x returned geometry
3058 * @param y returned geometry
3059 * @param w returned geometry
3060 * @param h returned geometry
3061 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3066 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3068 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3069 Widget_Data *wd = elm_widget_data_get(obj);
3070 if (!wd) return EINA_FALSE;
3071 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3076 * This moves the cursor one place to the right within the entry.
3078 * @param obj The entry object
3079 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3084 elm_entry_cursor_next(Evas_Object *obj)
3086 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3087 Widget_Data *wd = elm_widget_data_get(obj);
3088 if (!wd) return EINA_FALSE;
3089 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3093 * This moves the cursor one place to the left within the entry.
3095 * @param obj The entry object
3096 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3101 elm_entry_cursor_prev(Evas_Object *obj)
3103 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3104 Widget_Data *wd = elm_widget_data_get(obj);
3105 if (!wd) return EINA_FALSE;
3106 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3110 * This moves the cursor one line up within the entry.
3112 * @param obj The entry object
3113 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3118 elm_entry_cursor_up(Evas_Object *obj)
3120 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3121 Widget_Data *wd = elm_widget_data_get(obj);
3122 if (!wd) return EINA_FALSE;
3123 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3127 * This moves the cursor one line down within the entry.
3129 * @param obj The entry object
3130 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3135 elm_entry_cursor_down(Evas_Object *obj)
3137 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3138 Widget_Data *wd = elm_widget_data_get(obj);
3139 if (!wd) return EINA_FALSE;
3140 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3144 * This moves the cursor to the beginning of the entry.
3146 * @param obj The entry object
3151 elm_entry_cursor_begin_set(Evas_Object *obj)
3153 ELM_CHECK_WIDTYPE(obj, widtype);
3154 Widget_Data *wd = elm_widget_data_get(obj);
3156 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3160 * This moves the cursor to the end of the entry.
3162 * @param obj The entry object
3167 elm_entry_cursor_end_set(Evas_Object *obj)
3169 ELM_CHECK_WIDTYPE(obj, widtype);
3170 Widget_Data *wd = elm_widget_data_get(obj);
3172 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3176 * This moves the cursor to the beginning of the current line.
3178 * @param obj The entry object
3183 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3185 ELM_CHECK_WIDTYPE(obj, widtype);
3186 Widget_Data *wd = elm_widget_data_get(obj);
3188 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3192 * This moves the cursor to the end of the current line.
3194 * @param obj The entry object
3199 elm_entry_cursor_line_end_set(Evas_Object *obj)
3201 ELM_CHECK_WIDTYPE(obj, widtype);
3202 Widget_Data *wd = elm_widget_data_get(obj);
3204 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3208 * This begins a selection within the entry as though
3209 * the user were holding down the mouse button to make a selection.
3211 * @param obj The entry object
3216 elm_entry_cursor_selection_begin(Evas_Object *obj)
3218 ELM_CHECK_WIDTYPE(obj, widtype);
3219 Widget_Data *wd = elm_widget_data_get(obj);
3221 edje_object_part_text_select_begin(wd->ent, "elm.text");
3225 * This ends a selection within the entry as though
3226 * the user had just released the mouse button while making a selection.
3228 * @param obj The entry object
3233 elm_entry_cursor_selection_end(Evas_Object *obj)
3235 ELM_CHECK_WIDTYPE(obj, widtype);
3236 Widget_Data *wd = elm_widget_data_get(obj);
3238 edje_object_part_text_select_extend(wd->ent, "elm.text");
3242 * TODO: fill this in
3244 * @param obj The entry object
3245 * @return TODO: fill this in
3250 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3252 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3253 Widget_Data *wd = elm_widget_data_get(obj);
3254 if (!wd) return EINA_FALSE;
3255 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3259 * This returns whether the cursor is visible.
3261 * @param obj The entry object
3262 * @return If true, the cursor is visible.
3267 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3269 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3270 Widget_Data *wd = elm_widget_data_get(obj);
3271 if (!wd) return EINA_FALSE;
3272 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3276 * TODO: fill this in
3278 * @param obj The entry object
3279 * @return TODO: fill this in
3284 elm_entry_cursor_content_get(const Evas_Object *obj)
3286 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3287 Widget_Data *wd = elm_widget_data_get(obj);
3288 if (!wd) return NULL;
3289 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3293 * This executes a "cut" action on the selected text in the entry.
3295 * @param obj The entry object
3300 elm_entry_selection_cut(Evas_Object *obj)
3302 ELM_CHECK_WIDTYPE(obj, widtype);
3303 Widget_Data *wd = elm_widget_data_get(obj);
3305 _cut(obj, NULL, NULL);
3309 * This executes a "copy" action on the selected text in the entry.
3311 * @param obj The entry object
3316 elm_entry_selection_copy(Evas_Object *obj)
3318 ELM_CHECK_WIDTYPE(obj, widtype);
3319 Widget_Data *wd = elm_widget_data_get(obj);
3321 _copy(obj, NULL, NULL);
3325 * This executes a "paste" action in the entry.
3327 * @param obj The entry object
3332 elm_entry_selection_paste(Evas_Object *obj)
3334 ELM_CHECK_WIDTYPE(obj, widtype);
3335 Widget_Data *wd = elm_widget_data_get(obj);
3337 _paste(obj, NULL, NULL);
3341 * This clears and frees the items in a entry's contextual (right click) menu.
3343 * @param obj The entry object
3348 elm_entry_context_menu_clear(Evas_Object *obj)
3350 ELM_CHECK_WIDTYPE(obj, widtype);
3351 Widget_Data *wd = elm_widget_data_get(obj);
3352 Elm_Entry_Context_Menu_Item *it;
3354 EINA_LIST_FREE(wd->items, it)
3356 eina_stringshare_del(it->label);
3357 eina_stringshare_del(it->icon_file);
3358 eina_stringshare_del(it->icon_group);
3364 * This adds an item to the entry's contextual menu.
3366 * @param obj The entry object
3367 * @param label The item's text label
3368 * @param icon_file The item's icon file
3369 * @param icon_type The item's icon type
3370 * @param func The callback to execute when the item is clicked
3371 * @param data The data to associate with the item for related functions
3376 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)
3378 ELM_CHECK_WIDTYPE(obj, widtype);
3379 Widget_Data *wd = elm_widget_data_get(obj);
3380 Elm_Entry_Context_Menu_Item *it;
3382 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3384 wd->items = eina_list_append(wd->items, it);
3386 it->label = eina_stringshare_add(label);
3387 it->icon_file = eina_stringshare_add(icon_file);
3388 it->icon_type = icon_type;
3390 it->data = (void *)data;
3394 * This disables the entry's contextual (right click) menu.
3396 * @param obj The entry object
3397 * @param disabled If true, the menu is disabled
3402 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3404 ELM_CHECK_WIDTYPE(obj, widtype);
3405 Widget_Data *wd = elm_widget_data_get(obj);
3407 if (wd->context_menu == !disabled) return;
3408 wd->context_menu = !disabled;
3412 * This returns whether the entry's contextual (right click) menu is disabled.
3414 * @param obj The entry object
3415 * @return If true, the menu is disabled
3420 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3422 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3423 Widget_Data *wd = elm_widget_data_get(obj);
3424 if (!wd) return EINA_FALSE;
3425 return !wd->context_menu;
3429 * This appends a custom item provider to the list for that entry
3431 * This appends the given callback. The list is walked from beginning to end
3432 * with each function called given the item href string in the text. If the
3433 * function returns an object handle other than NULL (it should create an
3434 * and object to do this), then this object is used to replace that item. If
3435 * not the next provider is called until one provides an item object, or the
3436 * default provider in entry does.
3438 * @param obj The entry object
3439 * @param func The function called to provide the item object
3440 * @param data The data passed to @p func
3445 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3447 ELM_CHECK_WIDTYPE(obj, widtype);
3448 Widget_Data *wd = elm_widget_data_get(obj);
3450 EINA_SAFETY_ON_NULL_RETURN(func);
3451 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3455 wd->item_providers = eina_list_append(wd->item_providers, ip);
3459 * This prepends a custom item provider to the list for that entry
3461 * This prepends the given callback. See elm_entry_item_provider_append() for
3464 * @param obj The entry object
3465 * @param func The function called to provide the item object
3466 * @param data The data passed to @p func
3471 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3473 ELM_CHECK_WIDTYPE(obj, widtype);
3474 Widget_Data *wd = elm_widget_data_get(obj);
3476 EINA_SAFETY_ON_NULL_RETURN(func);
3477 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3481 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3485 * This removes a custom item provider to the list for that entry
3487 * This removes the given callback. See elm_entry_item_provider_append() for
3490 * @param obj The entry object
3491 * @param func The function called to provide the item object
3492 * @param data The data passed to @p func
3497 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3499 ELM_CHECK_WIDTYPE(obj, widtype);
3500 Widget_Data *wd = elm_widget_data_get(obj);
3502 Elm_Entry_Item_Provider *ip;
3504 EINA_SAFETY_ON_NULL_RETURN(func);
3505 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3507 if ((ip->func == func) && (ip->data == data))
3509 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3517 * Append a filter function for text inserted in the entry
3519 * Append the given callback to the list. This functions will be called
3520 * whenever any text is inserted into the entry, with the text to be inserted
3521 * as a parameter. The callback function is free to alter the text in any way
3522 * it wants, but it must remember to free the given pointer and update it.
3523 * If the new text is to be discarded, the function can free it and set it text
3524 * parameter to NULL. This will also prevent any following filters from being
3527 * @param obj The entry object
3528 * @param func The function to use as text filter
3529 * @param data User data to pass to @p func
3534 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3537 Elm_Entry_Text_Filter *tf;
3538 ELM_CHECK_WIDTYPE(obj, widtype);
3540 wd = elm_widget_data_get(obj);
3542 EINA_SAFETY_ON_NULL_RETURN(func);
3544 tf = ELM_NEW(Elm_Entry_Text_Filter);
3548 wd->text_filters = eina_list_append(wd->text_filters, tf);
3552 * Prepend a filter function for text insdrted in the entry
3554 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3555 * for more information
3557 * @param obj The entry object
3558 * @param func The function to use as text filter
3559 * @param data User data to pass to @p func
3564 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3567 Elm_Entry_Text_Filter *tf;
3568 ELM_CHECK_WIDTYPE(obj, widtype);
3570 wd = elm_widget_data_get(obj);
3572 EINA_SAFETY_ON_NULL_RETURN(func);
3574 tf = ELM_NEW(Elm_Entry_Text_Filter);
3578 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3582 * Remove a filter from the list
3584 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3585 * for more information.
3587 * @param obj The entry object
3588 * @param func The filter function to remove
3589 * @param data The user data passed when adding the function
3594 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3598 Elm_Entry_Text_Filter *tf;
3599 ELM_CHECK_WIDTYPE(obj, widtype);
3601 wd = elm_widget_data_get(obj);
3603 EINA_SAFETY_ON_NULL_RETURN(func);
3605 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3607 if ((tf->func == func) && (tf->data == data))
3609 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3617 * This converts a markup (HTML-like) string into UTF-8.
3619 * @param s The string (in markup) to be converted
3620 * @return The converted string (in UTF-8)
3625 elm_entry_markup_to_utf8(const char *s)
3627 char *ss = _elm_util_mkup_to_text(s);
3628 if (!ss) ss = strdup("");
3633 * This converts a UTF-8 string into markup (HTML-like).
3635 * @param s The string (in UTF-8) to be converted
3636 * @return The converted string (in markup)
3641 elm_entry_utf8_to_markup(const char *s)
3643 char *ss = _elm_util_text_to_mkup(s);
3644 if (!ss) ss = strdup("");
3649 * Get the input method context in the entry widget
3651 * @param obj The entry object
3652 * @return The input method context
3656 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3658 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3659 Widget_Data *wd = elm_widget_data_get(obj);
3660 if (!wd || !wd->ent) return NULL;
3662 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3666 * Set whether entry should enable the return key on soft keyboard automatically
3668 * @param obj The entry object
3669 * @param on If true, entry enables the return key on soft keyboard automatically.
3674 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3676 ELM_CHECK_WIDTYPE(obj, widtype);
3677 Widget_Data *wd = elm_widget_data_get(obj);
3680 wd->autoreturnkey = on;
3681 _check_enable_returnkey(obj);
3685 * Set whether entry should support auto capitalization
3687 * @param obj The entry object
3688 * @param on If true, entry suports auto capitalization.
3693 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3695 ELM_CHECK_WIDTYPE(obj, widtype);
3696 Widget_Data *wd = elm_widget_data_get(obj);
3700 wd->autocapital = EINA_FALSE;
3702 wd->autocapital = autocap;
3704 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3705 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3706 wd->autocapital = EINA_FALSE;
3708 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3712 * Set whether entry should support auto period
3714 * @param obj The entry object
3715 * @param on If true, entry suports auto period.
3720 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3722 ELM_CHECK_WIDTYPE(obj, widtype);
3723 Widget_Data *wd = elm_widget_data_get(obj);
3727 wd->autoperiod = EINA_FALSE;
3729 wd->autoperiod = autoperiod;
3731 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3732 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3733 wd->autoperiod = EINA_FALSE;
3735 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3739 * Set the font size on the entry object
3741 * @param obj The entry object
3742 * @param size font size
3747 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3749 ELM_CHECK_WIDTYPE(obj, widtype);
3750 Widget_Data *wd = elm_widget_data_get(obj);
3751 Eina_Strbuf *fontbuf = NULL;
3756 t = eina_stringshare_add(elm_entry_entry_get(obj));
3757 fontbuf = eina_strbuf_new();
3758 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3760 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3762 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3764 elm_entry_entry_set(obj, t);
3768 eina_strbuf_free(fontbuf);
3769 eina_stringshare_del(t);
3773 * Set the text align on the entry object
3775 * @param obj The entry object
3776 * @param align align mode
3781 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3783 ELM_CHECK_WIDTYPE(obj, widtype);
3784 Widget_Data *wd = elm_widget_data_get(obj);
3789 t = eina_stringshare_add(elm_entry_entry_get(obj));
3791 if (len <= 0) return;
3793 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3794 elm_entry_entry_set(obj, t);
3798 eina_stringshare_del(t);
3802 * Set the text color on the entry object
3804 * @param obj The entry object
3805 * @param r Red property background color of The entry object
3806 * @param g Green property background color of The entry object
3807 * @param b Blue property background color of The entry object
3808 * @param a Alpha property background alpha of The entry object
3813 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3815 ELM_CHECK_WIDTYPE(obj, widtype);
3816 Widget_Data *wd = elm_widget_data_get(obj);
3817 Eina_Strbuf *colorbuf = NULL;
3822 t = eina_stringshare_add(elm_entry_entry_get(obj));
3824 if (len <= 0) return;
3825 colorbuf = eina_strbuf_new();
3826 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3828 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3830 elm_entry_entry_set(obj, t);
3834 eina_strbuf_free(colorbuf);
3835 eina_stringshare_del(t);
3839 * Set background color of the entry
3841 * @param obj The entry object
3842 * @param r Red property background color of The entry object
3843 * @param g Green property background color of The entry object
3844 * @param b Blue property background color of The entry object
3845 * @param a Alpha property background alpha of The entry object
3849 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3851 ELM_CHECK_WIDTYPE(obj, widtype);
3852 Widget_Data *wd = elm_widget_data_get(obj);
3853 evas_object_color_set(wd->bg, r, g, b, a);
3855 if (wd->bgcolor == EINA_FALSE)
3858 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3863 * Set the ellipsis behavior of the entry
3865 * @param obj The entry object
3866 * @param ellipsis To ellipsis text or not
3870 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3872 ELM_CHECK_WIDTYPE(obj, widtype);
3873 Widget_Data *wd = elm_widget_data_get(obj);
3874 if (wd->ellipsis == ellipsis) return;
3875 wd->ellipsis = ellipsis;
3881 * Filter inserted text based on user defined character and byte limits
3883 * Add this filter to an entry to limit the characters that it will accept
3884 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3885 * The funtion works on the UTF-8 representation of the string, converting
3886 * it from the set markup, thus not accounting for any format in it.
3888 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3889 * it as data when setting the filter. In it it's possible to set limits
3890 * by character count or bytes (any of them is disabled if 0), and both can
3891 * be set at the same time. In that case, it first checks for characters,
3894 * The function will cut the inserted text in order to allow only the first
3895 * number of characters that are still allowed. The cut is made in
3896 * characters, even when limiting by bytes, in order to always contain
3897 * valid ones and avoid half unicode characters making it in.
3902 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3904 Elm_Entry_Filter_Limit_Size *lim = data;
3907 const char *(*text_get)(const Evas_Object *);
3908 const char *widget_type;
3910 EINA_SAFETY_ON_NULL_RETURN(data);
3911 EINA_SAFETY_ON_NULL_RETURN(entry);
3912 EINA_SAFETY_ON_NULL_RETURN(text);
3914 /* hack. I don't want to copy the entire function to work with
3916 widget_type = elm_widget_type_get(entry);
3917 if (!strcmp(widget_type, "entry"))
3918 text_get = elm_entry_entry_get;
3919 else if (!strcmp(widget_type, "scrolled_entry"))
3920 text_get = elm_scrolled_entry_entry_get;
3924 current = elm_entry_markup_to_utf8(text_get(entry));
3926 if (lim->max_char_count > 0)
3929 len = evas_string_char_len_get(current);
3930 if (len >= lim->max_char_count)
3932 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3938 newlen = evas_string_char_len_get(*text);
3939 cut = strlen(*text);
3940 while ((len + newlen) > lim->max_char_count)
3942 cut = evas_string_char_prev_get(*text, cut, NULL);
3948 if (lim->max_byte_count > 0)
3950 len = strlen(current);
3951 if (len >= lim->max_byte_count)
3953 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3959 newlen = strlen(*text);
3960 while ((len + newlen) > lim->max_byte_count)
3962 int p = evas_string_char_prev_get(*text, newlen, NULL);
3963 newlen -= (newlen - p);
3966 (*text)[newlen] = 0;
3977 * Filter inserted text based on accepted or rejected sets of characters
3979 * Add this filter to an entry to restrict the set of accepted characters
3980 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3981 * This structure contains both accepted and rejected sets, but they are
3982 * mutually exclusive. If accepted is set, it will be used, otherwise it
3983 * goes on to the rejected set.
3986 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3988 Elm_Entry_Filter_Accept_Set *as = data;
3992 int read_idx, last_read_idx = 0, read_char;
3994 EINA_SAFETY_ON_NULL_RETURN(data);
3995 EINA_SAFETY_ON_NULL_RETURN(text);
3997 if ((!as->accepted) && (!as->rejected))
4003 goes_in = EINA_TRUE;
4008 goes_in = EINA_FALSE;
4012 read_idx = evas_string_char_next_get(*text, 0, &read_char);
4015 int cmp_idx, cmp_char;
4016 Eina_Bool in_set = EINA_FALSE;
4018 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4021 if (read_char == cmp_char)
4026 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4028 if (in_set == goes_in)
4030 int size = read_idx - last_read_idx;
4031 const char *src = (*text) + last_read_idx;
4033 memcpy(insert, *text + last_read_idx, size);
4036 last_read_idx = read_idx;
4037 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4043 * This sets the file (and implicitly loads it) for the text to display and
4044 * then edit. All changes are written back to the file after a short delay if
4045 * the entry object is set to autosave.
4047 * @param obj The entry object
4048 * @param file The path to the file to load and save
4049 * @param format The file format
4054 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4056 ELM_CHECK_WIDTYPE(obj, widtype);
4057 Widget_Data *wd = elm_widget_data_get(obj);
4059 if (wd->delay_write)
4061 ecore_timer_del(wd->delay_write);
4062 wd->delay_write = NULL;
4064 if (wd->autosave) _save(obj);
4065 eina_stringshare_replace(&wd->file, file);
4066 wd->format = format;
4071 * Gets the file to load and save and the file format
4073 * @param obj The entry object
4074 * @param file The path to the file to load and save
4075 * @param format The file format
4080 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4082 ELM_CHECK_WIDTYPE(obj, widtype);
4083 Widget_Data *wd = elm_widget_data_get(obj);
4085 if (file) *file = wd->file;
4086 if (format) *format = wd->format;
4090 * This function writes any changes made to the file set with
4091 * elm_entry_file_set()
4093 * @param obj The entry object
4098 elm_entry_file_save(Evas_Object *obj)
4100 ELM_CHECK_WIDTYPE(obj, widtype);
4101 Widget_Data *wd = elm_widget_data_get(obj);
4103 if (wd->delay_write)
4105 ecore_timer_del(wd->delay_write);
4106 wd->delay_write = NULL;
4109 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4113 * This sets the entry object to 'autosave' the loaded text file or not.
4115 * @param obj The entry object
4116 * @param autosave Autosave the loaded file or not
4121 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4123 ELM_CHECK_WIDTYPE(obj, widtype);
4124 Widget_Data *wd = elm_widget_data_get(obj);
4126 wd->autosave = !!autosave;
4130 * This gets the entry object's 'autosave' status.
4132 * @param obj The entry object
4133 * @return Autosave the loaded file or not
4138 elm_entry_autosave_get(const Evas_Object *obj)
4140 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4141 Widget_Data *wd = elm_widget_data_get(obj);
4142 if (!wd) return EINA_FALSE;
4143 return wd->autosave;
4147 * Control pasting of text and images for the widget.
4149 * Normally the entry allows both text and images to be pasted. By setting
4150 * textonly to be true, this prevents images from being pasted.
4152 * Note this only changes the behaviour of text.
4154 * @param obj The entry object
4155 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
4160 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4162 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4163 ELM_CHECK_WIDTYPE(obj, widtype);
4164 Widget_Data *wd = elm_widget_data_get(obj);
4166 textonly = !!textonly;
4167 if (wd->textonly == textonly) return;
4168 wd->textonly = !!textonly;
4172 * Getting elm_entry text paste/drop mode.
4174 * In textonly mode, only text may be pasted or dropped into the widget.
4176 * @param obj The entry object
4177 * @return If the widget only accepts text from pastes.
4182 elm_entry_cnp_textonly_get(Evas_Object *obj)
4184 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4185 Widget_Data *wd = elm_widget_data_get(obj);
4186 if (!wd) return EINA_FALSE;
4187 return wd->textonly;
4191 * This sets the attribute to show the input panel automatically.
4193 * @param obj The entry object
4194 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4199 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4201 ELM_CHECK_WIDTYPE(obj, widtype);
4202 Widget_Data *wd = elm_widget_data_get(obj);
4205 wd->input_panel_enable = enabled;
4206 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4210 * Set the input panel layout of the entry
4212 * @param obj The entry object
4213 * @param layout the layout to set
4218 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4220 ELM_CHECK_WIDTYPE(obj, widtype);
4221 Widget_Data *wd = elm_widget_data_get(obj);
4224 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4227 wd->input_panel_layout = layout;
4229 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4233 * Set the magnifier style of the entry
4235 * @param obj The entry object
4236 * @param type the magnifier style to set
4241 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4243 ELM_CHECK_WIDTYPE(obj, widtype);
4244 Widget_Data *wd = elm_widget_data_get(obj);
4247 wd->mgf_type = type;
4248 _magnifier_create(obj);