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, const char *source __UNUSED__)
1706 Widget_Data *wd = elm_widget_data_get(data);
1707 Elm_Entry_Anchor_Info ei;
1708 char *buf2, *p, *p2, *n;
1710 p = strrchr(emission, ',');
1713 const Eina_List *geoms;
1717 while (p2 >= emission)
1719 if (*p2 == ',') break;
1723 buf2 = alloca(5 + p - p2);
1724 strncpy(buf2, p2, p - p2);
1727 ei.button = atoi(buf2);
1728 ei.x = ei.y = ei.w = ei.h = 0;
1730 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1733 Evas_Textblock_Rectangle *r;
1735 Evas_Coord px, py, x, y;
1737 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1738 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1739 EINA_LIST_FOREACH(geoms, l, r)
1741 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1742 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1753 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1758 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1760 Widget_Data *wd = elm_widget_data_get(data);
1765 _signal_anchor_in(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_out(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_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1781 Widget_Data *wd = elm_widget_data_get(data);
1783 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1787 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1789 Widget_Data *wd = elm_widget_data_get(data);
1791 wd->double_clicked = EINA_FALSE;
1792 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1794 if ((wd->api) && (wd->api->obj_hidemenu))
1796 wd->api->obj_hidemenu(data);
1801 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1803 Widget_Data *wd = elm_widget_data_get(data);
1805 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1809 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1811 Widget_Data *wd = elm_widget_data_get(data);
1813 wd->double_clicked = EINA_TRUE;
1814 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1817 #ifdef HAVE_ELEMENTARY_X
1819 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1821 Widget_Data *wd = elm_widget_data_get(data);
1822 Ecore_X_Event_Selection_Notify *ev = event;
1823 if (!wd) return ECORE_CALLBACK_PASS_ON;
1824 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1825 return ECORE_CALLBACK_PASS_ON;
1827 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1828 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1830 Ecore_X_Selection_Data_Text *text_data;
1832 text_data = ev->data;
1833 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1835 if (text_data->text)
1837 char *txt = _elm_util_text_to_mkup(text_data->text);
1841 elm_entry_entry_insert(data, txt);
1846 wd->selection_asked = EINA_FALSE;
1848 else if (ev->selection == ECORE_X_SELECTION_XDND)
1850 Ecore_X_Selection_Data_Text *text_data;
1852 text_data = ev->data;
1853 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1855 if (text_data->text)
1857 char *txt = _elm_util_text_to_mkup(text_data->text);
1861 /* Massive FIXME: this should be at the drag point */
1862 elm_entry_entry_insert(data, txt);
1867 wd->drag_selection_asked = EINA_FALSE;
1869 ecore_x_dnd_send_finished();
1872 return ECORE_CALLBACK_PASS_ON;
1876 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1879 Widget_Data *wd = elm_widget_data_get(data);
1880 Ecore_X_Event_Selection_Clear *ev = event;
1881 if (!wd) return ECORE_CALLBACK_PASS_ON;
1882 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1883 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1884 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1886 elm_entry_select_none(data);
1891 Evas_Object *top = elm_widget_top_get(data);
1892 Ecore_X_Event_Selection_Clear *ev = event;
1895 return ECORE_CALLBACK_PASS_ON;
1897 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1899 return ECORE_CALLBACK_PASS_ON;
1902 if (cnpwidgetdata == data)
1904 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
1908 return ECORE_CALLBACK_PASS_ON;
1913 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1918 wd = elm_widget_data_get(obj);
1920 if (!wd) return EINA_FALSE;
1921 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1923 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1924 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1925 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1926 EDJE_CURSOR_MAIN,drop->x,drop->y);
1927 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1928 elm_entry_entry_insert(obj, drop->data);
1929 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1930 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1936 static Evas_Object *
1937 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1939 Widget_Data *wd = elm_widget_data_get(data);
1942 Elm_Entry_Item_Provider *ip;
1944 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1946 o = ip->func(ip->data, data, item);
1949 if (!strncmp(item, "file://", 7))
1951 const char *fname = item + 7;
1953 o = evas_object_image_filled_add(evas_object_evas_get(data));
1954 evas_object_image_file_set(o, fname, NULL);
1955 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1957 evas_object_show(o);
1962 o = edje_object_add(evas_object_evas_get(data));
1963 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1967 o = edje_object_add(evas_object_evas_get(data));
1968 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1969 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1974 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1976 char *curlocater, *starttag, *endtag;
1977 int firstindex = 0, foundflag = -1;
1979 curlocater = strstr(oldstring, key);
1982 starttag = curlocater;
1983 endtag = curlocater + strlen(key);
1984 if (endtag == NULL || *endtag != '=')
1990 firstindex = abs(oldstring - curlocater);
1991 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1992 *value = (char*)(oldstring + firstindex);
1994 while (oldstring != starttag)
1996 if (*starttag == '>')
2001 if (*starttag == '<')
2005 if (starttag == NULL) break;
2008 while (NULL != endtag)
2019 if (endtag == NULL) break;
2022 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
2032 if (foundflag == 1) return 0;
2038 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2040 const char *srcstring = NULL;
2041 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2042 char *curlocater, *replocater;
2043 char *starttag, *endtag;
2044 int tagtxtlen = 0, insertflag = 0;
2046 srcstring = eina_strbuf_string_get(srcbuf);
2047 curlocater = strstr(srcstring, key);
2049 if (!curlocater || !srcstring)
2057 starttag = strchr(srcstring, '<');
2058 endtag = strchr(srcstring, '>');
2059 tagtxtlen = endtag - starttag;
2060 if (tagtxtlen <= 0) tagtxtlen = 0;
2061 if (starttag < curlocater && curlocater < endtag) break;
2062 if (endtag != NULL && endtag+1 != NULL)
2063 srcstring = endtag+1;
2066 } while (strlen(srcstring) > 1);
2068 if (starttag && endtag && tagtxtlen > strlen(key))
2070 repbuf = eina_strbuf_new();
2071 diffbuf = eina_strbuf_new();
2072 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2073 srcstring = eina_strbuf_string_get(repbuf);
2074 curlocater = strstr(srcstring, key);
2076 if (curlocater != NULL)
2078 replocater = curlocater + strlen(key) + 1;
2080 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2083 if (replocater-curlocater > strlen(key)+1)
2085 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2094 eina_strbuf_reset(repbuf);
2102 if (repbuf == NULL) repbuf = eina_strbuf_new();
2103 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2107 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2108 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2114 eina_strbuf_prepend(diffbuf, "<");
2115 eina_strbuf_append(diffbuf, ">");
2116 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2120 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2121 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2125 if (repbuf) eina_strbuf_free(repbuf);
2126 if (diffbuf) eina_strbuf_free(diffbuf);
2132 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2134 Eina_Strbuf *sharebuf = NULL;
2136 sharebuf = eina_strbuf_new();
2137 eina_strbuf_append(sharebuf, *srcstring);
2138 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2139 eina_stringshare_del(*srcstring);
2140 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2141 eina_strbuf_free(sharebuf);
2147 _is_width_over(Evas_Object *obj)
2149 Evas_Coord x, y, w, h;
2150 Evas_Coord vx, vy, vw, vh;
2151 Widget_Data *wd = elm_widget_data_get(obj);
2155 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
2157 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
2159 if (x >= 0 && y >= 0)
2162 if (4 < wd->wrap_w && w > wd->wrap_w)
2169 _reverse_ellipsis_entry(Evas_Object *obj)
2171 Widget_Data *wd = elm_widget_data_get(obj);
2172 int cur_fontsize = 0;
2173 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
2174 char *kvalue = NULL;
2175 const char *minfont, *deffont, *maxfont;
2176 const char *ellipsis_string = "...";
2177 int minfontsize, maxfontsize, minshowcount;
2179 minshowcount = strlen(ellipsis_string) + 1;
2180 minfont = edje_object_data_get(wd->ent, "min_font_size");
2181 if (minfont) minfontsize = atoi(minfont);
2182 else minfontsize = 1;
2183 maxfont = edje_object_data_get(wd->ent, "max_font_size");
2184 if (maxfont) maxfontsize = atoi(maxfont);
2185 else maxfontsize = 1;
2186 deffont = edje_object_data_get(wd->ent, "default_font_size");
2187 if (deffont) cur_fontsize = atoi(deffont);
2188 else cur_fontsize = 1;
2189 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
2190 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
2192 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
2194 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
2197 txtbuf = eina_strbuf_new();
2198 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
2200 if (cur_fontsize >= atoi(deffont))
2202 if (txtbuf) eina_strbuf_free(txtbuf);
2206 if (_is_width_over(obj) != 1)
2208 int rev_fontsize = cur_fontsize;
2212 if (rev_fontsize > atoi(deffont))
2215 if (fontbuf != NULL)
2217 eina_strbuf_free(fontbuf);
2220 fontbuf = eina_strbuf_new();
2221 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
2222 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2223 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2225 eina_strbuf_free(fontbuf);
2227 } while (_is_width_over(obj) != 1);
2229 while (_is_width_over(obj))
2232 if (rev_fontsize < atoi(deffont))
2235 if (fontbuf != NULL)
2237 eina_strbuf_free(fontbuf);
2240 fontbuf = eina_strbuf_new();
2241 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
2242 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2243 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2244 eina_strbuf_free(fontbuf);
2249 if (txtbuf) eina_strbuf_free(txtbuf);
2255 _ellipsis_entry_to_width(Evas_Object *obj)
2257 Widget_Data *wd = elm_widget_data_get(obj);
2258 int cur_fontsize = 0, len, jumpcount;
2259 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
2260 char *kvalue = NULL;
2261 const char *minfont, *deffont, *maxfont;
2262 const char *ellipsis_string = "...";
2263 int minfontsize, maxfontsize, minshowcount;
2264 int i, tagend, cur_len;
2267 minshowcount = strlen(ellipsis_string) + 1;
2268 minfont = edje_object_data_get(wd->ent, "min_font_size");
2269 if (minfont) minfontsize = atoi(minfont);
2270 else minfontsize = 1;
2271 maxfont = edje_object_data_get(wd->ent, "max_font_size");
2272 if (maxfont) maxfontsize = atoi(maxfont);
2273 else maxfontsize = 1;
2274 deffont = edje_object_data_get(wd->ent, "default_font_size");
2275 if (deffont) cur_fontsize = atoi(deffont);
2276 else cur_fontsize = 1;
2277 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
2278 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
2280 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
2282 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
2285 txtbuf = eina_strbuf_new();
2286 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
2288 while (_is_width_over(obj))
2290 if (wd->ellipsis_threshold == 0)
2291 wd->ellipsis_threshold = _entry_length_get(obj);
2292 if (cur_fontsize > minfontsize)
2295 if (fontbuf != NULL)
2297 eina_strbuf_free(fontbuf);
2300 fontbuf = eina_strbuf_new();
2301 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
2302 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
2303 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2304 eina_strbuf_free(fontbuf);
2306 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2310 len = _entry_length_get(obj);
2311 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2312 cur_len = strlen(cur_str);
2314 for (i = 0; i < len; i++)
2316 if(cur_str[i] == '>' && cur_str[i+1] != '\0' &&
2317 cur_str[i+1] != '<')
2324 while (jumpcount < len-strlen(ellipsis_string))
2326 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2330 eina_strbuf_free(txtbuf);
2333 txtbuf = eina_strbuf_new();
2334 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
2335 eina_strbuf_append(txtbuf, ellipsis_string);
2336 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
2337 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2338 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2340 if (_is_width_over(obj))
2348 if (txtbuf) eina_strbuf_free(txtbuf);
2353 static Eina_Bool *_textinput_control_function(void *data,void *input_data)
2355 /* calculate character count */
2356 Evas_Object *entry = (Evas_Object *)data;
2357 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
2360 size_t insert_text_len=0;
2361 char *text = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2363 size_t remain_bytes;
2366 byte_len = strlen(text); /* no of bytes */
2367 remain_bytes = wd->max_no_of_bytes - byte_len;
2368 sprintf(buf,"%d",remain_bytes);
2369 //edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
2372 insert_text = (char *)input_data;
2373 insert_text_len = strlen(insert_text);
2374 if (remain_bytes < insert_text_len)
2376 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2379 if (byte_len >= wd->max_no_of_bytes)
2381 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2391 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2393 Widget_Data *wd = elm_widget_data_get(data);
2395 Elm_Entry_Text_Filter *tf;
2397 if (type == EDJE_TEXT_FILTER_FORMAT)
2400 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2402 tf->func(tf->data, data, text);
2409 * This adds an entry to @p parent object.
2411 * @param parent The parent object
2412 * @return The new object or NULL if it cannot be created
2417 elm_entry_add(Evas_Object *parent)
2419 Evas_Object *obj, *top;
2423 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2425 wd = ELM_NEW(Widget_Data);
2426 e = evas_object_evas_get(parent);
2427 if (!e) return NULL;
2428 wd->bgcolor = EINA_FALSE;
2429 wd->bg = evas_object_rectangle_add(e);
2430 evas_object_color_set(wd->bg, 0, 0, 0, 0);
2431 obj = elm_widget_add(e);
2432 ELM_SET_WIDTYPE(widtype, "entry");
2433 elm_widget_type_set(obj, "entry");
2434 elm_widget_sub_object_add(parent, obj);
2435 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2436 elm_widget_data_set(obj, wd);
2437 elm_widget_del_hook_set(obj, _del_hook);
2438 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2439 elm_widget_theme_hook_set(obj, _theme_hook);
2440 elm_widget_disable_hook_set(obj, _disable_hook);
2441 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2442 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2443 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2444 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2445 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2446 elm_widget_can_focus_set(obj, EINA_TRUE);
2447 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2449 wd->linewrap = EINA_TRUE;
2450 wd->ellipsis = EINA_FALSE;
2451 wd->char_linewrap= EINA_FALSE;
2452 wd->editable = EINA_TRUE;
2453 wd->disabled = EINA_FALSE;
2454 wd->context_menu = EINA_TRUE;
2455 wd->autosave = EINA_TRUE;
2456 wd->textonly = EINA_FALSE;
2457 wd->autoperiod = EINA_TRUE;
2459 wd->ellipsis_threshold = 0;
2461 wd->ent = edje_object_add(e);
2462 edje_object_item_provider_set(wd->ent, _get_item, obj);
2463 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2464 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2465 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2466 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2468 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2470 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2473 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2474 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2475 _signal_entry_changed, obj);
2476 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2477 _signal_handler_move_start, obj);
2478 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2479 _signal_handler_move_end, obj);
2480 edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2481 _signal_handler_moving, obj);
2482 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2483 _signal_selection_start, obj);
2484 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2485 _signal_selection_end, obj);
2486 edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2487 _signal_magnifier_changed, obj);
2488 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2489 _signal_selection_changed, obj);
2490 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2491 _signal_selection_cleared, obj);
2492 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2493 _signal_entry_paste_request, obj);
2494 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2495 _signal_entry_copy_notify, obj);
2496 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2497 _signal_entry_cut_notify, obj);
2498 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2499 _signal_cursor_changed, obj);
2500 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2501 _signal_anchor_down, obj);
2502 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2503 _signal_anchor_up, obj);
2504 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2505 _signal_anchor_move, obj);
2506 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2507 _signal_anchor_in, obj);
2508 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2509 _signal_anchor_out, obj);
2510 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2511 _signal_key_enter, obj);
2512 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2513 _signal_mouse_down, obj);
2514 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2515 _signal_mouse_clicked, obj);
2516 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2517 _signal_mouse_double, obj);
2518 edje_object_part_text_set(wd->ent, "elm.text", "");
2519 elm_widget_resize_object_set(obj, wd->ent);
2522 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2524 #ifdef HAVE_ELEMENTARY_X
2525 top = elm_widget_top_get(obj);
2526 if ((top) && (elm_win_xwindow_get(top)))
2528 wd->sel_notify_handler =
2529 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2530 _event_selection_notify, obj);
2531 wd->sel_clear_handler =
2532 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2533 _event_selection_clear, obj);
2536 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2539 entries = eina_list_prepend(entries, obj);
2541 // module - find module for entry
2542 wd->api = _module(obj);
2543 // if found - hook in
2544 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2546 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2547 // TODO: and save some bytes, making descriptions per-class and not instance!
2548 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2552 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2554 ELM_CHECK_WIDTYPE(obj, widtype);
2555 Widget_Data *wd = elm_widget_data_get(obj);
2557 ext_mod->cancel = _cancel;
2558 ext_mod->copy = _copy;
2559 ext_mod->cut = _cut;
2560 ext_mod->paste = _paste;
2561 ext_mod->select = _select;
2562 ext_mod->selectall = _selectall;
2563 ext_mod->ent = wd->ent;
2564 ext_mod->items = wd->items;
2565 ext_mod->longpress_timer = wd->longpress_timer;
2566 ext_mod->editable = wd->editable;
2567 ext_mod->have_selection = wd->have_selection;
2568 ext_mod->password = wd->password;
2569 ext_mod->selmode = wd->selmode;
2570 ext_mod->cnpinit = _cnpinit;
2571 ext_mod->context_menu = wd->context_menu;
2572 ext_mod->textonly = wd->textonly;
2576 * This sets the entry object not to line wrap. All input will
2577 * be on a single line, and the entry box will extend with user input.
2579 * @param obj The entry object
2580 * @param single_line If true, the text in the entry
2581 * will be on a single line.
2586 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2588 ELM_CHECK_WIDTYPE(obj, widtype);
2589 Widget_Data *wd = elm_widget_data_get(obj);
2591 Ecore_IMF_Context *ic;
2593 if (wd->single_line == single_line) return;
2594 wd->single_line = single_line;
2595 wd->linewrap = EINA_FALSE;
2596 wd->char_linewrap = EINA_FALSE;
2597 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2598 t = eina_stringshare_add(elm_entry_entry_get(obj));
2599 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2600 elm_entry_entry_set(obj, t);
2601 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2602 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2603 ic = elm_entry_imf_context_get(obj);
2606 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2609 eina_stringshare_del(t);
2614 * This returns true if the entry has been set to single line mode.
2615 * See also elm_entry_single_line_set().
2617 * @param obj The entry object
2618 * @return single_line If true, the text in the entry is set to display
2624 elm_entry_single_line_get(const Evas_Object *obj)
2626 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2627 Widget_Data *wd = elm_widget_data_get(obj);
2628 if (!wd) return EINA_FALSE;
2629 return wd->single_line;
2633 * This sets the entry object to password mode. All text entered
2634 * and/or displayed within the widget will be replaced with asterisks (*).
2636 * @param obj The entry object
2637 * @param password If true, password mode is enabled.
2642 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2644 ELM_CHECK_WIDTYPE(obj, widtype);
2645 Widget_Data *wd = elm_widget_data_get(obj);
2646 Ecore_IMF_Context *ic;
2649 if (wd->password == password) return;
2650 wd->password = password;
2651 wd->single_line = EINA_TRUE;
2652 wd->linewrap = EINA_FALSE;
2653 wd->char_linewrap = EINA_FALSE;
2654 if (_elm_config->password_show_last_character)
2655 wd->show_last_character = EINA_TRUE;
2656 t = eina_stringshare_add(elm_entry_entry_get(obj));
2657 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2658 elm_entry_entry_set(obj, t);
2663 elm_entry_autoperiod_set(obj, EINA_FALSE);
2665 if (wd->autocapital)
2666 elm_entry_autocapitalization_set(obj, EINA_FALSE);
2669 ic = elm_entry_imf_context_get(obj);
2671 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2673 eina_stringshare_del(t);
2679 * This returns whether password mode is enabled.
2680 * See also elm_entry_password_set().
2682 * @param obj The entry object
2683 * @return If true, the entry is set to display all characters
2689 elm_entry_password_get(const Evas_Object *obj)
2691 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2692 Widget_Data *wd = elm_widget_data_get(obj);
2693 if (!wd) return EINA_FALSE;
2694 return wd->password;
2698 * This sets the text displayed within the entry to @p entry.
2700 * @param obj The entry object
2701 * @param entry The text to be displayed
2706 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2708 ELM_CHECK_WIDTYPE(obj, widtype);
2709 Widget_Data *wd = elm_widget_data_get(obj);
2711 if (!entry) entry = "";
2712 if(wd->max_no_of_bytes)
2714 int len = strlen(entry);
2715 if(len > wd->max_no_of_bytes)
2717 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2721 edje_object_part_text_set(wd->ent, "elm.text", entry);
2722 if (wd->text) eina_stringshare_del(wd->text);
2724 wd->changed = EINA_TRUE;
2729 * This returns the text currently shown in object @p entry.
2730 * See also elm_entry_entry_set().
2732 * @param obj The entry object
2733 * @return The currently displayed text or NULL on failure
2738 elm_entry_entry_get(const Evas_Object *obj)
2740 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2741 Widget_Data *wd = elm_widget_data_get(obj);
2743 if (!wd) return NULL;
2745 if ((wd->text)&&(wd->password))
2746 return elm_entry_markup_to_utf8(wd->text);
2748 if (wd->text) return wd->text;
2749 text = edje_object_part_text_get(wd->ent, "elm.text");
2752 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2755 eina_stringshare_replace(&wd->text, text);
2756 if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2762 * This returns EINA_TRUE if the entry is empty/there was an error
2763 * and EINA_FALSE if it is not empty.
2765 * @param obj The entry object
2766 * @return If the entry is empty or not.
2771 elm_entry_is_empty(const Evas_Object *obj)
2773 /* FIXME: until there's support for that in textblock, we just check
2774 * to see if the there is text or not. */
2775 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2776 Widget_Data *wd = elm_widget_data_get(obj);
2777 const Evas_Object *tb;
2778 Evas_Textblock_Cursor *cur;
2780 if (!wd) return EINA_TRUE;
2783 /* It's a hack until we get the support suggested above.
2784 * We just create a cursor, point it to the begining, and then
2785 * try to advance it, if it can advance, the tb is not empty,
2786 * otherwise it is. */
2787 tb = edje_object_part_object_get(wd->ent, "elm.text");
2788 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2789 actually, ok for the time being, thsese hackish stuff will be removed
2790 once evas 1.0 is out*/
2791 evas_textblock_cursor_pos_set(cur, 0);
2792 ret = evas_textblock_cursor_char_next(cur);
2793 evas_textblock_cursor_free(cur);
2798 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
2799 if (!str) return EINA_TRUE;
2801 ret = (strlen(str) == 0);
2807 * This returns all selected text within the entry.
2809 * @param obj The entry object
2810 * @return The selected text within the entry or NULL on failure
2815 elm_entry_selection_get(const Evas_Object *obj)
2817 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2818 Widget_Data *wd = elm_widget_data_get(obj);
2819 if (!wd) return NULL;
2820 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2824 * This inserts text in @p entry where the current cursor position.
2826 * This inserts text at the cursor position is as if it was typed
2827 * by the user (note this also allows markup which a user
2828 * can't just "type" as it would be converted to escaped text, so this
2829 * call can be used to insert things like emoticon items or bold push/pop
2830 * tags, other font and color change tags etc.)
2832 * @param obj The entry object
2833 * @param entry The text to insert
2838 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2840 ELM_CHECK_WIDTYPE(obj, widtype);
2841 Widget_Data *wd = elm_widget_data_get(obj);
2843 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2845 if (cnpwidgetdata == obj)
2846 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2848 wd->changed = EINA_TRUE;
2853 * This enables word line wrapping in the entry object. It is the opposite
2854 * of elm_entry_single_line_set(). Additionally, setting this disables
2855 * character line wrapping.
2856 * See also elm_entry_line_char_wrap_set().
2858 * @param obj The entry object
2859 * @param wrap If true, the entry will be wrapped once it reaches the end
2860 * of the object. Wrapping will occur at the end of the word before the end of the
2866 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2868 ELM_CHECK_WIDTYPE(obj, widtype);
2869 Widget_Data *wd = elm_widget_data_get(obj);
2872 if (wd->linewrap == wrap) return;
2873 wd->linewrap = wrap;
2875 wd->char_linewrap = EINA_FALSE;
2876 t = eina_stringshare_add(elm_entry_entry_get(obj));
2877 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2878 elm_entry_entry_set(obj, t);
2879 eina_stringshare_del(t);
2884 * Set wrap width of the entry
2886 * @param obj The entry object
2887 * @param w The wrap width in pixels at a minimum where words need to wrap
2891 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2893 Widget_Data *wd = elm_widget_data_get(obj);
2894 if (wd->wrap_w == w) return;
2900 * get wrap width of the entry
2902 * @param obj The entry object
2903 * @return The wrap width in pixels at a minimum where words need to wrap
2907 elm_entry_wrap_width_get(const Evas_Object *obj)
2909 Widget_Data *wd = elm_widget_data_get(obj);
2914 * This enables character line wrapping in the entry object. It is the opposite
2915 * of elm_entry_single_line_set(). Additionally, setting this disables
2916 * word line wrapping.
2917 * See also elm_entry_line_wrap_set().
2919 * @param obj The entry object
2920 * @param wrap If true, the entry will be wrapped once it reaches the end
2921 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2926 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2928 ELM_CHECK_WIDTYPE(obj, widtype);
2929 Widget_Data *wd = elm_widget_data_get(obj);
2932 if (wd->char_linewrap == wrap) return;
2933 wd->char_linewrap = wrap;
2934 if(wd->char_linewrap)
2935 wd->linewrap = EINA_FALSE;
2936 t = eina_stringshare_add(elm_entry_entry_get(obj));
2937 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2938 elm_entry_entry_set(obj, t);
2939 eina_stringshare_del(t);
2944 * This sets the editable attribute of the entry.
2946 * @param obj The entry object
2947 * @param editable If true, the entry will be editable by the user.
2948 * If false, it will be set to the disabled state.
2953 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2955 ELM_CHECK_WIDTYPE(obj, widtype);
2956 Widget_Data *wd = elm_widget_data_get(obj);
2959 if (wd->editable == editable) return;
2960 wd->editable = editable;
2961 t = eina_stringshare_add(elm_entry_entry_get(obj));
2962 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2963 elm_entry_entry_set(obj, t);
2964 eina_stringshare_del(t);
2967 #ifdef HAVE_ELEMENTARY_X
2969 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2971 elm_drop_target_del(obj);
2976 * This gets the editable attribute of the entry.
2977 * See also elm_entry_editable_set().
2979 * @param obj The entry object
2980 * @return If true, the entry is editable by the user.
2981 * If false, it is not editable by the user
2986 elm_entry_editable_get(const Evas_Object *obj)
2988 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2989 Widget_Data *wd = elm_widget_data_get(obj);
2990 if (!wd) return EINA_FALSE;
2991 return wd->editable;
2995 * This drops any existing text selection within the entry.
2997 * @param obj The entry object
3002 elm_entry_select_none(Evas_Object *obj)
3004 ELM_CHECK_WIDTYPE(obj, widtype);
3005 Widget_Data *wd = elm_widget_data_get(obj);
3009 wd->selmode = EINA_FALSE;
3010 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3011 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3013 wd->have_selection = EINA_FALSE;
3014 edje_object_part_text_select_none(wd->ent, "elm.text");
3018 * This selects all text within the entry.
3020 * @param obj The entry object
3025 elm_entry_select_all(Evas_Object *obj)
3027 ELM_CHECK_WIDTYPE(obj, widtype);
3028 Widget_Data *wd = elm_widget_data_get(obj);
3032 wd->selmode = EINA_FALSE;
3033 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3034 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3036 wd->have_selection = EINA_TRUE;
3037 edje_object_part_text_select_all(wd->ent, "elm.text");
3041 * This function returns the geometry of the cursor.
3043 * It's useful if you want to draw something on the cursor (or where it is),
3044 * or for example in the case of scrolled entry where you want to show the
3047 * @param obj The entry object
3048 * @param x returned geometry
3049 * @param y returned geometry
3050 * @param w returned geometry
3051 * @param h returned geometry
3052 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3057 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3059 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3060 Widget_Data *wd = elm_widget_data_get(obj);
3061 if (!wd) return EINA_FALSE;
3062 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3067 * This moves the cursor one place to the right within the entry.
3069 * @param obj The entry object
3070 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3075 elm_entry_cursor_next(Evas_Object *obj)
3077 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3078 Widget_Data *wd = elm_widget_data_get(obj);
3079 if (!wd) return EINA_FALSE;
3080 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3084 * This moves the cursor one place to the left within the entry.
3086 * @param obj The entry object
3087 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3092 elm_entry_cursor_prev(Evas_Object *obj)
3094 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3095 Widget_Data *wd = elm_widget_data_get(obj);
3096 if (!wd) return EINA_FALSE;
3097 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3101 * This moves the cursor one line up within the entry.
3103 * @param obj The entry object
3104 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3109 elm_entry_cursor_up(Evas_Object *obj)
3111 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3112 Widget_Data *wd = elm_widget_data_get(obj);
3113 if (!wd) return EINA_FALSE;
3114 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3118 * This moves the cursor one line down within the entry.
3120 * @param obj The entry object
3121 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3126 elm_entry_cursor_down(Evas_Object *obj)
3128 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3129 Widget_Data *wd = elm_widget_data_get(obj);
3130 if (!wd) return EINA_FALSE;
3131 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3135 * This moves the cursor to the beginning of the entry.
3137 * @param obj The entry object
3142 elm_entry_cursor_begin_set(Evas_Object *obj)
3144 ELM_CHECK_WIDTYPE(obj, widtype);
3145 Widget_Data *wd = elm_widget_data_get(obj);
3147 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3151 * This moves the cursor to the end of the entry.
3153 * @param obj The entry object
3158 elm_entry_cursor_end_set(Evas_Object *obj)
3160 ELM_CHECK_WIDTYPE(obj, widtype);
3161 Widget_Data *wd = elm_widget_data_get(obj);
3163 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3167 * This moves the cursor to the beginning of the current line.
3169 * @param obj The entry object
3174 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3176 ELM_CHECK_WIDTYPE(obj, widtype);
3177 Widget_Data *wd = elm_widget_data_get(obj);
3179 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3183 * This moves the cursor to the end of the current line.
3185 * @param obj The entry object
3190 elm_entry_cursor_line_end_set(Evas_Object *obj)
3192 ELM_CHECK_WIDTYPE(obj, widtype);
3193 Widget_Data *wd = elm_widget_data_get(obj);
3195 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3199 * This begins a selection within the entry as though
3200 * the user were holding down the mouse button to make a selection.
3202 * @param obj The entry object
3207 elm_entry_cursor_selection_begin(Evas_Object *obj)
3209 ELM_CHECK_WIDTYPE(obj, widtype);
3210 Widget_Data *wd = elm_widget_data_get(obj);
3212 edje_object_part_text_select_begin(wd->ent, "elm.text");
3216 * This ends a selection within the entry as though
3217 * the user had just released the mouse button while making a selection.
3219 * @param obj The entry object
3224 elm_entry_cursor_selection_end(Evas_Object *obj)
3226 ELM_CHECK_WIDTYPE(obj, widtype);
3227 Widget_Data *wd = elm_widget_data_get(obj);
3229 edje_object_part_text_select_extend(wd->ent, "elm.text");
3233 * TODO: fill this in
3235 * @param obj The entry object
3236 * @return TODO: fill this in
3241 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3243 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3244 Widget_Data *wd = elm_widget_data_get(obj);
3245 if (!wd) return EINA_FALSE;
3246 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3250 * This returns whether the cursor is visible.
3252 * @param obj The entry object
3253 * @return If true, the cursor is visible.
3258 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3260 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3261 Widget_Data *wd = elm_widget_data_get(obj);
3262 if (!wd) return EINA_FALSE;
3263 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3267 * TODO: fill this in
3269 * @param obj The entry object
3270 * @return TODO: fill this in
3275 elm_entry_cursor_content_get(const Evas_Object *obj)
3277 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3278 Widget_Data *wd = elm_widget_data_get(obj);
3279 if (!wd) return NULL;
3280 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3284 * This executes a "cut" action on the selected text in the entry.
3286 * @param obj The entry object
3291 elm_entry_selection_cut(Evas_Object *obj)
3293 ELM_CHECK_WIDTYPE(obj, widtype);
3294 Widget_Data *wd = elm_widget_data_get(obj);
3296 _cut(obj, NULL, NULL);
3300 * This executes a "copy" action on the selected text in the entry.
3302 * @param obj The entry object
3307 elm_entry_selection_copy(Evas_Object *obj)
3309 ELM_CHECK_WIDTYPE(obj, widtype);
3310 Widget_Data *wd = elm_widget_data_get(obj);
3312 _copy(obj, NULL, NULL);
3316 * This executes a "paste" action in the entry.
3318 * @param obj The entry object
3323 elm_entry_selection_paste(Evas_Object *obj)
3325 ELM_CHECK_WIDTYPE(obj, widtype);
3326 Widget_Data *wd = elm_widget_data_get(obj);
3328 _paste(obj, NULL, NULL);
3332 * This clears and frees the items in a entry's contextual (right click) menu.
3334 * @param obj The entry object
3339 elm_entry_context_menu_clear(Evas_Object *obj)
3341 ELM_CHECK_WIDTYPE(obj, widtype);
3342 Widget_Data *wd = elm_widget_data_get(obj);
3343 Elm_Entry_Context_Menu_Item *it;
3345 EINA_LIST_FREE(wd->items, it)
3347 eina_stringshare_del(it->label);
3348 eina_stringshare_del(it->icon_file);
3349 eina_stringshare_del(it->icon_group);
3355 * This adds an item to the entry's contextual menu.
3357 * @param obj The entry object
3358 * @param label The item's text label
3359 * @param icon_file The item's icon file
3360 * @param icon_type The item's icon type
3361 * @param func The callback to execute when the item is clicked
3362 * @param data The data to associate with the item for related functions
3367 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)
3369 ELM_CHECK_WIDTYPE(obj, widtype);
3370 Widget_Data *wd = elm_widget_data_get(obj);
3371 Elm_Entry_Context_Menu_Item *it;
3373 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3375 wd->items = eina_list_append(wd->items, it);
3377 it->label = eina_stringshare_add(label);
3378 it->icon_file = eina_stringshare_add(icon_file);
3379 it->icon_type = icon_type;
3381 it->data = (void *)data;
3385 * This disables the entry's contextual (right click) menu.
3387 * @param obj The entry object
3388 * @param disabled If true, the menu is disabled
3393 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3395 ELM_CHECK_WIDTYPE(obj, widtype);
3396 Widget_Data *wd = elm_widget_data_get(obj);
3398 if (wd->context_menu == !disabled) return;
3399 wd->context_menu = !disabled;
3403 * This returns whether the entry's contextual (right click) menu is disabled.
3405 * @param obj The entry object
3406 * @return If true, the menu is disabled
3411 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3413 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3414 Widget_Data *wd = elm_widget_data_get(obj);
3415 if (!wd) return EINA_FALSE;
3416 return !wd->context_menu;
3420 * This appends a custom item provider to the list for that entry
3422 * This appends the given callback. The list is walked from beginning to end
3423 * with each function called given the item href string in the text. If the
3424 * function returns an object handle other than NULL (it should create an
3425 * and object to do this), then this object is used to replace that item. If
3426 * not the next provider is called until one provides an item object, or the
3427 * default provider in entry does.
3429 * @param obj The entry object
3430 * @param func The function called to provide the item object
3431 * @param data The data passed to @p func
3436 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3438 ELM_CHECK_WIDTYPE(obj, widtype);
3439 Widget_Data *wd = elm_widget_data_get(obj);
3441 EINA_SAFETY_ON_NULL_RETURN(func);
3442 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3446 wd->item_providers = eina_list_append(wd->item_providers, ip);
3450 * This prepends a custom item provider to the list for that entry
3452 * This prepends the given callback. See elm_entry_item_provider_append() for
3455 * @param obj The entry object
3456 * @param func The function called to provide the item object
3457 * @param data The data passed to @p func
3462 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3464 ELM_CHECK_WIDTYPE(obj, widtype);
3465 Widget_Data *wd = elm_widget_data_get(obj);
3467 EINA_SAFETY_ON_NULL_RETURN(func);
3468 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3472 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3476 * This removes a custom item provider to the list for that entry
3478 * This removes the given callback. See elm_entry_item_provider_append() for
3481 * @param obj The entry object
3482 * @param func The function called to provide the item object
3483 * @param data The data passed to @p func
3488 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3490 ELM_CHECK_WIDTYPE(obj, widtype);
3491 Widget_Data *wd = elm_widget_data_get(obj);
3493 Elm_Entry_Item_Provider *ip;
3495 EINA_SAFETY_ON_NULL_RETURN(func);
3496 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3498 if ((ip->func == func) && (ip->data == data))
3500 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3508 * Append a filter function for text inserted in the entry
3510 * Append the given callback to the list. This functions will be called
3511 * whenever any text is inserted into the entry, with the text to be inserted
3512 * as a parameter. The callback function is free to alter the text in any way
3513 * it wants, but it must remember to free the given pointer and update it.
3514 * If the new text is to be discarded, the function can free it and set it text
3515 * parameter to NULL. This will also prevent any following filters from being
3518 * @param obj The entry object
3519 * @param func The function to use as text filter
3520 * @param data User data to pass to @p func
3525 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3528 Elm_Entry_Text_Filter *tf;
3529 ELM_CHECK_WIDTYPE(obj, widtype);
3531 wd = elm_widget_data_get(obj);
3533 EINA_SAFETY_ON_NULL_RETURN(func);
3535 tf = ELM_NEW(Elm_Entry_Text_Filter);
3539 wd->text_filters = eina_list_append(wd->text_filters, tf);
3543 * Prepend a filter function for text insdrted in the entry
3545 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3546 * for more information
3548 * @param obj The entry object
3549 * @param func The function to use as text filter
3550 * @param data User data to pass to @p func
3555 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3558 Elm_Entry_Text_Filter *tf;
3559 ELM_CHECK_WIDTYPE(obj, widtype);
3561 wd = elm_widget_data_get(obj);
3563 EINA_SAFETY_ON_NULL_RETURN(func);
3565 tf = ELM_NEW(Elm_Entry_Text_Filter);
3569 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3573 * Remove a filter from the list
3575 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3576 * for more information.
3578 * @param obj The entry object
3579 * @param func The filter function to remove
3580 * @param data The user data passed when adding the function
3585 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3589 Elm_Entry_Text_Filter *tf;
3590 ELM_CHECK_WIDTYPE(obj, widtype);
3592 wd = elm_widget_data_get(obj);
3594 EINA_SAFETY_ON_NULL_RETURN(func);
3596 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3598 if ((tf->func == func) && (tf->data == data))
3600 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3608 * This converts a markup (HTML-like) string into UTF-8.
3610 * @param s The string (in markup) to be converted
3611 * @return The converted string (in UTF-8)
3616 elm_entry_markup_to_utf8(const char *s)
3618 char *ss = _elm_util_mkup_to_text(s);
3619 if (!ss) ss = strdup("");
3624 * This converts a UTF-8 string into markup (HTML-like).
3626 * @param s The string (in UTF-8) to be converted
3627 * @return The converted string (in markup)
3632 elm_entry_utf8_to_markup(const char *s)
3634 char *ss = _elm_util_text_to_mkup(s);
3635 if (!ss) ss = strdup("");
3640 * Get the input method context in the entry widget
3642 * @param obj The entry object
3643 * @return The input method context
3647 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3649 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3650 Widget_Data *wd = elm_widget_data_get(obj);
3651 if (!wd || !wd->ent) return NULL;
3653 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3657 * Set whether entry should enable the return key on soft keyboard automatically
3659 * @param obj The entry object
3660 * @param on If true, entry enables the return key on soft keyboard automatically.
3665 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3667 ELM_CHECK_WIDTYPE(obj, widtype);
3668 Widget_Data *wd = elm_widget_data_get(obj);
3671 wd->autoreturnkey = on;
3672 _check_enable_returnkey(obj);
3676 * Set whether entry should support auto capitalization
3678 * @param obj The entry object
3679 * @param on If true, entry suports auto capitalization.
3684 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3686 ELM_CHECK_WIDTYPE(obj, widtype);
3687 Widget_Data *wd = elm_widget_data_get(obj);
3691 wd->autocapital = EINA_FALSE;
3693 wd->autocapital = autocap;
3695 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3696 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3697 wd->autocapital = EINA_FALSE;
3699 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3703 * Set whether entry should support auto period
3705 * @param obj The entry object
3706 * @param on If true, entry suports auto period.
3711 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3713 ELM_CHECK_WIDTYPE(obj, widtype);
3714 Widget_Data *wd = elm_widget_data_get(obj);
3718 wd->autoperiod = EINA_FALSE;
3720 wd->autoperiod = autoperiod;
3722 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3723 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3724 wd->autoperiod = EINA_FALSE;
3726 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3730 * Set the font size on the entry object
3732 * @param obj The entry object
3733 * @param size font size
3738 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3740 ELM_CHECK_WIDTYPE(obj, widtype);
3741 Widget_Data *wd = elm_widget_data_get(obj);
3742 Eina_Strbuf *fontbuf = NULL;
3747 t = eina_stringshare_add(elm_entry_entry_get(obj));
3748 fontbuf = eina_strbuf_new();
3749 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3751 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3753 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3755 elm_entry_entry_set(obj, t);
3759 eina_strbuf_free(fontbuf);
3760 eina_stringshare_del(t);
3764 * Set the text align on the entry object
3766 * @param obj The entry object
3767 * @param align align mode
3772 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3774 ELM_CHECK_WIDTYPE(obj, widtype);
3775 Widget_Data *wd = elm_widget_data_get(obj);
3780 t = eina_stringshare_add(elm_entry_entry_get(obj));
3782 if (len <= 0) return;
3784 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3785 elm_entry_entry_set(obj, t);
3789 eina_stringshare_del(t);
3793 * Set the text color on the entry object
3795 * @param obj The entry object
3796 * @param r Red property background color of The entry object
3797 * @param g Green property background color of The entry object
3798 * @param b Blue property background color of The entry object
3799 * @param a Alpha property background alpha of The entry object
3804 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3806 ELM_CHECK_WIDTYPE(obj, widtype);
3807 Widget_Data *wd = elm_widget_data_get(obj);
3808 Eina_Strbuf *colorbuf = NULL;
3813 t = eina_stringshare_add(elm_entry_entry_get(obj));
3815 if (len <= 0) return;
3816 colorbuf = eina_strbuf_new();
3817 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3819 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3821 elm_entry_entry_set(obj, t);
3825 eina_strbuf_free(colorbuf);
3826 eina_stringshare_del(t);
3830 * Set background color of the entry
3832 * @param obj The entry object
3833 * @param r Red property background color of The entry object
3834 * @param g Green property background color of The entry object
3835 * @param b Blue property background color of The entry object
3836 * @param a Alpha property background alpha of The entry object
3840 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3842 ELM_CHECK_WIDTYPE(obj, widtype);
3843 Widget_Data *wd = elm_widget_data_get(obj);
3844 evas_object_color_set(wd->bg, r, g, b, a);
3846 if (wd->bgcolor == EINA_FALSE)
3849 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3854 * Set the ellipsis behavior of the entry
3856 * @param obj The entry object
3857 * @param ellipsis To ellipsis text or not
3861 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3863 ELM_CHECK_WIDTYPE(obj, widtype);
3864 Widget_Data *wd = elm_widget_data_get(obj);
3865 if (wd->ellipsis == ellipsis) return;
3866 wd->ellipsis = ellipsis;
3872 * Filter inserted text based on user defined character and byte limits
3874 * Add this filter to an entry to limit the characters that it will accept
3875 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3876 * The funtion works on the UTF-8 representation of the string, converting
3877 * it from the set markup, thus not accounting for any format in it.
3879 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3880 * it as data when setting the filter. In it it's possible to set limits
3881 * by character count or bytes (any of them is disabled if 0), and both can
3882 * be set at the same time. In that case, it first checks for characters,
3885 * The function will cut the inserted text in order to allow only the first
3886 * number of characters that are still allowed. The cut is made in
3887 * characters, even when limiting by bytes, in order to always contain
3888 * valid ones and avoid half unicode characters making it in.
3893 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3895 Elm_Entry_Filter_Limit_Size *lim = data;
3898 const char *(*text_get)(const Evas_Object *);
3899 const char *widget_type;
3901 EINA_SAFETY_ON_NULL_RETURN(data);
3902 EINA_SAFETY_ON_NULL_RETURN(entry);
3903 EINA_SAFETY_ON_NULL_RETURN(text);
3905 /* hack. I don't want to copy the entire function to work with
3907 widget_type = elm_widget_type_get(entry);
3908 if (!strcmp(widget_type, "entry"))
3909 text_get = elm_entry_entry_get;
3910 else if (!strcmp(widget_type, "scrolled_entry"))
3911 text_get = elm_scrolled_entry_entry_get;
3915 current = elm_entry_markup_to_utf8(text_get(entry));
3917 if (lim->max_char_count > 0)
3920 len = evas_string_char_len_get(current);
3921 if (len >= lim->max_char_count)
3923 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3929 newlen = evas_string_char_len_get(*text);
3930 cut = strlen(*text);
3931 while ((len + newlen) > lim->max_char_count)
3933 cut = evas_string_char_prev_get(*text, cut, NULL);
3939 if (lim->max_byte_count > 0)
3941 len = strlen(current);
3942 if (len >= lim->max_byte_count)
3944 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3950 newlen = strlen(*text);
3951 while ((len + newlen) > lim->max_byte_count)
3953 int p = evas_string_char_prev_get(*text, newlen, NULL);
3954 newlen -= (newlen - p);
3957 (*text)[newlen] = 0;
3968 * Filter inserted text based on accepted or rejected sets of characters
3970 * Add this filter to an entry to restrict the set of accepted characters
3971 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3972 * This structure contains both accepted and rejected sets, but they are
3973 * mutually exclusive. If accepted is set, it will be used, otherwise it
3974 * goes on to the rejected set.
3977 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3979 Elm_Entry_Filter_Accept_Set *as = data;
3983 int read_idx, last_read_idx = 0, read_char;
3985 EINA_SAFETY_ON_NULL_RETURN(data);
3986 EINA_SAFETY_ON_NULL_RETURN(text);
3988 if ((!as->accepted) && (!as->rejected))
3994 goes_in = EINA_TRUE;
3999 goes_in = EINA_FALSE;
4003 read_idx = evas_string_char_next_get(*text, 0, &read_char);
4006 int cmp_idx, cmp_char;
4007 Eina_Bool in_set = EINA_FALSE;
4009 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4012 if (read_char == cmp_char)
4017 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4019 if (in_set == goes_in)
4021 int size = read_idx - last_read_idx;
4022 const char *src = (*text) + last_read_idx;
4024 memcpy(insert, *text + last_read_idx, size);
4027 last_read_idx = read_idx;
4028 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4034 * This sets the file (and implicitly loads it) for the text to display and
4035 * then edit. All changes are written back to the file after a short delay if
4036 * the entry object is set to autosave.
4038 * @param obj The entry object
4039 * @param file The path to the file to load and save
4040 * @param format The file format
4045 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4047 ELM_CHECK_WIDTYPE(obj, widtype);
4048 Widget_Data *wd = elm_widget_data_get(obj);
4050 if (wd->delay_write)
4052 ecore_timer_del(wd->delay_write);
4053 wd->delay_write = NULL;
4055 if (wd->autosave) _save(obj);
4056 eina_stringshare_replace(&wd->file, file);
4057 wd->format = format;
4062 * Gets the file to load and save and the file format
4064 * @param obj The entry object
4065 * @param file The path to the file to load and save
4066 * @param format The file format
4071 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4073 ELM_CHECK_WIDTYPE(obj, widtype);
4074 Widget_Data *wd = elm_widget_data_get(obj);
4076 if (file) *file = wd->file;
4077 if (format) *format = wd->format;
4081 * This function writes any changes made to the file set with
4082 * elm_entry_file_set()
4084 * @param obj The entry object
4089 elm_entry_file_save(Evas_Object *obj)
4091 ELM_CHECK_WIDTYPE(obj, widtype);
4092 Widget_Data *wd = elm_widget_data_get(obj);
4094 if (wd->delay_write)
4096 ecore_timer_del(wd->delay_write);
4097 wd->delay_write = NULL;
4100 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4104 * This sets the entry object to 'autosave' the loaded text file or not.
4106 * @param obj The entry object
4107 * @param autosave Autosave the loaded file or not
4112 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4114 ELM_CHECK_WIDTYPE(obj, widtype);
4115 Widget_Data *wd = elm_widget_data_get(obj);
4117 wd->autosave = !!autosave;
4121 * This gets the entry object's 'autosave' status.
4123 * @param obj The entry object
4124 * @return Autosave the loaded file or not
4129 elm_entry_autosave_get(const Evas_Object *obj)
4131 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4132 Widget_Data *wd = elm_widget_data_get(obj);
4133 if (!wd) return EINA_FALSE;
4134 return wd->autosave;
4138 * Control pasting of text and images for the widget.
4140 * Normally the entry allows both text and images to be pasted. By setting
4141 * textonly to be true, this prevents images from being pasted.
4143 * Note this only changes the behaviour of text.
4145 * @param obj The entry object
4146 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
4151 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4153 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4154 ELM_CHECK_WIDTYPE(obj, widtype);
4155 Widget_Data *wd = elm_widget_data_get(obj);
4157 textonly = !!textonly;
4158 if (wd->textonly == textonly) return;
4159 wd->textonly = !!textonly;
4163 * Getting elm_entry text paste/drop mode.
4165 * In textonly mode, only text may be pasted or dropped into the widget.
4167 * @param obj The entry object
4168 * @return If the widget only accepts text from pastes.
4173 elm_entry_cnp_textonly_get(Evas_Object *obj)
4175 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4176 Widget_Data *wd = elm_widget_data_get(obj);
4177 if (!wd) return EINA_FALSE;
4178 return wd->textonly;
4182 * This sets the attribute to show the input panel automatically.
4184 * @param obj The entry object
4185 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4190 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4192 ELM_CHECK_WIDTYPE(obj, widtype);
4193 Widget_Data *wd = elm_widget_data_get(obj);
4196 wd->input_panel_enable = enabled;
4197 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4201 * Set the input panel layout of the entry
4203 * @param obj The entry object
4204 * @param layout the layout to set
4209 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4211 ELM_CHECK_WIDTYPE(obj, widtype);
4212 Widget_Data *wd = elm_widget_data_get(obj);
4215 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4218 wd->input_panel_layout = layout;
4220 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4224 * Set the magnifier style of the entry
4226 * @param obj The entry object
4227 * @param type the magnifier style to set
4232 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4234 ELM_CHECK_WIDTYPE(obj, widtype);
4235 Widget_Data *wd = elm_widget_data_get(obj);
4238 wd->mgf_type = type;
4239 _magnifier_create(obj);