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:
78 * "changed" - The text within the entry was changed
79 * "activated" - The entry has had editing finished and changes are to be committed
80 (generally when enter key is pressed)
81 * "press" - The entry has been clicked
82 * "longpressed" - The entry has been clicked for a couple seconds
83 * "clicked" - The entry has been clicked
84 * "clicked,double" - The entry has been double clicked
85 * "focused" - The entry has received focus
86 * "unfocused" - The entry has lost focus
87 * "selection,paste" - A paste action has occurred
88 * "selection,copy" - A copy action has occurred
89 * "selection,cut" - A cut action has occurred
90 * "selection,start" - A selection has begun
91 * "selection,changed" - The selection has changed
92 * "selection,cleared" - The selection has been cleared
93 * "cursor,changed" - The cursor has changed
94 * "anchor,clicked" - The anchor has been clicked
95 * "preedit,changed" - The preedit string has changed
98 /* Maximum chunk size to be inserted to the entry at once
99 * FIXME: This size is arbitrary, should probably choose a better size.
100 * Possibly also find a way to set it to a low value for weak computers,
101 * and to a big value for better computers. */
102 #define _CHUNK_SIZE 10000
104 typedef struct _Mod_Api Mod_Api;
106 typedef struct _Widget_Data Widget_Data;
107 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
108 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
109 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
113 Evas_Object *ent, *scroller, *end, *icon;
115 Evas_Object *hoversel;
119 Evas_Object *mgf_proxy;
120 Evas_Object *mgf_clip;
122 Evas_Coord mgf_height;
125 Ecore_Job *deferred_recalc_job;
126 Ecore_Event_Handler *sel_notify_handler;
127 Ecore_Event_Handler *sel_clear_handler;
128 Ecore_Timer *longpress_timer;
129 Ecore_Timer *delay_write;
130 /* for deferred appending */
131 Ecore_Idler *append_text_idler;
132 char *append_text_left;
133 int append_text_position;
135 /* Only for clipboard */
138 const char *password_text;
141 Elm_Text_Format format;
142 Evas_Coord lastw, entmw, entmh;
143 Evas_Coord downx, downy;
144 Evas_Coord cx, cy, cw, ch;
146 Eina_List *item_providers;
147 Eina_List *text_filters;
148 Eina_List *match_list;
149 Ecore_Job *matchlist_job;
150 int matchlist_threshold;
151 Ecore_Job *hovdeljob;
152 Mod_Api *api; // module api if supplied
154 Elm_Scroller_Policy policy_h, policy_v;
155 Elm_Wrap_Type linewrap;
156 Elm_Input_Panel_Layout input_panel_layout;
157 Eina_Bool changed : 1;
158 Eina_Bool single_line : 1;
159 Eina_Bool password : 1;
160 Eina_Bool editable : 1;
161 Eina_Bool selection_asked : 1;
162 Eina_Bool have_selection : 1;
163 Eina_Bool selmode : 1;
164 Eina_Bool deferred_cur : 1;
165 Eina_Bool cur_changed : 1;
166 Eina_Bool disabled : 1;
167 Eina_Bool double_clicked : 1;
168 Eina_Bool long_pressed : 1;
169 Eina_Bool context_menu : 1;
170 Eina_Bool drag_selection_asked : 1;
171 Eina_Bool bgcolor : 1;
172 Eina_Bool can_write : 1;
173 Eina_Bool autosave : 1;
174 Eina_Bool textonly : 1;
175 Eina_Bool usedown : 1;
176 Eina_Bool scroll : 1;
177 Eina_Bool autoreturnkey : 1;
178 Eina_Bool input_panel_enable : 1;
179 Eina_Bool autocapital : 1;
180 Eina_Bool autoperiod : 1;
181 Eina_Bool matchlist_list_clicked : 1;
182 Eina_Bool matchlist_case_sensitive : 1;
185 struct _Elm_Entry_Context_Menu_Item
189 const char *icon_file;
190 const char *icon_group;
191 Elm_Icon_Type icon_type;
196 struct _Elm_Entry_Item_Provider
198 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
202 struct _Elm_Entry_Text_Filter
204 void (*func) (void *data, Evas_Object *entry, char **text);
208 typedef enum _Length_Unit
215 static const char *widtype = NULL;
217 static Evas_Object *cnpwidgetdata = NULL;
220 #ifdef HAVE_ELEMENTARY_X
221 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
223 static void _del_hook(Evas_Object *obj);
224 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
225 static void _theme_hook(Evas_Object *obj);
226 static void _disable_hook(Evas_Object *obj);
227 static void _sizing_eval(Evas_Object *obj);
228 static void _on_focus_hook(void *data, Evas_Object *obj);
229 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
230 static const char *_getbase(Evas_Object *obj);
231 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
232 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
233 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
234 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
235 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
236 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
237 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
238 static void _signal_handler_moving(void *data, Evas_Object *obj, const char *emission, const char *source);
239 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
240 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
241 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
242 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
243 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
244 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
245 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
246 static int _entry_length_get(Evas_Object *obj);
247 static void _magnifier_create(void *data);
248 static void _magnifier_show(void *data);
249 static void _magnifier_hide(void *data);
250 static void _magnifier_move(void *data);
252 static const char SIG_CHANGED[] = "changed";
253 static const char SIG_ACTIVATED[] = "activated";
254 static const char SIG_PRESS[] = "press";
255 static const char SIG_LONGPRESSED[] = "longpressed";
256 static const char SIG_CLICKED[] = "clicked";
257 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
258 static const char SIG_FOCUSED[] = "focused";
259 static const char SIG_UNFOCUSED[] = "unfocused";
260 static const char SIG_SELECTION_PASTE[] = "selection,paste";
261 static const char SIG_SELECTION_COPY[] = "selection,copy";
262 static const char SIG_SELECTION_CUT[] = "selection,cut";
263 static const char SIG_SELECTION_START[] = "selection,start";
264 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
265 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
266 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
267 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
268 static const char SIG_MATCHLIST_CLICKED[] = "matchlist,clicked";
269 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
270 static const Evas_Smart_Cb_Description _signals[] = {
274 {SIG_LONGPRESSED, ""},
276 {SIG_CLICKED_DOUBLE, ""},
279 {SIG_SELECTION_PASTE, ""},
280 {SIG_SELECTION_COPY, ""},
281 {SIG_SELECTION_CUT, ""},
282 {SIG_SELECTION_START, ""},
283 {SIG_SELECTION_CHANGED, ""},
284 {SIG_SELECTION_CLEARED, ""},
285 {SIG_CURSOR_CHANGED, ""},
286 {SIG_ANCHOR_CLICKED, ""},
287 {SIG_PREEDIT_CHANGED, ""},
288 {SIG_MATCHLIST_CLICKED, ""},
292 typedef enum _Elm_Entry_Magnifier_Type
294 _ENTRY_MAGNIFIER_FIXEDSIZE = 0,
295 _ENTRY_MAGNIFIER_FILLWIDTH,
296 _ENTRY_MAGNIFIER_CIRCULAR,
297 } Elm_Entry_Magnifier_Type;
300 static Eina_List *entries = NULL;
304 void (*obj_hook) (Evas_Object *obj);
305 void (*obj_unhook) (Evas_Object *obj);
306 void (*obj_longpress) (Evas_Object *obj);
307 void (*obj_hidemenu) (Evas_Object *obj);
308 void (*obj_mouseup) (Evas_Object *obj);
312 _module(Evas_Object *obj __UNUSED__)
314 static Elm_Module *m = NULL;
315 if (m) goto ok; // already found - just use
316 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
318 m->api = malloc(sizeof(Mod_Api));
319 if (!m->api) return NULL;
320 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
321 _elm_module_symbol_get(m, "obj_hook");
322 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
323 _elm_module_symbol_get(m, "obj_unhook");
324 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
325 _elm_module_symbol_get(m, "obj_longpress");
326 ((Mod_Api *)(m->api) )->obj_hidemenu = // called on hide menu
327 _elm_module_symbol_get(m, "obj_hidemenu");
328 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
329 _elm_module_symbol_get(m, "obj_mouseup");
330 ok: // ok - return api
335 _buf_append(char *buf, const char *str, int *len, int *alloc)
337 int len2 = strlen(str);
338 if ((*len + len2) >= *alloc)
340 char *buf2 = realloc(buf, *alloc + len2 + 512);
341 if (!buf2) return NULL;
343 *alloc += (512 + len2);
345 strcpy(buf + *len, str);
351 _load_file(const char *file)
355 int alloc = 0, len = 0;
356 char *text = NULL, buf[16384 + 1];
358 f = fopen(file, "rb");
360 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
364 tmp_text = _buf_append(text, buf, &len, &alloc);
365 if (!tmp_text) break;
373 _load_plain(const char *file)
377 text = _load_file(file);
382 text2 = elm_entry_utf8_to_markup(text);
390 _load(Evas_Object *obj)
392 Widget_Data *wd = elm_widget_data_get(obj);
397 elm_entry_entry_set(obj, "");
402 case ELM_TEXT_FORMAT_PLAIN_UTF8:
403 text = _load_plain(wd->file);
405 case ELM_TEXT_FORMAT_MARKUP_UTF8:
406 text = _load_file(wd->file);
414 elm_entry_entry_set(obj, text);
418 elm_entry_entry_set(obj, "");
422 _save_markup_utf8(const char *file, const char *text)
426 if ((!text) || (!text[0]))
428 ecore_file_unlink(file);
431 f = fopen(file, "wb");
434 // FIXME: report a write error
437 fputs(text, f); // FIXME: catch error
442 _save_plain_utf8(const char *file, const char *text)
446 text2 = elm_entry_markup_to_utf8(text);
449 _save_markup_utf8(file, text2);
454 _save(Evas_Object *obj)
456 Widget_Data *wd = elm_widget_data_get(obj);
458 if (!wd->file) return;
461 case ELM_TEXT_FORMAT_PLAIN_UTF8:
462 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
464 case ELM_TEXT_FORMAT_MARKUP_UTF8:
465 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
473 _delay_write(void *data)
475 Widget_Data *wd = elm_widget_data_get(data);
476 if (!wd) return ECORE_CALLBACK_CANCEL;
478 wd->delay_write = NULL;
479 return ECORE_CALLBACK_CANCEL;
482 static Elm_Entry_Text_Filter *
483 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
485 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
486 if (!tf) return NULL;
489 if (func == elm_entry_filter_limit_size)
491 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
498 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
504 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
507 else if (func == elm_entry_filter_accept_set)
509 Elm_Entry_Filter_Accept_Set *as = data, *as2;
516 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
523 as2->accepted = eina_stringshare_add(as->accepted);
525 as2->accepted = NULL;
527 as2->rejected = eina_stringshare_add(as->rejected);
529 as2->rejected = NULL;
538 _filter_free(Elm_Entry_Text_Filter *tf)
540 if (tf->func == elm_entry_filter_limit_size)
542 Elm_Entry_Filter_Limit_Size *lim = tf->data;
545 else if (tf->func == elm_entry_filter_accept_set)
547 Elm_Entry_Filter_Accept_Set *as = tf->data;
550 if (as->accepted) eina_stringshare_del(as->accepted);
551 if (as->rejected) eina_stringshare_del(as->rejected);
559 _del_pre_hook(Evas_Object *obj)
561 Widget_Data *wd = elm_widget_data_get(obj);
565 ecore_timer_del(wd->delay_write);
566 wd->delay_write = NULL;
567 if (wd->autosave) _save(obj);
572 _del_hook(Evas_Object *obj)
574 Widget_Data *wd = elm_widget_data_get(obj);
575 Elm_Entry_Context_Menu_Item *it;
576 Elm_Entry_Item_Provider *ip;
577 Elm_Entry_Text_Filter *tf;
579 if (wd->file) eina_stringshare_del(wd->file);
581 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
582 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
584 entries = eina_list_remove(entries, obj);
585 #ifdef HAVE_ELEMENTARY_X
586 if (wd->sel_notify_handler)
587 ecore_event_handler_del(wd->sel_notify_handler);
588 if (wd->sel_clear_handler)
589 ecore_event_handler_del(wd->sel_clear_handler);
591 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
592 if (wd->text) eina_stringshare_del(wd->text);
593 if (wd->password_text) eina_stringshare_del(wd->password_text);
594 if (wd->bg) evas_object_del(wd->bg);
595 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
596 if (wd->append_text_idler)
598 ecore_idler_del(wd->append_text_idler);
599 free(wd->append_text_left);
600 wd->append_text_left = NULL;
601 wd->append_text_idler = NULL;
603 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
604 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
605 if (wd->mgf_proxy) evas_object_del(wd->mgf_proxy);
606 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
607 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
609 EINA_LIST_FREE(wd->items, it)
611 eina_stringshare_del(it->label);
612 eina_stringshare_del(it->icon_file);
613 eina_stringshare_del(it->icon_group);
616 EINA_LIST_FREE(wd->item_providers, ip)
620 EINA_LIST_FREE(wd->text_filters, tf)
628 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
630 Widget_Data *wd = elm_widget_data_get(obj);
631 edje_object_mirrored_set(wd->ent, rtl);
635 _theme_hook(Evas_Object *obj)
637 Widget_Data *wd = elm_widget_data_get(obj);
639 Ecore_IMF_Context *ic;
640 _elm_widget_mirrored_reload(obj);
641 _mirrored_set(obj, elm_widget_mirrored_get(obj));
643 t = eina_stringshare_add(elm_entry_entry_get(obj));
644 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
645 if (_elm_config->desktop_entry)
646 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
647 elm_entry_entry_set(obj, t);
648 eina_stringshare_del(t);
649 if (elm_widget_disabled_get(obj))
650 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
651 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
652 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
653 if (elm_widget_focus_get(obj))
654 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
655 edje_object_message_signal_process(wd->ent);
656 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
657 elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
658 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
659 elm_widget_style_get(obj));
665 edj = elm_smart_scroller_edje_object_get(wd->scroller);
666 str = edje_object_data_get(edj, "focus_highlight");
667 if ((str) && (!strcmp(str, "on")))
668 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
670 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
675 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", EINA_FALSE);
676 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", EINA_FALSE);
680 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
681 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
684 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
687 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
694 _disable_hook(Evas_Object *obj)
696 Widget_Data *wd = elm_widget_data_get(obj);
698 if (elm_widget_disabled_get(obj))
700 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
701 wd->disabled = EINA_TRUE;
705 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
706 wd->disabled = EINA_FALSE;
711 _recalc_cursor_geometry(Evas_Object *obj)
713 Widget_Data *wd = elm_widget_data_get(obj);
715 evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
716 if (!elm_object_focus_get(obj)) return;
717 if (!wd->deferred_recalc_job)
719 Evas_Coord cx, cy, cw, ch;
720 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
724 elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
725 wd->cur_changed = EINA_FALSE;
729 wd->deferred_cur = EINA_TRUE;
733 _elm_win_recalc_job(void *data)
735 Widget_Data *wd = elm_widget_data_get(data);
736 Evas_Coord minh = -1, resw = -1, minw = -1, fw = 0, fh = 0;
738 wd->deferred_recalc_job = NULL;
740 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
741 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
742 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
745 /* This is a hack to workaround the way min size hints are treated.
746 * If the minimum width is smaller than the restricted width, it means
747 * the mininmum doesn't matter. */
750 Evas_Coord ominw = -1;
751 evas_object_size_hint_min_get(data, &ominw, NULL);
755 elm_coords_finger_size_adjust(1, &fw, 1, &fh);
758 Evas_Coord vmw = 0, vmh = 0;
760 edje_object_size_min_calc
761 (elm_smart_scroller_edje_object_get(wd->scroller),
765 evas_object_size_hint_min_set(data, vmw, minh + vmh);
766 evas_object_size_hint_max_set(data, -1, minh + vmh);
770 evas_object_size_hint_min_set(data, vmw, vmh);
771 evas_object_size_hint_max_set(data, -1, -1);
778 evas_object_size_hint_min_set(data, minw, minh);
779 evas_object_size_hint_max_set(data, -1, minh);
783 evas_object_size_hint_min_set(data, fw, minh);
784 evas_object_size_hint_max_set(data, -1, -1);
788 if ((wd->deferred_cur) && (elm_object_focus_get(data)))
790 Evas_Coord cx, cy, cw, ch;
791 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
795 elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
796 wd->cur_changed = EINA_FALSE;
802 _sizing_eval(Evas_Object *obj)
804 Widget_Data *wd = elm_widget_data_get(obj);
805 Evas_Coord minw = -1, minh = -1;
806 Evas_Coord resw, resh;
809 evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
812 if ((resw == wd->lastw) && (!wd->changed)) return;
813 wd->changed = EINA_FALSE;
817 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
819 evas_object_resize(wd->scroller, resw, resh);
820 edje_object_size_min_calc
821 (elm_smart_scroller_edje_object_get(wd->scroller),
823 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
824 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
827 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
829 if ((minw > 0) && (vw < minw)) vw = minw;
830 if (minh > vh) vh = minh;
832 if (wd->single_line) h = vmh + minh;
834 evas_object_resize(wd->ent, vw, vh);
835 evas_object_size_hint_min_get(obj, &w, NULL);
836 evas_object_size_hint_min_set(obj, w, h);
838 evas_object_size_hint_max_set(obj, -1, h);
840 evas_object_size_hint_max_set(obj, -1, -1);
844 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
845 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
850 if (!wd->changed) return;
851 wd->changed = EINA_FALSE;
855 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
857 edje_object_size_min_calc(wd->ent, &minw, &minh);
860 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
862 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
864 if ((minw > 0) && (vw < minw)) vw = minw;
865 if (minh > 0) vh = minh;
867 evas_object_resize(wd->ent, vw, vh);
868 edje_object_size_min_calc
869 (elm_smart_scroller_edje_object_get(wd->scroller),
871 if (wd->single_line) h = vmh + minh;
873 evas_object_size_hint_min_get(obj, &w, NULL);
874 evas_object_size_hint_min_set(obj, w, h);
876 evas_object_size_hint_max_set(obj, -1, h);
878 evas_object_size_hint_max_set(obj, -1, -1);
882 edje_object_size_min_calc(wd->ent, &minw, &minh);
885 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
886 evas_object_size_hint_min_set(obj, minw, minh);
888 evas_object_size_hint_max_set(obj, -1, minh);
890 evas_object_size_hint_max_set(obj, -1, -1);
894 _recalc_cursor_geometry(obj);
898 _check_enable_returnkey(Evas_Object *obj)
900 Widget_Data *wd = elm_widget_data_get(obj);
903 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
906 if (!wd->autoreturnkey) return;
908 if (_entry_length_get(obj) == 0)
910 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
914 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
919 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
921 Widget_Data *wd = elm_widget_data_get(obj);
922 Evas_Object *top = elm_widget_top_get(obj);
924 if (!wd->editable) return;
925 if (elm_widget_focus_get(obj))
927 printf("[Elm_entry::Focused] obj : %p\n", obj);
928 evas_object_focus_set(wd->ent, EINA_TRUE);
929 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
930 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
931 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
932 _check_enable_returnkey(obj);
933 wd->mgf_type = _ENTRY_MAGNIFIER_FIXEDSIZE;
937 printf("[Elm_entry::Unfocused] obj : %p\n", obj);
938 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
939 evas_object_focus_set(wd->ent, EINA_FALSE);
940 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
941 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
943 if ((wd->api) && (wd->api->obj_hidemenu))
945 wd->api->obj_hidemenu(obj);
951 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
953 Widget_Data *wd = elm_widget_data_get(obj);
955 edje_object_signal_emit(wd->ent, emission, source);
957 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
962 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
964 Widget_Data *wd = elm_widget_data_get(obj);
966 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
968 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
969 emission, source, func_cb, data);
973 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
975 Widget_Data *wd = elm_widget_data_get(obj);
976 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
979 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
980 emission, source, func_cb, data);
984 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
986 Widget_Data *wd = elm_widget_data_get(obj);
987 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
991 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
993 Widget_Data *wd = elm_widget_data_get(obj);
995 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
999 _show_region_hook(void *data, Evas_Object *obj)
1001 Widget_Data *wd = elm_widget_data_get(data);
1002 Evas_Coord x, y, w, h;
1004 elm_widget_show_region_get(obj, &x, &y, &w, &h);
1006 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
1010 _hoversel_position(Evas_Object *obj)
1012 Widget_Data *wd = elm_widget_data_get(obj);
1013 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
1018 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1027 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1028 &cx, &cy, &cw, &ch);
1029 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
1032 cx += (cw - mw) / 2;
1037 cy += (ch - mh) / 2;
1040 evas_object_move(wd->hoversel, x + cx, y + cy);
1041 evas_object_resize(wd->hoversel, cw, ch);
1045 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1047 Widget_Data *wd = elm_widget_data_get(data);
1049 if (wd->hoversel) _hoversel_position(data);
1053 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1055 Widget_Data *wd = elm_widget_data_get(data);
1062 else if (wd->scroll)
1064 Evas_Coord vw = 0, vh = 0;
1066 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
1067 if (vw < wd->entmw) vw = wd->entmw;
1068 if (vh < wd->entmh) vh = wd->entmh;
1069 evas_object_resize(wd->ent, vw, vh);
1071 if (wd->hoversel) _hoversel_position(data);
1075 _hover_del(void *data)
1077 Widget_Data *wd = elm_widget_data_get(data);
1082 evas_object_del(wd->hoversel);
1083 wd->hoversel = NULL;
1085 wd->hovdeljob = NULL;
1089 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1091 Widget_Data *wd = elm_widget_data_get(data);
1094 if (wd->hoversel) evas_object_hide(wd->hoversel);
1097 if (!_elm_config->desktop_entry)
1100 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1103 elm_widget_scroll_freeze_pop(data);
1104 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
1105 wd->hovdeljob = ecore_job_add(_hover_del, data);
1109 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1111 Widget_Data *wd = elm_widget_data_get(data);
1113 wd->selmode = EINA_TRUE;
1114 edje_object_part_text_select_none(wd->ent, "elm.text");
1115 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1116 edje_object_part_text_select_all(wd->ent, "elm.text");
1117 elm_object_scroll_freeze_pop(data);
1121 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1123 Widget_Data *wd = elm_widget_data_get(data);
1125 wd->selmode = EINA_TRUE;
1126 edje_object_part_text_select_none(wd->ent, "elm.text");
1127 if (!_elm_config->desktop_entry)
1130 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1132 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1133 if (!_elm_config->desktop_entry)
1134 elm_object_scroll_freeze_pop(data);
1135 //elm_widget_scroll_hold_push(data);
1139 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1141 Widget_Data *wd = elm_widget_data_get(data);
1143 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1144 if (wd->sel_notify_handler)
1146 #ifdef HAVE_ELEMENTARY_X
1147 Elm_Sel_Format formats;
1148 wd->selection_asked = EINA_TRUE;
1149 formats = ELM_SEL_FORMAT_MARKUP;
1151 formats |= ELM_SEL_FORMAT_IMAGE;
1152 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
1158 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1160 Widget_Data *wd = elm_widget_data_get(obj);
1164 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1165 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
1166 if (seltype == ELM_SEL_CLIPBOARD)
1167 eina_stringshare_replace(&wd->cut_sel, sel);
1171 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1173 Widget_Data *wd = elm_widget_data_get(data);
1176 wd->selmode = EINA_FALSE;
1177 if (!_elm_config->desktop_entry)
1178 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1179 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1180 if (!_elm_config->desktop_entry)
1181 elm_widget_scroll_hold_pop(data);
1182 _store_selection(ELM_SEL_CLIPBOARD, data);
1183 edje_object_part_text_insert(wd->ent, "elm.text", "");
1184 edje_object_part_text_select_none(wd->ent, "elm.text");
1188 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1190 Widget_Data *wd = elm_widget_data_get(data);
1192 wd->selmode = EINA_TRUE;
1193 if (!_elm_config->desktop_entry)
1195 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1196 elm_widget_scroll_hold_pop(data);
1198 _store_selection(ELM_SEL_CLIPBOARD, data);
1202 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1204 Widget_Data *wd = elm_widget_data_get(data);
1206 wd->selmode = EINA_FALSE;
1207 if (!_elm_config->desktop_entry)
1208 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1209 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1210 if (!_elm_config->desktop_entry)
1211 elm_widget_scroll_hold_pop(data);
1212 edje_object_part_text_select_none(wd->ent, "elm.text");
1216 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
1218 Widget_Data *wd = elm_widget_data_get(data);
1222 #ifdef HAVE_ELEMENTARY_X
1223 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
1225 cnpwidgetdata = data;
1226 elm_cbhm_helper_init(obj);
1227 if (elm_entry_cnp_textonly_get(obj))
1228 elm_cbhm_send_raw_data("show0");
1230 elm_cbhm_send_raw_data("show1");
1236 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1238 Widget_Data *wd = elm_widget_data_get(data);
1240 cnpwidgetdata = data;
1246 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1248 Elm_Entry_Context_Menu_Item *it = data;
1249 Evas_Object *obj2 = it->obj;
1250 if (it->func) it->func(it->data, obj2, NULL);
1254 _menu_press(Evas_Object *obj)
1256 Widget_Data *wd = elm_widget_data_get(obj);
1259 const Elm_Entry_Context_Menu_Item *it;
1261 if ((wd->api) && (wd->api->obj_longpress))
1263 wd->api->obj_longpress(obj);
1265 else if (wd->context_menu)
1267 const char *context_menu_orientation;
1269 if (wd->hoversel) evas_object_del(wd->hoversel);
1270 else elm_widget_scroll_freeze_push(obj);
1271 wd->hoversel = elm_hoversel_add(obj);
1272 context_menu_orientation = edje_object_data_get
1273 (wd->ent, "context_menu_orientation");
1274 if ((context_menu_orientation) &&
1275 (!strcmp(context_menu_orientation, "horizontal")))
1276 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1277 elm_object_style_set(wd->hoversel, "entry");
1278 elm_widget_sub_object_add(obj, wd->hoversel);
1279 elm_object_text_set(wd->hoversel, "Text");
1280 top = elm_widget_top_get(obj);
1281 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1282 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1286 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1288 if (1) // need way to detect if someone has a selection
1291 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1295 if ((!wd->password) && (wd->editable))
1296 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1297 _clipboard_menu, obj);
1304 if (wd->have_selection)
1306 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1309 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1312 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1316 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1317 _clipboard_menu, obj);
1321 EINA_LIST_FOREACH(wd->items, l, it)
1323 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1324 it->icon_type, _item_clicked, it);
1328 _hoversel_position(obj);
1329 evas_object_show(wd->hoversel);
1330 elm_hoversel_hover_begin(wd->hoversel);
1332 if (!_elm_config->desktop_entry)
1334 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1335 edje_object_part_text_select_abort(wd->ent, "elm.text");
1341 _magnifier_hide(void *data)
1343 Widget_Data *wd = elm_widget_data_get(data);
1346 evas_object_hide(wd->mgf_bg);
1347 evas_object_hide(wd->mgf_clip);
1350 elm_smart_scroller_freeze_set(wd->scroller, EINA_FALSE);
1354 _magnifier_show(void *data)
1356 Widget_Data *wd = elm_widget_data_get(data);
1359 evas_object_show(wd->mgf_bg);
1360 evas_object_show(wd->mgf_clip);
1364 _magnifier_move(void *data)
1366 Widget_Data *wd = elm_widget_data_get(data);
1369 Evas_Coord x, y, w, h, fs;
1370 Evas_Coord cx, cy, cw, ch, ox, oy;
1372 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1376 evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1377 elm_smart_scroller_child_pos_get(wd->scroller, &ox, &oy);
1382 evas_object_geometry_get(data, &x, &y, &w, &h);
1385 fs = elm_finger_size_get();
1387 if ((cy + y) - wd->mgf_height - fs < 0)
1388 oy = -1 * ((cy + y) - wd->mgf_height - fs);
1390 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1391 evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1392 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1393 evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1397 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);
1401 _magnifier_create(void *data)
1403 Widget_Data *wd = elm_widget_data_get(data);
1404 Evas_Coord x, y, w, h, mw, mh;
1405 const char* key_data = NULL;
1411 evas_object_image_source_unset(wd->mgf_proxy);
1412 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1413 evas_object_hide(wd->mgf_proxy);
1414 evas_object_clip_unset(wd->mgf_proxy);
1415 evas_object_del(wd->mgf_proxy);
1417 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1418 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1421 evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1423 evas_object_geometry_get(data, &x, &y, &w, &h);
1425 if ((w <= 0) || (h <= 0))
1428 wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1430 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1431 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1432 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1433 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1437 wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1438 evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1439 edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1441 key_data = edje_object_data_get(wd->mgf_bg, "height");
1442 if (key_data) wd->mgf_height = atoi(key_data);
1443 key_data = edje_object_data_get(wd->mgf_bg, "scale");
1444 if (key_data) wd->mgf_scale = atof(key_data);
1446 if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1447 evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1451 elm_smart_scroller_freeze_set(wd->scroller, EINA_TRUE);
1452 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(wd->scroller));
1453 evas_object_image_source_set(wd->mgf_proxy, wd->scroller);
1457 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1458 evas_object_image_source_set(wd->mgf_proxy, data);
1461 mw = (Evas_Coord)((float)w * wd->mgf_scale);
1462 mh = (Evas_Coord)((float)h * wd->mgf_scale);
1463 if ((mw <= 0) || (mh <= 0))
1466 evas_object_resize(wd->mgf_proxy, mw, mh);
1467 evas_object_image_fill_set(wd->mgf_proxy, 0, 0, mw, mh);
1468 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1469 evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1470 evas_object_show(wd->mgf_proxy);
1471 evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1473 evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1474 evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1478 _long_press(void *data)
1480 Widget_Data *wd = elm_widget_data_get(data);
1481 if (!wd) return ECORE_CALLBACK_CANCEL;
1483 wd->long_pressed = EINA_TRUE;
1485 if (wd->longpress_timer)
1487 ecore_timer_del(wd->longpress_timer);
1488 wd->longpress_timer = NULL;
1491 _cancel(data, NULL, NULL);
1493 _magnifier_create(data);
1494 _magnifier_move(data);
1495 _magnifier_show(data);
1496 elm_object_scroll_freeze_push(data);
1498 wd->longpress_timer = NULL;
1499 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1500 return ECORE_CALLBACK_CANCEL;
1504 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1506 Widget_Data *wd = elm_widget_data_get(data);
1507 Evas_Event_Mouse_Down *ev = event_info;
1509 if (wd->disabled) return;
1510 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1511 wd->downx = ev->canvas.x;
1512 wd->downy = ev->canvas.y;
1513 wd->long_pressed = EINA_FALSE;
1514 if (ev->button == 1)
1516 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1517 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1522 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1524 Widget_Data *wd = elm_widget_data_get(data);
1525 Evas_Event_Mouse_Up *ev = event_info;
1527 if (wd->disabled) return;
1528 if (ev->button == 1)
1530 if (!wd->double_clicked)
1532 if ((wd->api) && (wd->api->obj_mouseup))
1534 wd->api->obj_mouseup(data);
1538 if (wd->longpress_timer)
1540 ecore_timer_del(wd->longpress_timer);
1541 wd->longpress_timer = NULL;
1544 _magnifier_hide(data);
1545 elm_object_scroll_freeze_pop(data);
1547 if (wd->long_pressed)
1553 else if (ev->button == 3)
1561 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1563 Widget_Data *wd = elm_widget_data_get(data);
1564 Evas_Event_Mouse_Move *ev = event_info;
1566 if (wd->disabled) return;
1569 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1571 if (wd->longpress_timer)
1573 ecore_timer_del(wd->longpress_timer);
1574 wd->longpress_timer = NULL;
1577 else if (wd->longpress_timer)
1581 dx = wd->downx - ev->cur.canvas.x;
1583 dy = wd->downy - ev->cur.canvas.y;
1586 ((_elm_config->finger_size / 2) *
1587 (_elm_config->finger_size / 2)))
1589 ecore_timer_del(wd->longpress_timer);
1590 wd->longpress_timer = NULL;
1594 else if (wd->longpress_timer)
1598 dx = wd->downx - ev->cur.canvas.x;
1600 dy = wd->downy - ev->cur.canvas.y;
1603 ((_elm_config->finger_size / 2) *
1604 (_elm_config->finger_size / 2)))
1606 ecore_timer_del(wd->longpress_timer);
1607 wd->longpress_timer = NULL;
1611 if (ev->buttons == 1)
1613 if (wd->long_pressed)
1615 _magnifier_show(data);
1616 _magnifier_move(data);
1622 _getbase(Evas_Object *obj)
1624 Widget_Data *wd = elm_widget_data_get(obj);
1625 if (!wd) return "base";
1628 if (wd->password) return "base-password";
1631 if (wd->single_line) return "base-single";
1634 switch (wd->linewrap)
1637 return "base-charwrap";
1640 case ELM_WRAP_MIXED:
1641 return "base-mixedwrap";
1644 return "base-nowrap";
1651 if (wd->password) return "base-password";
1654 if (wd->single_line) return "base-single-noedit";
1657 switch (wd->linewrap)
1660 return "base-noedit-charwrap";
1662 return "base-noedit";
1663 case ELM_WRAP_MIXED:
1664 return "base-noedit-mixedwrap";
1667 return "base-nowrap-noedit";
1677 _entry_length_get(Evas_Object *obj)
1680 const char *str = elm_entry_entry_get(obj);
1683 char *plain_str = _elm_util_mkup_to_text(str);
1684 if (!plain_str) return 0;
1686 len = strlen(plain_str);
1692 #ifndef HAVE_STRCASESTR
1693 char* _strcasestr(const char *s, const char *find)
1698 if ((c = *find++) != 0) {
1699 c = tolower((unsigned char) c);
1703 if( (sc = *s++) == 0)
1705 } while ((char)tolower((unsigned char)sc) != c);
1706 } while (strncasecmp(s, find, len) != 0);
1714 _matchlist_show(void *data)
1716 Widget_Data *wd = elm_widget_data_get(data);
1717 const char *text = NULL;
1719 char *str_list = NULL, *str_result = NULL;
1720 char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1723 Eina_Bool textfound = EINA_FALSE;
1726 if (elm_widget_disabled_get(data)) return;
1728 wd->matchlist_job = NULL;
1730 if (wd->matchlist_list_clicked)
1732 evas_object_hide(wd->hover);
1733 wd->matchlist_list_clicked = EINA_FALSE;
1736 text = elm_entry_entry_get(data);
1739 textlen = strlen(text);
1741 if (textlen < wd->matchlist_threshold)
1743 evas_object_hide(wd->hover);
1747 evas_object_hide(wd->hover);
1751 elm_list_clear(wd->list);
1752 EINA_LIST_FOREACH(wd->match_list, l, str_list)
1754 if (wd->matchlist_case_sensitive)
1755 str_result = strstr(str_list, text);
1757 #ifdef HAVE_STRCASESTR
1758 str_result = strcasestr(str_list, text);
1760 str_result = _strcasestr(str_list, text);
1765 str_mkup = malloc(strlen(str_list) + 16);
1766 if (str_mkup == NULL) return;
1768 textlen = strlen(str_list) - strlen(str_result);
1769 str_front = malloc(textlen + 1);
1770 if (str_front == NULL) return;
1772 memset(str_front, 0, textlen + 1);
1773 strncpy(str_front, str_list, textlen);
1775 textlen = strlen(text);
1776 str_mid = malloc(textlen + 1);
1777 if (str_mid == NULL) return;
1779 memset(str_mid, 0, textlen + 1);
1780 strncpy(str_mid, str_list + strlen(str_front), textlen);
1782 sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1784 elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1786 if (str_mkup) free(str_mkup);
1787 if (str_front) free(str_front);
1788 if (str_mid) free(str_mid);
1790 textfound=EINA_TRUE;
1799 elm_list_go(wd->list);
1800 evas_object_show(wd->hover);
1801 evas_object_raise(wd->hover);
1805 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1807 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1808 Widget_Data *wd = elm_widget_data_get(data);
1809 if ((it == NULL) || (wd == NULL))
1812 const char *text = elm_list_item_label_get(it);
1813 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1818 elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1819 elm_entry_cursor_end_set(data);
1820 wd->matchlist_list_clicked = EINA_TRUE;
1822 evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1825 elm_widget_focus_set(data, EINA_TRUE);
1829 _entry_changed_common_handling(void *data, const char *event)
1831 Widget_Data *wd = elm_widget_data_get(data);
1832 Evas_Coord minw, minh;
1834 wd->changed = EINA_TRUE;
1835 /* Reset the size hints which are no more relevant.
1836 * Keep the height, this is a hack, but doesn't really matter
1837 * cause we'll re-eval in a moment. */
1840 evas_object_size_hint_min_get(data, &minw, &minh);
1841 evas_object_size_hint_min_set(data, minw, minh);
1845 evas_object_size_hint_min_get(data, NULL, &minh);
1846 evas_object_size_hint_min_set(data, -1, minh);
1850 if (wd->text) eina_stringshare_del(wd->text);
1852 if (wd->password_text) eina_stringshare_del(wd->password_text);
1853 wd->password_text = NULL;
1854 _check_enable_returnkey(data);
1855 evas_object_smart_callback_call(data, event, NULL);
1856 if (wd->delay_write)
1858 ecore_timer_del(wd->delay_write);
1859 wd->delay_write = NULL;
1862 if ((wd->single_line) && (wd->match_list))
1864 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1865 wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1867 if ((!wd->autosave) || (!wd->file)) return;
1868 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1872 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1874 _entry_changed_common_handling(data, SIG_CHANGED);
1878 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1880 _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1885 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1887 Widget_Data *wd = elm_widget_data_get(data);
1888 elm_object_scroll_freeze_push(data);
1890 if ((wd->api) && (wd->api->obj_hidemenu))
1892 wd->api->obj_hidemenu(data);
1895 _magnifier_create(data);
1896 _magnifier_move(data);
1897 _magnifier_show(data);
1901 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1903 Widget_Data *wd = elm_widget_data_get(data);
1904 elm_object_scroll_freeze_pop(data);
1906 if (wd->have_selection)
1908 _magnifier_hide(data);
1914 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1916 _magnifier_move(data);
1917 _magnifier_show(data);
1921 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1923 _magnifier_hide(data);
1928 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1930 Widget_Data *wd = elm_widget_data_get(data);
1934 EINA_LIST_FOREACH(entries, l, entry)
1936 if (entry != data) elm_entry_select_none(entry);
1938 wd->have_selection = EINA_TRUE;
1939 wd->selmode = EINA_TRUE;
1940 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1941 #ifdef HAVE_ELEMENTARY_X
1942 if (wd->sel_notify_handler)
1944 const char *txt = elm_entry_selection_get(data);
1947 top = elm_widget_top_get(data);
1948 if ((top) && (elm_win_xwindow_get(top)))
1949 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1955 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1957 Evas_Coord cx, cy, cw, ch;
1958 Widget_Data *wd = elm_widget_data_get(data);
1961 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1962 if (!wd->deferred_recalc_job)
1963 elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
1966 wd->deferred_cur = EINA_TRUE;
1970 wd->ch = ch + elm_finger_size_get();
1975 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1977 Evas_Coord cx, cy, cw, ch;
1978 Widget_Data *wd = elm_widget_data_get(data);
1980 wd->have_selection = EINA_TRUE;
1981 wd->selmode = EINA_TRUE;
1982 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1983 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1984 elm_entry_selection_get(data));
1986 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1987 if (!wd->deferred_recalc_job)
1988 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get(), EINA_FALSE);
1991 wd->deferred_cur = EINA_TRUE;
1995 wd->ch = ch + elm_finger_size_get();
2000 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2002 Widget_Data *wd = elm_widget_data_get(data);
2004 if (!wd->have_selection) return;
2005 wd->have_selection = EINA_FALSE;
2006 wd->selmode = EINA_FALSE;
2007 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
2008 if (wd->sel_notify_handler)
2012 #ifdef HAVE_ELEMENTARY_X
2015 top = elm_widget_top_get(data);
2016 if ((top) && (elm_win_xwindow_get(top)))
2017 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
2020 eina_stringshare_del(wd->cut_sel);
2025 #ifdef HAVE_ELEMENTARY_X
2028 top = elm_widget_top_get(data);
2029 if ((top) && (elm_win_xwindow_get(top)))
2030 elm_selection_clear(ELM_SEL_PRIMARY, data);
2035 if ((wd->api) && (wd->api->obj_hidemenu))
2037 wd->api->obj_hidemenu(data);
2042 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2044 Widget_Data *wd = elm_widget_data_get(data);
2046 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2047 if (wd->sel_notify_handler)
2049 #ifdef HAVE_ELEMENTARY_X
2052 top = elm_widget_top_get(data);
2053 if ((top) && (elm_win_xwindow_get(top)))
2055 wd->selection_asked = EINA_TRUE;
2056 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
2064 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2066 Widget_Data *wd = elm_widget_data_get(data);
2068 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
2069 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2070 elm_entry_selection_get(data));
2074 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2076 Widget_Data *wd = elm_widget_data_get(data);
2078 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
2079 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2080 elm_entry_selection_get(data));
2081 edje_object_part_text_insert(wd->ent, "elm.text", "");
2082 wd->changed = EINA_TRUE;
2087 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2089 Widget_Data *wd = elm_widget_data_get(data);
2091 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2092 wd->cur_changed = EINA_TRUE;
2093 _recalc_cursor_geometry(data);
2097 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2099 Widget_Data *wd = elm_widget_data_get(data);
2104 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2106 Widget_Data *wd = elm_widget_data_get(data);
2111 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
2113 Widget_Data *wd = elm_widget_data_get(data);
2114 Elm_Entry_Anchor_Info ei;
2115 char *buf2, *p, *p2, *n;
2117 p = strrchr(emission, ',');
2120 const Eina_List *geoms;
2124 while (p2 >= emission)
2126 if (*p2 == ',') break;
2130 buf2 = alloca(5 + p - p2);
2131 strncpy(buf2, p2, p - p2);
2134 ei.button = atoi(buf2);
2135 ei.x = ei.y = ei.w = ei.h = 0;
2137 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
2140 Evas_Textblock_Rectangle *r;
2142 Evas_Coord px, py, x, y;
2144 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
2145 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
2146 EINA_LIST_FOREACH(geoms, l, r)
2148 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
2149 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
2160 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
2165 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2167 Widget_Data *wd = elm_widget_data_get(data);
2172 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2174 Widget_Data *wd = elm_widget_data_get(data);
2179 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2181 Widget_Data *wd = elm_widget_data_get(data);
2186 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2188 Widget_Data *wd = elm_widget_data_get(data);
2190 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
2194 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2196 Widget_Data *wd = elm_widget_data_get(data);
2198 wd->double_clicked = EINA_FALSE;
2199 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
2201 if ((wd->api) && (wd->api->obj_hidemenu))
2203 wd->api->obj_hidemenu(data);
2208 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2210 Widget_Data *wd = elm_widget_data_get(data);
2212 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
2216 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2218 Widget_Data *wd = elm_widget_data_get(data);
2220 wd->double_clicked = EINA_TRUE;
2221 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
2224 #ifdef HAVE_ELEMENTARY_X
2226 _event_selection_notify(void *data, int type __UNUSED__, void *event)
2228 Widget_Data *wd = elm_widget_data_get(data);
2229 Ecore_X_Event_Selection_Notify *ev = event;
2230 if (!wd) return ECORE_CALLBACK_PASS_ON;
2231 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
2232 return ECORE_CALLBACK_PASS_ON;
2234 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2235 (ev->selection == ECORE_X_SELECTION_PRIMARY))
2237 Ecore_X_Selection_Data_Text *text_data;
2239 text_data = ev->data;
2240 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2242 if (text_data->text)
2244 char *txt = _elm_util_text_to_mkup(text_data->text);
2248 elm_entry_entry_insert(data, txt);
2253 wd->selection_asked = EINA_FALSE;
2255 else if (ev->selection == ECORE_X_SELECTION_XDND)
2257 Ecore_X_Selection_Data_Text *text_data;
2259 text_data = ev->data;
2260 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2262 if (text_data->text)
2264 char *txt = _elm_util_text_to_mkup(text_data->text);
2268 /* Massive FIXME: this should be at the drag point */
2269 elm_entry_entry_insert(data, txt);
2274 wd->drag_selection_asked = EINA_FALSE;
2276 ecore_x_dnd_send_finished();
2279 return ECORE_CALLBACK_PASS_ON;
2283 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2286 Widget_Data *wd = elm_widget_data_get(data);
2287 Ecore_X_Event_Selection_Clear *ev = event;
2288 if (!wd) return ECORE_CALLBACK_PASS_ON;
2289 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2290 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2291 (ev->selection == ECORE_X_SELECTION_PRIMARY))
2293 elm_entry_select_none(data);
2298 Evas_Object *top = elm_widget_top_get(data);
2299 Ecore_X_Event_Selection_Clear *ev = event;
2302 return ECORE_CALLBACK_PASS_ON;
2304 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2306 return ECORE_CALLBACK_PASS_ON;
2309 if (cnpwidgetdata == data)
2311 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
2315 return ECORE_CALLBACK_PASS_ON;
2319 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2324 wd = elm_widget_data_get(obj);
2325 if (!wd) return EINA_FALSE;
2326 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
2328 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2329 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2330 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2331 EDJE_CURSOR_MAIN,drop->x,drop->y);
2332 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2333 elm_entry_entry_insert(obj, drop->data);
2334 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2335 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2341 static Evas_Object *
2342 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2344 Widget_Data *wd = elm_widget_data_get(data);
2347 Elm_Entry_Item_Provider *ip;
2349 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2351 o = ip->func(ip->data, data, item);
2354 if (!strncmp(item, "file://", 7))
2356 const char *fname = item + 7;
2358 o = evas_object_image_filled_add(evas_object_evas_get(data));
2359 evas_object_image_file_set(o, fname, NULL);
2360 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2362 evas_object_show(o);
2367 o = edje_object_add(evas_object_evas_get(data));
2368 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2372 o = edje_object_add(evas_object_evas_get(data));
2373 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2374 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2379 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2381 const char *srcstring = NULL;
2382 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2383 char *curlocater, *replocater;
2384 char *starttag, *endtag;
2385 int tagtxtlen = 0, insertflag = 0;
2387 srcstring = eina_strbuf_string_get(srcbuf);
2388 curlocater = strstr(srcstring, key);
2390 if (!curlocater || !srcstring)
2398 starttag = strchr(srcstring, '<');
2399 endtag = strchr(srcstring, '>');
2400 tagtxtlen = endtag - starttag;
2401 if (tagtxtlen <= 0) tagtxtlen = 0;
2402 if (starttag < curlocater && curlocater < endtag) break;
2403 if (endtag != NULL && endtag+1 != NULL)
2404 srcstring = endtag+1;
2407 } while (strlen(srcstring) > 1);
2409 if (starttag && endtag && tagtxtlen > strlen(key))
2411 repbuf = eina_strbuf_new();
2412 diffbuf = eina_strbuf_new();
2413 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2414 srcstring = eina_strbuf_string_get(repbuf);
2415 curlocater = strstr(srcstring, key);
2417 if (curlocater != NULL)
2419 replocater = curlocater + strlen(key) + 1;
2421 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2424 if (replocater-curlocater > strlen(key)+1)
2426 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2435 eina_strbuf_reset(repbuf);
2443 if (repbuf == NULL) repbuf = eina_strbuf_new();
2444 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2448 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2449 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2455 eina_strbuf_prepend(diffbuf, "<");
2456 eina_strbuf_append(diffbuf, ">");
2457 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2461 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2462 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2466 if (repbuf) eina_strbuf_free(repbuf);
2467 if (diffbuf) eina_strbuf_free(diffbuf);
2473 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2475 Eina_Strbuf *sharebuf = NULL;
2477 sharebuf = eina_strbuf_new();
2478 eina_strbuf_append(sharebuf, *srcstring);
2479 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2480 eina_stringshare_del(*srcstring);
2481 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2482 eina_strbuf_free(sharebuf);
2488 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2490 Widget_Data *wd = elm_widget_data_get(data);
2492 Elm_Entry_Text_Filter *tf;
2494 if (type == EDJE_TEXT_FILTER_FORMAT)
2497 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2499 tf->func(tf->data, data, text);
2505 /* This function is used to insert text by chunks in jobs */
2507 _text_append_idler(void *data)
2511 Evas_Object *obj = (Evas_Object *) data;
2512 Widget_Data *wd = elm_widget_data_get(obj);
2513 if (wd->text) eina_stringshare_del(wd->text);
2515 if (wd->password_text) eina_stringshare_del(wd->password_text);
2516 wd->password_text = NULL;
2517 wd->changed = EINA_TRUE;
2519 start = wd->append_text_position;
2520 if(start + _CHUNK_SIZE < wd->append_text_len)
2522 wd->append_text_position = (start + _CHUNK_SIZE);
2523 /* Go to the start of the nearest codepoint, because we don't want
2524 * to cut it in the middle */
2525 eina_unicode_utf8_get_prev(wd->append_text_left,
2526 &wd->append_text_position);
2530 wd->append_text_position = wd->append_text_len;
2533 backup = wd->append_text_left[wd->append_text_position];
2534 wd->append_text_left[wd->append_text_position] = '\0';
2536 edje_object_part_text_append(wd->ent, "elm.text",
2537 wd->append_text_left + start);
2539 wd->append_text_left[wd->append_text_position] = backup;
2541 /* If there's still more to go, renew the idler, else, cleanup */
2542 if (wd->append_text_position < wd->append_text_len)
2544 return ECORE_CALLBACK_RENEW;
2548 free(wd->append_text_left);
2549 wd->append_text_left = NULL;
2550 wd->append_text_idler = NULL;
2551 return ECORE_CALLBACK_CANCEL;
2556 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2558 int i = 0, unit_size;
2559 int current_len = strlen(*text);
2560 char *new_text = *text;
2561 if (unit >= LENGTH_UNIT_LAST) return;
2564 if (*new_text == '<')
2566 while (*new_text != '>')
2569 if (!*new_text) break;
2576 if (*new_text == '&')
2578 while (*(new_text + index) != ';')
2581 if (!*(new_text + index)) break;
2585 index = evas_string_char_next_get(new_text, index, NULL);
2586 markup = malloc(index + 1);
2587 strncpy(markup, new_text, index);
2589 if (unit == LENGTH_UNIT_BYTE)
2590 unit_size = strlen(elm_entry_markup_to_utf8(markup));
2591 else if (unit == LENGTH_UNIT_CHAR)
2592 unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
2598 if (can_add < unit_size)
2602 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2608 strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
2609 current_len -= index;
2610 (*text)[current_len] = 0;
2615 can_add -= unit_size;
2620 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2624 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2627 ELM_CHECK_WIDTYPE(obj, widtype);
2628 if (item && strcmp(item, "default")) return;
2629 Widget_Data *wd = elm_widget_data_get(obj);
2631 if (!entry) entry = "";
2632 if (wd->text) eina_stringshare_del(wd->text);
2634 if (wd->password_text) eina_stringshare_del(wd->password_text);
2635 wd->password_text = NULL;
2636 wd->changed = EINA_TRUE;
2638 /* Clear currently pending job if there is one */
2639 if (wd->append_text_idler)
2641 ecore_idler_del(wd->append_text_idler);
2642 free(wd->append_text_left);
2643 wd->append_text_left = NULL;
2644 wd->append_text_idler = NULL;
2647 len = strlen(entry);
2648 /* Split to ~_CHUNK_SIZE chunks */
2649 if (len > _CHUNK_SIZE)
2651 wd->append_text_left = (char *) malloc(len + 1);
2654 /* If we decided to use the idler */
2655 if (wd->append_text_left)
2657 /* Need to clear the entry first */
2658 edje_object_part_text_set(wd->ent, "elm.text", "");
2659 memcpy(wd->append_text_left, entry, len + 1);
2660 wd->append_text_position = 0;
2661 wd->append_text_len = len;
2662 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2666 edje_object_part_text_set(wd->ent, "elm.text", entry);
2671 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2673 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2674 Widget_Data *wd = elm_widget_data_get(obj);
2675 if (item && strcmp(item, "default")) return NULL;
2677 if (!wd) return NULL;
2680 if(wd->password_text) return wd->password_text;
2686 text = edje_object_part_text_get(wd->ent, "elm.text");
2689 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2692 eina_stringshare_replace(&wd->text, text);
2695 const char *pw_text;
2696 pw_text = elm_entry_markup_to_utf8(wd->text);
2699 eina_stringshare_replace(&wd->password_text, pw_text);
2701 return wd->password_text;
2708 * This adds an entry to @p parent object.
2710 * @param parent The parent object
2711 * @return The new object or NULL if it cannot be created
2716 elm_entry_add(Evas_Object *parent)
2718 Evas_Object *obj, *top;
2722 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2724 ELM_SET_WIDTYPE(widtype, "entry");
2725 elm_widget_type_set(obj, "entry");
2726 elm_widget_sub_object_add(parent, obj);
2727 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2728 elm_widget_data_set(obj, wd);
2729 elm_widget_del_hook_set(obj, _del_hook);
2730 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2731 elm_widget_theme_hook_set(obj, _theme_hook);
2732 elm_widget_disable_hook_set(obj, _disable_hook);
2733 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2734 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2735 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2736 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2737 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2738 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2739 elm_widget_can_focus_set(obj, EINA_TRUE);
2740 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2741 elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2742 elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2744 wd->scroller = elm_smart_scroller_add(e);
2745 elm_widget_sub_object_add(obj, wd->scroller);
2746 elm_smart_scroller_widget_set(wd->scroller, obj);
2747 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
2748 elm_widget_style_get(obj));
2749 evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2750 evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
2751 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2752 elm_smart_scroller_propagate_events_set(wd->scroller, EINA_TRUE);
2754 wd->linewrap = ELM_WRAP_WORD;
2755 wd->editable = EINA_TRUE;
2756 wd->disabled = EINA_FALSE;
2757 wd->context_menu = EINA_TRUE;
2758 wd->autosave = EINA_TRUE;
2759 wd->textonly = EINA_FALSE;
2760 wd->autoperiod = EINA_TRUE;
2762 wd->ent = edje_object_add(e);
2763 elm_widget_sub_object_add(obj, wd->ent);
2764 edje_object_item_provider_set(wd->ent, _get_item, obj);
2765 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2766 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2767 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2769 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2771 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2773 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2775 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2776 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2777 _signal_entry_changed, obj);
2778 edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2779 _signal_preedit_changed, obj);
2780 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2781 _signal_handler_move_start, obj);
2782 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2783 _signal_handler_move_end, obj);
2784 edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2785 _signal_handler_moving, obj);
2786 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2787 _signal_selection_start, obj);
2788 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2789 _signal_selection_end, obj);
2790 edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2791 _signal_magnifier_changed, obj);
2792 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2793 _signal_selection_changed, obj);
2794 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2795 _signal_selection_cleared, obj);
2796 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2797 _signal_entry_paste_request, obj);
2798 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2799 _signal_entry_copy_notify, obj);
2800 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2801 _signal_entry_cut_notify, obj);
2802 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2803 _signal_cursor_changed, obj);
2804 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2805 _signal_anchor_down, obj);
2806 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2807 _signal_anchor_up, obj);
2808 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2809 _signal_anchor_clicked, obj);
2810 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2811 _signal_anchor_move, obj);
2812 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2813 _signal_anchor_in, obj);
2814 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2815 _signal_anchor_out, obj);
2816 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2817 _signal_key_enter, obj);
2818 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2819 _signal_mouse_down, obj);
2820 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2821 _signal_mouse_clicked, obj);
2822 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2823 _signal_mouse_double, obj);
2824 edje_object_part_text_set(wd->ent, "elm.text", "");
2825 if (_elm_config->desktop_entry)
2826 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2827 elm_widget_resize_object_set(obj, wd->ent);
2830 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2832 #ifdef HAVE_ELEMENTARY_X
2833 top = elm_widget_top_get(obj);
2834 if ((top) && (elm_win_xwindow_get(top)))
2836 wd->sel_notify_handler =
2837 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2838 _event_selection_notify, obj);
2839 wd->sel_clear_handler =
2840 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2841 _event_selection_clear, obj);
2844 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2845 _drag_drop_cb, NULL);
2848 entries = eina_list_prepend(entries, obj);
2850 // module - find module for entry
2851 wd->api = _module(obj);
2852 // if found - hook in
2853 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2855 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2856 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2857 // TODO: and save some bytes, making descriptions per-class and not instance!
2858 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2862 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2864 ELM_CHECK_WIDTYPE(obj, widtype);
2865 Widget_Data *wd = elm_widget_data_get(obj);
2867 ext_mod->cancel = _cancel;
2868 ext_mod->copy = _copy;
2869 ext_mod->cut = _cut;
2870 ext_mod->paste = _paste;
2871 ext_mod->select = _select;
2872 ext_mod->selectall = _selectall;
2873 ext_mod->ent = wd->ent;
2874 ext_mod->items = wd->items;
2875 ext_mod->longpress_timer = wd->longpress_timer;
2876 ext_mod->editable = wd->editable;
2877 ext_mod->have_selection = wd->have_selection;
2878 ext_mod->password = wd->password;
2879 ext_mod->selmode = wd->selmode;
2880 ext_mod->cnpinit = _cnpinit;
2881 ext_mod->context_menu = wd->context_menu;
2882 ext_mod->textonly = wd->textonly;
2886 * This sets the entry object not to line wrap. All input will
2887 * be on a single line, and the entry box will extend with user input.
2889 * @param obj The entry object
2890 * @param single_line If true, the text in the entry
2891 * will be on a single line.
2896 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2898 ELM_CHECK_WIDTYPE(obj, widtype);
2899 Widget_Data *wd = elm_widget_data_get(obj);
2901 if (wd->single_line == single_line) return;
2902 wd->single_line = single_line;
2903 wd->linewrap = ELM_WRAP_NONE;
2904 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2908 if (wd->single_line)
2910 elm_smart_scroller_policy_set(wd->scroller,
2911 ELM_SMART_SCROLLER_POLICY_OFF,
2912 ELM_SMART_SCROLLER_POLICY_OFF);
2913 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2917 const Elm_Scroller_Policy map[3] =
2919 ELM_SMART_SCROLLER_POLICY_AUTO,
2920 ELM_SMART_SCROLLER_POLICY_ON,
2921 ELM_SMART_SCROLLER_POLICY_OFF
2923 elm_smart_scroller_policy_set(wd->scroller,
2926 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2933 * This returns true if the entry has been set to single line mode.
2934 * See also elm_entry_single_line_set().
2936 * @param obj The entry object
2937 * @return single_line If true, the text in the entry is set to display
2943 elm_entry_single_line_get(const Evas_Object *obj)
2945 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2946 Widget_Data *wd = elm_widget_data_get(obj);
2947 if (!wd) return EINA_FALSE;
2948 return wd->single_line;
2952 * This sets the entry object to password mode. All text entered
2953 * and/or displayed within the widget will be replaced with asterisks (*).
2955 * @param obj The entry object
2956 * @param password If true, password mode is enabled.
2961 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2963 ELM_CHECK_WIDTYPE(obj, widtype);
2964 Widget_Data *wd = elm_widget_data_get(obj);
2966 if (wd->password == password) return;
2967 wd->password = password;
2968 wd->single_line = EINA_TRUE;
2969 wd->linewrap = ELM_WRAP_NONE;
2974 * This returns whether password mode is enabled.
2975 * See also elm_entry_password_set().
2977 * @param obj The entry object
2978 * @return If true, the entry is set to display all characters
2984 elm_entry_password_get(const Evas_Object *obj)
2986 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2987 Widget_Data *wd = elm_widget_data_get(obj);
2988 if (!wd) return EINA_FALSE;
2989 return wd->password;
2993 * This sets the text displayed within the entry to @p entry.
2995 * @param obj The entry object
2996 * @param entry The text to be displayed
3001 elm_entry_entry_set(Evas_Object *obj, const char *entry)
3003 _elm_entry_text_set(obj, NULL, entry);
3007 * This appends @p entry to the text of the entry.
3009 * @param obj The entry object
3010 * @param entry The text to be displayed
3015 elm_entry_entry_append(Evas_Object *obj, const char *entry)
3018 ELM_CHECK_WIDTYPE(obj, widtype);
3019 Widget_Data *wd = elm_widget_data_get(obj);
3021 if (!entry) entry = "";
3022 wd->changed = EINA_TRUE;
3024 len = strlen(entry);
3025 if (wd->append_text_left)
3028 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
3034 wd->append_text_left = tmpbuf;
3035 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
3036 wd->append_text_len += len;
3040 /* FIXME: Add chunked appending here (like in entry_set) */
3041 edje_object_part_text_append(wd->ent, "elm.text", entry);
3046 * This returns the text currently shown in object @p entry.
3047 * See also elm_entry_entry_set().
3049 * @param obj The entry object
3050 * @return The currently displayed text or NULL on failure
3055 elm_entry_entry_get(const Evas_Object *obj)
3057 return _elm_entry_text_get(obj, NULL);
3061 * This returns EINA_TRUE if the entry is empty/there was an error
3062 * and EINA_FALSE if it is not empty.
3064 * @param obj The entry object
3065 * @return If the entry is empty or not.
3070 elm_entry_is_empty(const Evas_Object *obj)
3072 /* FIXME: until there's support for that in textblock, we just check
3073 * to see if the there is text or not. */
3074 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3075 Widget_Data *wd = elm_widget_data_get(obj);
3076 const Evas_Object *tb;
3077 //Evas_Textblock_Cursor *cur;
3079 if (!wd) return EINA_TRUE;
3082 /* It's a hack until we get the support suggested above.
3083 * We just create a cursor, point it to the begining, and then
3084 * try to advance it, if it can advance, the tb is not empty,
3085 * otherwise it is. */
3086 tb = edje_object_part_object_get(wd->ent, "elm.text");
3087 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
3088 actually, ok for the time being, thsese hackish stuff will be removed
3089 once evas 1.0 is out*/
3090 evas_textblock_cursor_pos_set(cur, 0);
3091 ret = evas_textblock_cursor_char_next(cur);
3092 evas_textblock_cursor_free(cur);
3097 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
3098 if (!str) return EINA_TRUE;
3100 ret = (strlen(str) == 0);
3106 * This returns all selected text within the entry.
3108 * @param obj The entry object
3109 * @return The selected text within the entry or NULL on failure
3114 elm_entry_selection_get(const Evas_Object *obj)
3116 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3117 Widget_Data *wd = elm_widget_data_get(obj);
3118 if (!wd) return NULL;
3119 return edje_object_part_text_selection_get(wd->ent, "elm.text");
3123 * This inserts text in @p entry where the current cursor position.
3125 * This inserts text at the cursor position is as if it was typed
3126 * by the user (note this also allows markup which a user
3127 * can't just "type" as it would be converted to escaped text, so this
3128 * call can be used to insert things like emoticon items or bold push/pop
3129 * tags, other font and color change tags etc.)
3131 * @param obj The entry object
3132 * @param entry The text to insert
3137 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
3139 ELM_CHECK_WIDTYPE(obj, widtype);
3140 Widget_Data *wd = elm_widget_data_get(obj);
3142 edje_object_part_text_insert(wd->ent, "elm.text", entry);
3144 #ifdef HAVE_ELEMENTARY_X
3145 if (cnpwidgetdata == obj)
3146 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
3149 wd->changed = EINA_TRUE;
3154 * This enables word line wrapping in the entry object. It is the opposite
3155 * of elm_entry_single_line_set(). Additionally, setting this disables
3156 * character line wrapping.
3158 * @param obj The entry object
3159 * @param wrap If true, the entry will be wrapped once it reaches the end
3160 * of the object. Wrapping will occur at the end of the word before the end of the
3166 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
3168 ELM_CHECK_WIDTYPE(obj, widtype);
3169 Widget_Data *wd = elm_widget_data_get(obj);
3171 if (wd->linewrap == wrap) return;
3173 wd->linewrap = wrap;
3178 * Get the wrapping behavior of the entry.
3179 * See also elm_entry_line_wrap_set().
3181 * @param obj The entry object
3187 elm_entry_line_wrap_get(const Evas_Object *obj)
3189 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3190 Widget_Data *wd = elm_widget_data_get(obj);
3191 if (!wd) return EINA_FALSE;
3192 return wd->linewrap;
3196 * This sets the editable attribute of the entry.
3198 * @param obj The entry object
3199 * @param editable If true, the entry will be editable by the user.
3200 * If false, it will be set to the disabled state.
3205 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
3207 ELM_CHECK_WIDTYPE(obj, widtype);
3208 Widget_Data *wd = elm_widget_data_get(obj);
3210 if (wd->editable == editable) return;
3211 wd->editable = editable;
3214 #ifdef HAVE_ELEMENTARY_X
3216 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
3218 elm_drop_target_del(obj);
3223 * This gets the editable attribute of the entry.
3224 * See also elm_entry_editable_set().
3226 * @param obj The entry object
3227 * @return If true, the entry is editable by the user.
3228 * If false, it is not editable by the user
3233 elm_entry_editable_get(const Evas_Object *obj)
3235 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3236 Widget_Data *wd = elm_widget_data_get(obj);
3237 if (!wd) return EINA_FALSE;
3238 return wd->editable;
3242 * This drops any existing text selection within the entry.
3244 * @param obj The entry object
3249 elm_entry_select_none(Evas_Object *obj)
3251 ELM_CHECK_WIDTYPE(obj, widtype);
3252 Widget_Data *wd = elm_widget_data_get(obj);
3256 wd->selmode = EINA_FALSE;
3257 if (!_elm_config->desktop_entry)
3258 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3259 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3261 wd->have_selection = EINA_FALSE;
3262 edje_object_part_text_select_none(wd->ent, "elm.text");
3266 * This selects all text within the entry.
3268 * @param obj The entry object
3273 elm_entry_select_all(Evas_Object *obj)
3275 ELM_CHECK_WIDTYPE(obj, widtype);
3276 Widget_Data *wd = elm_widget_data_get(obj);
3280 wd->selmode = EINA_FALSE;
3281 if (!_elm_config->desktop_entry)
3282 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3283 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3285 wd->have_selection = EINA_TRUE;
3286 edje_object_part_text_select_all(wd->ent, "elm.text");
3290 * This function returns the geometry of the cursor.
3292 * It's useful if you want to draw something on the cursor (or where it is),
3293 * or for example in the case of scrolled entry where you want to show the
3296 * @param obj The entry object
3297 * @param x returned geometry
3298 * @param y returned geometry
3299 * @param w returned geometry
3300 * @param h returned geometry
3301 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3306 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3308 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3309 Widget_Data *wd = elm_widget_data_get(obj);
3310 if (!wd) return EINA_FALSE;
3311 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3316 * This moves the cursor one place to the right within the entry.
3318 * @param obj The entry object
3319 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3324 elm_entry_cursor_next(Evas_Object *obj)
3326 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3327 Widget_Data *wd = elm_widget_data_get(obj);
3328 if (!wd) return EINA_FALSE;
3329 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3333 * This moves the cursor one place to the left within the entry.
3335 * @param obj The entry object
3336 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3341 elm_entry_cursor_prev(Evas_Object *obj)
3343 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3344 Widget_Data *wd = elm_widget_data_get(obj);
3345 if (!wd) return EINA_FALSE;
3346 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3350 * This moves the cursor one line up within the entry.
3352 * @param obj The entry object
3353 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3358 elm_entry_cursor_up(Evas_Object *obj)
3360 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3361 Widget_Data *wd = elm_widget_data_get(obj);
3362 if (!wd) return EINA_FALSE;
3363 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3367 * This moves the cursor one line down within the entry.
3369 * @param obj The entry object
3370 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3375 elm_entry_cursor_down(Evas_Object *obj)
3377 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3378 Widget_Data *wd = elm_widget_data_get(obj);
3379 if (!wd) return EINA_FALSE;
3380 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3384 * This moves the cursor to the beginning of the entry.
3386 * @param obj The entry object
3391 elm_entry_cursor_begin_set(Evas_Object *obj)
3393 ELM_CHECK_WIDTYPE(obj, widtype);
3394 Widget_Data *wd = elm_widget_data_get(obj);
3396 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3400 * This moves the cursor to the end of the entry.
3402 * @param obj The entry object
3407 elm_entry_cursor_end_set(Evas_Object *obj)
3409 ELM_CHECK_WIDTYPE(obj, widtype);
3410 Widget_Data *wd = elm_widget_data_get(obj);
3413 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3416 elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
3417 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
3422 * This moves the cursor to the beginning of the current line.
3424 * @param obj The entry object
3429 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3431 ELM_CHECK_WIDTYPE(obj, widtype);
3432 Widget_Data *wd = elm_widget_data_get(obj);
3434 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3438 * This moves the cursor to the end of the current line.
3440 * @param obj The entry object
3445 elm_entry_cursor_line_end_set(Evas_Object *obj)
3447 ELM_CHECK_WIDTYPE(obj, widtype);
3448 Widget_Data *wd = elm_widget_data_get(obj);
3450 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3454 * This begins a selection within the entry as though
3455 * the user were holding down the mouse button to make a selection.
3457 * @param obj The entry object
3462 elm_entry_cursor_selection_begin(Evas_Object *obj)
3464 ELM_CHECK_WIDTYPE(obj, widtype);
3465 Widget_Data *wd = elm_widget_data_get(obj);
3467 edje_object_part_text_select_begin(wd->ent, "elm.text");
3471 * This ends a selection within the entry as though
3472 * the user had just released the mouse button while making a selection.
3474 * @param obj The entry object
3479 elm_entry_cursor_selection_end(Evas_Object *obj)
3481 ELM_CHECK_WIDTYPE(obj, widtype);
3482 Widget_Data *wd = elm_widget_data_get(obj);
3484 edje_object_part_text_select_extend(wd->ent, "elm.text");
3488 * TODO: fill this in
3490 * @param obj The entry object
3491 * @return TODO: fill this in
3496 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3498 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3499 Widget_Data *wd = elm_widget_data_get(obj);
3500 if (!wd) return EINA_FALSE;
3501 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3505 * This returns whether the cursor is visible.
3507 * @param obj The entry object
3508 * @return If true, the cursor is visible.
3513 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3515 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3516 Widget_Data *wd = elm_widget_data_get(obj);
3517 if (!wd) return EINA_FALSE;
3518 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3522 * TODO: fill this in
3524 * @param obj The entry object
3525 * @return TODO: fill this in
3530 elm_entry_cursor_content_get(const Evas_Object *obj)
3532 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3533 Widget_Data *wd = elm_widget_data_get(obj);
3534 if (!wd) return NULL;
3535 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3539 * Sets the cursor position in the entry to the given value
3541 * @param obj The entry object
3542 * @param pos The position of the cursor
3547 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3549 ELM_CHECK_WIDTYPE(obj, widtype);
3550 Widget_Data *wd = elm_widget_data_get(obj);
3552 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3553 edje_object_message_signal_process(wd->ent);
3557 * Retrieves the current position of the cursor in the entry
3559 * @param obj The entry object
3560 * @return The cursor position
3565 elm_entry_cursor_pos_get(const Evas_Object *obj)
3567 ELM_CHECK_WIDTYPE(obj, widtype) 0;
3568 Widget_Data *wd = elm_widget_data_get(obj);
3570 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3574 * This executes a "cut" action on the selected text in the entry.
3576 * @param obj The entry object
3581 elm_entry_selection_cut(Evas_Object *obj)
3583 ELM_CHECK_WIDTYPE(obj, widtype);
3584 Widget_Data *wd = elm_widget_data_get(obj);
3586 _cut(obj, NULL, NULL);
3590 * This executes a "copy" action on the selected text in the entry.
3592 * @param obj The entry object
3597 elm_entry_selection_copy(Evas_Object *obj)
3599 ELM_CHECK_WIDTYPE(obj, widtype);
3600 Widget_Data *wd = elm_widget_data_get(obj);
3602 _copy(obj, NULL, NULL);
3606 * This executes a "paste" action in the entry.
3608 * @param obj The entry object
3613 elm_entry_selection_paste(Evas_Object *obj)
3615 ELM_CHECK_WIDTYPE(obj, widtype);
3616 Widget_Data *wd = elm_widget_data_get(obj);
3618 _paste(obj, NULL, NULL);
3622 * This clears and frees the items in a entry's contextual (right click) menu.
3624 * @param obj The entry object
3629 elm_entry_context_menu_clear(Evas_Object *obj)
3631 ELM_CHECK_WIDTYPE(obj, widtype);
3632 Widget_Data *wd = elm_widget_data_get(obj);
3633 Elm_Entry_Context_Menu_Item *it;
3635 EINA_LIST_FREE(wd->items, it)
3637 eina_stringshare_del(it->label);
3638 eina_stringshare_del(it->icon_file);
3639 eina_stringshare_del(it->icon_group);
3645 * This adds an item to the entry's contextual menu.
3647 * @param obj The entry object
3648 * @param label The item's text label
3649 * @param icon_file The item's icon file
3650 * @param icon_type The item's icon type
3651 * @param func The callback to execute when the item is clicked
3652 * @param data The data to associate with the item for related functions
3657 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)
3659 ELM_CHECK_WIDTYPE(obj, widtype);
3660 Widget_Data *wd = elm_widget_data_get(obj);
3661 Elm_Entry_Context_Menu_Item *it;
3663 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3665 wd->items = eina_list_append(wd->items, it);
3667 it->label = eina_stringshare_add(label);
3668 it->icon_file = eina_stringshare_add(icon_file);
3669 it->icon_type = icon_type;
3671 it->data = (void *)data;
3675 * This disables the entry's contextual (right click) menu.
3677 * @param obj The entry object
3678 * @param disabled If true, the menu is disabled
3683 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3685 ELM_CHECK_WIDTYPE(obj, widtype);
3686 Widget_Data *wd = elm_widget_data_get(obj);
3688 if (wd->context_menu == !disabled) return;
3689 wd->context_menu = !disabled;
3693 * This returns whether the entry's contextual (right click) menu is disabled.
3695 * @param obj The entry object
3696 * @return If true, the menu is disabled
3701 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3703 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3704 Widget_Data *wd = elm_widget_data_get(obj);
3705 if (!wd) return EINA_FALSE;
3706 return !wd->context_menu;
3710 * This appends a custom item provider to the list for that entry
3712 * This appends the given callback. The list is walked from beginning to end
3713 * with each function called given the item href string in the text. If the
3714 * function returns an object handle other than NULL (it should create an
3715 * and object to do this), then this object is used to replace that item. If
3716 * not the next provider is called until one provides an item object, or the
3717 * default provider in entry does.
3719 * @param obj The entry object
3720 * @param func The function called to provide the item object
3721 * @param data The data passed to @p func
3726 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3728 ELM_CHECK_WIDTYPE(obj, widtype);
3729 Widget_Data *wd = elm_widget_data_get(obj);
3731 EINA_SAFETY_ON_NULL_RETURN(func);
3732 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3736 wd->item_providers = eina_list_append(wd->item_providers, ip);
3740 * This prepends a custom item provider to the list for that entry
3742 * This prepends the given callback. See elm_entry_item_provider_append() for
3745 * @param obj The entry object
3746 * @param func The function called to provide the item object
3747 * @param data The data passed to @p func
3752 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3754 ELM_CHECK_WIDTYPE(obj, widtype);
3755 Widget_Data *wd = elm_widget_data_get(obj);
3757 EINA_SAFETY_ON_NULL_RETURN(func);
3758 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3762 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3766 * This removes a custom item provider to the list for that entry
3768 * This removes the given callback. See elm_entry_item_provider_append() for
3771 * @param obj The entry object
3772 * @param func The function called to provide the item object
3773 * @param data The data passed to @p func
3778 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3780 ELM_CHECK_WIDTYPE(obj, widtype);
3781 Widget_Data *wd = elm_widget_data_get(obj);
3783 Elm_Entry_Item_Provider *ip;
3785 EINA_SAFETY_ON_NULL_RETURN(func);
3786 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3788 if ((ip->func == func) && ((!data) || (ip->data == data)))
3790 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3798 * Append a filter function for text inserted in the entry
3800 * Append the given callback to the list. This functions will be called
3801 * whenever any text is inserted into the entry, with the text to be inserted
3802 * as a parameter. The callback function is free to alter the text in any way
3803 * it wants, but it must remember to free the given pointer and update it.
3804 * If the new text is to be discarded, the function can free it and set it text
3805 * parameter to NULL. This will also prevent any following filters from being
3808 * @param obj The entry object
3809 * @param func The function to use as text filter
3810 * @param data User data to pass to @p func
3815 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3818 Elm_Entry_Text_Filter *tf;
3819 ELM_CHECK_WIDTYPE(obj, widtype);
3821 wd = elm_widget_data_get(obj);
3823 EINA_SAFETY_ON_NULL_RETURN(func);
3825 tf = _filter_new(func, data);
3828 wd->text_filters = eina_list_append(wd->text_filters, tf);
3832 * Prepend a filter function for text insdrted in the entry
3834 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3835 * for more information
3837 * @param obj The entry object
3838 * @param func The function to use as text filter
3839 * @param data User data to pass to @p func
3844 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3847 Elm_Entry_Text_Filter *tf;
3848 ELM_CHECK_WIDTYPE(obj, widtype);
3850 wd = elm_widget_data_get(obj);
3852 EINA_SAFETY_ON_NULL_RETURN(func);
3854 tf = _filter_new(func, data);
3857 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3861 * Remove a filter from the list
3863 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3864 * for more information.
3866 * @param obj The entry object
3867 * @param func The filter function to remove
3868 * @param data The user data passed when adding the function
3873 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3877 Elm_Entry_Text_Filter *tf;
3878 ELM_CHECK_WIDTYPE(obj, widtype);
3880 wd = elm_widget_data_get(obj);
3882 EINA_SAFETY_ON_NULL_RETURN(func);
3884 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3886 if ((tf->func == func) && ((!data) || (tf->data == data)))
3888 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3896 * This converts a markup (HTML-like) string into UTF-8.
3897 * Returning string is obtained with malloc.
3898 * After use the returned string, it should be freed.
3900 * @param s The string (in markup) to be converted
3901 * @return The converted string (in UTF-8). It should be freed.
3906 elm_entry_markup_to_utf8(const char *s)
3908 char *ss = _elm_util_mkup_to_text(s);
3909 if (!ss) ss = strdup("");
3914 * This converts a UTF-8 string into markup (HTML-like).
3915 * Returning string is obtained with malloc.
3916 * After use the returned string, it should be freed.
3918 * @param s The string (in UTF-8) to be converted
3919 * @return The converted string (in markup). It should be freed.
3924 elm_entry_utf8_to_markup(const char *s)
3926 char *ss = _elm_util_text_to_mkup(s);
3927 if (!ss) ss = strdup("");
3932 * Filter inserted text based on user defined character and byte limits
3934 * Add this filter to an entry to limit the characters that it will accept
3935 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3936 * The funtion works on the UTF-8 representation of the string, converting
3937 * it from the set markup, thus not accounting for any format in it.
3939 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3940 * it as data when setting the filter. In it it's possible to set limits
3941 * by character count or bytes (any of them is disabled if 0), and both can
3942 * be set at the same time. In that case, it first checks for characters,
3945 * The function will cut the inserted text in order to allow only the first
3946 * number of characters that are still allowed. The cut is made in
3947 * characters, even when limiting by bytes, in order to always contain
3948 * valid ones and avoid half unicode characters making it in.
3953 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3955 Elm_Entry_Filter_Limit_Size *lim = data;
3958 const char *(*text_get)(const Evas_Object *);
3959 const char *widget_type;
3961 EINA_SAFETY_ON_NULL_RETURN(data);
3962 EINA_SAFETY_ON_NULL_RETURN(entry);
3963 EINA_SAFETY_ON_NULL_RETURN(text);
3965 /* hack. I don't want to copy the entire function to work with
3967 widget_type = elm_widget_type_get(entry);
3968 if (!strcmp(widget_type, "entry"))
3969 text_get = elm_entry_entry_get;
3973 current = elm_entry_markup_to_utf8(text_get(entry));
3975 if (lim->max_char_count > 0)
3977 len = evas_string_char_len_get(current);
3978 if (len >= lim->max_char_count)
3980 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3986 newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
3987 if ((len + newlen) > lim->max_char_count)
3988 _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3990 else if (lim->max_byte_count > 0)
3992 len = strlen(current);
3993 if (len >= lim->max_byte_count)
3995 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4001 newlen = strlen(elm_entry_markup_to_utf8(*text));
4002 if ((len + newlen) > lim->max_byte_count)
4003 _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
4009 * Filter inserted text based on accepted or rejected sets of characters
4011 * Add this filter to an entry to restrict the set of accepted characters
4012 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
4013 * This structure contains both accepted and rejected sets, but they are
4014 * mutually exclusive. If accepted is set, it will be used, otherwise it
4015 * goes on to the rejected set.
4018 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
4020 Elm_Entry_Filter_Accept_Set *as = data;
4024 int read_idx, last_read_idx = 0, read_char;
4026 EINA_SAFETY_ON_NULL_RETURN(data);
4027 EINA_SAFETY_ON_NULL_RETURN(text);
4029 if ((!as->accepted) && (!as->rejected))
4035 goes_in = EINA_TRUE;
4040 goes_in = EINA_FALSE;
4044 read_idx = evas_string_char_next_get(*text, 0, &read_char);
4047 int cmp_idx, cmp_char;
4048 Eina_Bool in_set = EINA_FALSE;
4050 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4053 if (read_char == cmp_char)
4058 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4060 if (in_set == goes_in)
4062 int size = read_idx - last_read_idx;
4063 const char *src = (*text) + last_read_idx;
4065 memcpy(insert, *text + last_read_idx, size);
4068 last_read_idx = read_idx;
4069 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4075 * This sets the file (and implicitly loads it) for the text to display and
4076 * then edit. All changes are written back to the file after a short delay if
4077 * the entry object is set to autosave.
4079 * @param obj The entry object
4080 * @param file The path to the file to load and save
4081 * @param format The file format
4086 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4088 ELM_CHECK_WIDTYPE(obj, widtype);
4089 Widget_Data *wd = elm_widget_data_get(obj);
4091 if (wd->delay_write)
4093 ecore_timer_del(wd->delay_write);
4094 wd->delay_write = NULL;
4096 if (wd->autosave) _save(obj);
4097 eina_stringshare_replace(&wd->file, file);
4098 wd->format = format;
4103 * Gets the file to load and save and the file format
4105 * @param obj The entry object
4106 * @param file The path to the file to load and save
4107 * @param format The file format
4112 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4114 ELM_CHECK_WIDTYPE(obj, widtype);
4115 Widget_Data *wd = elm_widget_data_get(obj);
4117 if (file) *file = wd->file;
4118 if (format) *format = wd->format;
4122 * This function writes any changes made to the file set with
4123 * elm_entry_file_set()
4125 * @param obj The entry object
4130 elm_entry_file_save(Evas_Object *obj)
4132 ELM_CHECK_WIDTYPE(obj, widtype);
4133 Widget_Data *wd = elm_widget_data_get(obj);
4135 if (wd->delay_write)
4137 ecore_timer_del(wd->delay_write);
4138 wd->delay_write = NULL;
4141 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4145 * This sets the entry object to 'autosave' the loaded text file or not.
4147 * @param obj The entry object
4148 * @param autosave Autosave the loaded file or not
4153 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4155 ELM_CHECK_WIDTYPE(obj, widtype);
4156 Widget_Data *wd = elm_widget_data_get(obj);
4158 wd->autosave = !!autosave;
4162 * This gets the entry object's 'autosave' status.
4164 * @param obj The entry object
4165 * @return Autosave the loaded file or not
4170 elm_entry_autosave_get(const Evas_Object *obj)
4172 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4173 Widget_Data *wd = elm_widget_data_get(obj);
4174 if (!wd) return EINA_FALSE;
4175 return wd->autosave;
4179 * Control pasting of text and images for the widget.
4181 * Normally the entry allows both text and images to be pasted. By setting
4182 * textonly to be true, this prevents images from being pasted.
4184 * Note this only changes the behaviour of text.
4186 * @param obj The entry object
4187 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
4192 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4194 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4195 ELM_CHECK_WIDTYPE(obj, widtype);
4196 Widget_Data *wd = elm_widget_data_get(obj);
4198 textonly = !!textonly;
4199 if (wd->textonly == textonly) return;
4200 wd->textonly = !!textonly;
4201 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
4202 #ifdef HAVE_ELEMENTARY_X
4203 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
4208 * Getting elm_entry text paste/drop mode.
4210 * In textonly mode, only text may be pasted or dropped into the widget.
4212 * @param obj The entry object
4213 * @return If the widget only accepts text from pastes.
4218 elm_entry_cnp_textonly_get(const Evas_Object *obj)
4220 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4221 Widget_Data *wd = elm_widget_data_get(obj);
4222 if (!wd) return EINA_FALSE;
4223 return wd->textonly;
4227 * Enable or disable scrolling in entry
4229 * Normally the entry is not scrollable unless you enable it with this call.
4231 * @param obj The entry object
4232 * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
4237 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
4239 ELM_CHECK_WIDTYPE(obj, widtype);
4240 Widget_Data *wd = elm_widget_data_get(obj);
4243 if (wd->scroll == scroll) return;
4244 wd->scroll = scroll;
4247 elm_widget_sub_object_del(obj, wd->scroller);
4248 elm_widget_resize_object_set(obj, wd->scroller);
4249 elm_widget_sub_object_add(obj, wd->ent);
4250 elm_smart_scroller_child_set(wd->scroller, wd->ent);
4251 evas_object_show(wd->scroller);
4252 elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
4253 if (wd->single_line)
4255 elm_smart_scroller_policy_set(wd->scroller,
4256 ELM_SMART_SCROLLER_POLICY_OFF,
4257 ELM_SMART_SCROLLER_POLICY_OFF);
4258 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4262 const Elm_Scroller_Policy map[3] =
4264 ELM_SMART_SCROLLER_POLICY_AUTO,
4265 ELM_SMART_SCROLLER_POLICY_ON,
4266 ELM_SMART_SCROLLER_POLICY_OFF
4268 elm_smart_scroller_policy_set(wd->scroller,
4271 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4276 elm_smart_scroller_child_set(wd->scroller, NULL);
4277 elm_widget_sub_object_del(obj, wd->ent);
4278 elm_widget_resize_object_set(obj, wd->ent);
4279 evas_object_smart_member_add(wd->scroller, obj);
4280 elm_widget_sub_object_add(obj, wd->scroller);
4281 evas_object_hide(wd->scroller);
4282 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
4289 * Get the scrollable state of the entry
4291 * Normally the entry is not scrollable. This gets the scrollable state
4292 * of the entry. See elm_entry_scrollable_set() for more information.
4294 * @param obj The entry object
4295 * @return The scrollable state
4300 elm_entry_scrollable_get(const Evas_Object *obj)
4302 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4303 Widget_Data *wd = elm_widget_data_get(obj);
4304 if (!wd) return EINA_FALSE;
4309 * This sets a widget to be displayed to the left of a scrolled entry.
4311 * @param obj The scrolled entry object
4312 * @param icon The widget to display on the left side of the scrolled
4315 * @note A previously set widget will be destroyed.
4316 * @note If the object being set does not have minimum size hints set,
4317 * it won't get properly displayed.
4320 * @see elm_entry_end_set
4323 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
4325 ELM_CHECK_WIDTYPE(obj, widtype);
4326 Widget_Data *wd = elm_widget_data_get(obj);
4329 EINA_SAFETY_ON_NULL_RETURN(icon);
4330 if (wd->icon == icon) return;
4331 if (wd->icon) evas_object_del(wd->icon);
4333 edje = elm_smart_scroller_edje_object_get(wd->scroller);
4335 edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
4336 edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
4341 * Gets the leftmost widget of the scrolled entry. This object is
4342 * owned by the scrolled entry and should not be modified.
4344 * @param obj The scrolled entry object
4345 * @return the left widget inside the scroller
4350 elm_entry_icon_get(const Evas_Object *obj)
4352 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4353 Widget_Data *wd = elm_widget_data_get(obj);
4354 if (!wd) return NULL;
4359 * Unset the leftmost widget of the scrolled entry, unparenting and
4362 * @param obj The scrolled entry object
4363 * @return the previously set icon sub-object of this entry, on
4366 * @see elm_entry_icon_set()
4371 elm_entry_icon_unset(Evas_Object *obj)
4373 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4374 Widget_Data *wd = elm_widget_data_get(obj);
4375 Evas_Object *ret = NULL;
4376 if (!wd) return NULL;
4379 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4380 if (!edje) return NULL;
4382 edje_object_part_unswallow(edje, wd->icon);
4383 edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
4391 * Sets the visibility of the left-side widget of the scrolled entry,
4392 * set by @elm_entry_icon_set().
4394 * @param obj The scrolled entry object
4395 * @param setting EINA_TRUE if the object should be displayed,
4396 * EINA_FALSE if not.
4401 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
4403 ELM_CHECK_WIDTYPE(obj, widtype);
4404 Widget_Data *wd = elm_widget_data_get(obj);
4405 if ((!wd) || (!wd->icon)) return;
4407 evas_object_hide(wd->icon);
4409 evas_object_show(wd->icon);
4414 * This sets a widget to be displayed to the end of a scrolled entry.
4416 * @param obj The scrolled entry object
4417 * @param end The widget to display on the right side of the scrolled
4420 * @note A previously set widget will be destroyed.
4421 * @note If the object being set does not have minimum size hints set,
4422 * it won't get properly displayed.
4425 * @see elm_entry_icon_set
4428 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
4430 ELM_CHECK_WIDTYPE(obj, widtype);
4431 Widget_Data *wd = elm_widget_data_get(obj);
4434 EINA_SAFETY_ON_NULL_RETURN(end);
4435 if (wd->end == end) return;
4436 if (wd->end) evas_object_del(wd->end);
4438 edje = elm_smart_scroller_edje_object_get(wd->scroller);
4440 edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
4441 edje_object_signal_emit(edje, "elm,action,show,end", "elm");
4446 * Gets the endmost widget of the scrolled entry. This object is owned
4447 * by the scrolled entry and should not be modified.
4449 * @param obj The scrolled entry object
4450 * @return the right widget inside the scroller
4455 elm_entry_end_get(const Evas_Object *obj)
4457 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4458 Widget_Data *wd = elm_widget_data_get(obj);
4459 if (!wd) return NULL;
4464 * Unset the endmost widget of the scrolled entry, unparenting and
4467 * @param obj The scrolled entry object
4468 * @return the previously set icon sub-object of this entry, on
4471 * @see elm_entry_icon_set()
4476 elm_entry_end_unset(Evas_Object *obj)
4478 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4479 Widget_Data *wd = elm_widget_data_get(obj);
4480 Evas_Object *ret = NULL;
4481 if (!wd) return NULL;
4484 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4485 if (!edje) return NULL;
4487 edje_object_part_unswallow(edje, wd->end);
4488 edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
4496 * Sets the visibility of the end widget of the scrolled entry, set by
4497 * @elm_entry_end_set().
4499 * @param obj The scrolled entry object
4500 * @param setting EINA_TRUE if the object should be displayed,
4501 * EINA_FALSE if not.
4506 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
4508 ELM_CHECK_WIDTYPE(obj, widtype);
4509 Widget_Data *wd = elm_widget_data_get(obj);
4510 if ((!wd) || (!wd->end)) return;
4512 evas_object_hide(wd->end);
4514 evas_object_show(wd->end);
4519 * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
4521 * @param obj The scrolled entry object
4522 * @param h The horizontal scrollbar policy to apply
4523 * @param v The vertical scrollbar policy to apply
4528 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
4530 ELM_CHECK_WIDTYPE(obj, widtype);
4531 Widget_Data *wd = elm_widget_data_get(obj);
4532 const Elm_Scroller_Policy map[3] =
4534 ELM_SMART_SCROLLER_POLICY_AUTO,
4535 ELM_SMART_SCROLLER_POLICY_ON,
4536 ELM_SMART_SCROLLER_POLICY_OFF
4541 elm_smart_scroller_policy_set(wd->scroller,
4547 * This enables/disables bouncing within the entry.
4549 * @param obj The scrolled entry object
4550 * @param h The horizontal bounce state
4551 * @param v The vertical bounce state
4556 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
4558 ELM_CHECK_WIDTYPE(obj, widtype);
4559 Widget_Data *wd = elm_widget_data_get(obj);
4561 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
4565 * Get the bounce mode
4567 * @param obj The Entry object
4568 * @param h_bounce Allow bounce horizontally
4569 * @param v_bounce Allow bounce vertically
4574 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
4576 ELM_CHECK_WIDTYPE(obj, widtype);
4577 Widget_Data *wd = elm_widget_data_get(obj);
4579 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
4582 EINA_DEPRECATED EAPI void
4583 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
4585 if (wrap) elm_entry_line_wrap_set(obj, ELM_WRAP_CHAR);
4589 * Set background color of the entry
4591 * @param obj The entry object
4592 * @param r Red property background color of The entry object
4593 * @param g Green property background color of The entry object
4594 * @param b Blue property background color of The entry object
4595 * @param a Alpha property background alpha of The entry object
4599 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4601 ELM_CHECK_WIDTYPE(obj, widtype);
4602 Widget_Data *wd = elm_widget_data_get(obj);
4603 evas_object_color_set(wd->bg, r, g, b, a);
4605 if (wd->bgcolor == EINA_FALSE)
4608 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
4613 * Set whether entry should support auto capitalization
4615 * @param obj The entry object
4616 * @param on If true, entry suports auto capitalization.
4621 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
4623 ELM_CHECK_WIDTYPE(obj, widtype);
4624 Widget_Data *wd = elm_widget_data_get(obj);
4628 wd->autocapital = EINA_FALSE;
4630 wd->autocapital = autocap;
4632 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4633 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4634 wd->autocapital = EINA_FALSE;
4636 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
4640 * Set whether entry should support auto period
4642 * @param obj The entry object
4643 * @param on If true, entry suports auto period.
4648 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
4650 ELM_CHECK_WIDTYPE(obj, widtype);
4651 Widget_Data *wd = elm_widget_data_get(obj);
4655 wd->autoperiod = EINA_FALSE;
4657 wd->autoperiod = autoperiod;
4659 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4660 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4661 wd->autoperiod = EINA_FALSE;
4663 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
4667 * Set whether entry should enable the return key on soft keyboard automatically
4669 * @param obj The entry object
4670 * @param on If true, entry enables the return key on soft keyboard automatically.
4675 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
4677 ELM_CHECK_WIDTYPE(obj, widtype);
4678 Widget_Data *wd = elm_widget_data_get(obj);
4681 wd->autoreturnkey = on;
4682 _check_enable_returnkey(obj);
4686 * This sets the attribute to show the input panel automatically.
4688 * @param obj The entry object
4689 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4694 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4696 ELM_CHECK_WIDTYPE(obj, widtype);
4697 Widget_Data *wd = elm_widget_data_get(obj);
4700 wd->input_panel_enable = enabled;
4701 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4705 * Set the input panel layout of the entry
4707 * @param obj The entry object
4708 * @param layout the layout to set
4713 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4715 ELM_CHECK_WIDTYPE(obj, widtype);
4716 Widget_Data *wd = elm_widget_data_get(obj);
4719 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4722 wd->input_panel_layout = layout;
4724 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4728 * Get the input method context in the entry widget
4730 * @param obj The entry object
4731 * @return The input method context
4735 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
4737 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4738 Widget_Data *wd = elm_widget_data_get(obj);
4739 if (!wd || !wd->ent) return NULL;
4741 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
4745 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
4747 Widget_Data *wd = elm_widget_data_get(obj);
4752 Evas_Coord max_w = 9999, max_h = 9999;
4753 const char* key_data = NULL;
4755 wd->matchlist_threshold = 1;
4756 wd->hover = elm_hover_add(elm_widget_parent_get(obj));
4757 elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
4758 elm_hover_target_set(wd->hover, obj);
4759 elm_object_style_set(wd->hover, "matchlist");
4761 wd->layout = elm_layout_add(wd->hover);
4762 elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
4763 wd->list = elm_list_add(wd->layout);
4764 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
4765 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
4766 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
4767 elm_object_style_set(wd->list, "matchlist");
4769 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
4770 if (key_data) max_w = atoi(key_data);
4771 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
4772 if (key_data) max_h = atoi(key_data);
4774 elm_list_go(wd->list);
4775 evas_object_size_hint_max_set(wd->list, max_w, max_h);
4776 evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
4777 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
4778 elm_hover_content_set(wd->hover, "bottom", wd->layout);
4780 wd->match_list = match_list;
4785 evas_object_del(wd->hover);
4787 wd->match_list = NULL;
4790 wd->matchlist_case_sensitive = case_sensitive;
4794 * Set the magnifier style of the entry
4796 * @param obj The entry object
4797 * @param type the magnifier style to set
4802 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4804 ELM_CHECK_WIDTYPE(obj, widtype);
4805 Widget_Data *wd = elm_widget_data_get(obj);
4808 wd->mgf_type = type;
4809 _magnifier_create(obj);
4813 * Set wrap width of the entry
4815 * @param obj The entry object
4816 * @param w The wrap width in pixels at a minimum where words need to wrap
4820 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
4822 Widget_Data *wd = elm_widget_data_get(obj);
4823 if (wd->wrap_w == w) return;
4829 * get wrap width of the entry
4831 * @param obj The entry object
4832 * @return The wrap width in pixels at a minimum where words need to wrap
4836 elm_entry_wrap_width_get(const Evas_Object *obj)
4838 Widget_Data *wd = elm_widget_data_get(obj);
4843 * Set the font size on the entry object
4845 * @param obj The entry object
4846 * @param size font size
4851 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
4853 ELM_CHECK_WIDTYPE(obj, widtype);
4854 Widget_Data *wd = elm_widget_data_get(obj);
4855 Eina_Strbuf *fontbuf = NULL;
4860 t = eina_stringshare_add(elm_entry_entry_get(obj));
4861 fontbuf = eina_strbuf_new();
4862 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
4864 if (fontsize == 0) removeflag = 1; // remove fontsize tag
4866 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
4868 elm_entry_entry_set(obj, t);
4872 eina_strbuf_free(fontbuf);
4873 eina_stringshare_del(t);
4877 * Set the text color on the entry object
4879 * @param obj The entry object
4880 * @param r Red property background color of The entry object
4881 * @param g Green property background color of The entry object
4882 * @param b Blue property background color of The entry object
4883 * @param a Alpha property background alpha of The entry object
4888 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4890 ELM_CHECK_WIDTYPE(obj, widtype);
4891 Widget_Data *wd = elm_widget_data_get(obj);
4892 Eina_Strbuf *colorbuf = NULL;
4897 t = eina_stringshare_add(elm_entry_entry_get(obj));
4899 if (len <= 0) return;
4900 colorbuf = eina_strbuf_new();
4901 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
4903 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
4905 elm_entry_entry_set(obj, t);
4909 eina_strbuf_free(colorbuf);
4910 eina_stringshare_del(t);
4914 * Set the text align on the entry object
4916 * @param obj The entry object
4917 * @param align align mode
4922 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
4924 ELM_CHECK_WIDTYPE(obj, widtype);
4925 Widget_Data *wd = elm_widget_data_get(obj);
4930 t = eina_stringshare_add(elm_entry_entry_get(obj));
4932 if (len <= 0) return;
4934 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
4935 elm_entry_entry_set(obj, t);
4939 eina_stringshare_del(t);