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 */
140 Elm_Text_Format format;
141 Evas_Coord lastw, entmw, entmh;
142 Evas_Coord downx, downy;
143 Evas_Coord cx, cy, cw, ch;
145 Eina_List *item_providers;
146 Eina_List *text_filters;
147 Eina_List *match_list;
148 Ecore_Job *matchlist_job;
149 Ecore_Job *hovdeljob;
150 Mod_Api *api; // module api if supplied
152 Elm_Scroller_Policy policy_h, policy_v;
153 Elm_Wrap_Type linewrap;
154 Eina_Bool changed : 1;
155 Eina_Bool single_line : 1;
156 Eina_Bool password : 1;
157 Eina_Bool editable : 1;
158 Eina_Bool selection_asked : 1;
159 Eina_Bool have_selection : 1;
160 Eina_Bool selmode : 1;
161 Eina_Bool deferred_cur : 1;
162 Eina_Bool cur_changed : 1;
163 Eina_Bool disabled : 1;
164 Eina_Bool double_clicked : 1;
165 Eina_Bool long_pressed : 1;
166 Eina_Bool context_menu : 1;
167 Eina_Bool drag_selection_asked : 1;
168 Eina_Bool bgcolor : 1;
169 Eina_Bool can_write : 1;
170 Eina_Bool autosave : 1;
171 Eina_Bool textonly : 1;
172 Eina_Bool usedown : 1;
173 Eina_Bool scroll : 1;
174 Eina_Bool autoreturnkey : 1;
175 Eina_Bool input_panel_enable : 1;
176 Eina_Bool autocapital : 1;
177 Elm_Input_Panel_Layout input_panel_layout;
178 Eina_Bool autoperiod : 1;
179 Eina_Bool matchlist_list_clicked : 1;
180 Eina_Bool matchlist_case_sensitive : 1;
181 int matchlist_threshold;
184 struct _Elm_Entry_Context_Menu_Item
188 const char *icon_file;
189 const char *icon_group;
190 Elm_Icon_Type icon_type;
195 struct _Elm_Entry_Item_Provider
197 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
201 struct _Elm_Entry_Text_Filter
203 void (*func) (void *data, Evas_Object *entry, char **text);
207 typedef enum _Length_Unit
214 static const char *widtype = NULL;
216 static Evas_Object *cnpwidgetdata = NULL;
219 #ifdef HAVE_ELEMENTARY_X
220 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
222 static void _del_hook(Evas_Object *obj);
223 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
224 static void _theme_hook(Evas_Object *obj);
225 static void _disable_hook(Evas_Object *obj);
226 static void _sizing_eval(Evas_Object *obj);
227 static void _on_focus_hook(void *data, Evas_Object *obj);
228 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
229 static const char *_getbase(Evas_Object *obj);
230 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
231 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
232 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
233 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
234 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
235 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
236 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
237 static void _signal_handler_moving(void *data, Evas_Object *obj, const char *emission, const char *source);
238 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
239 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
240 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
241 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
242 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
243 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
244 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
245 static int _entry_length_get(Evas_Object *obj);
246 static void _magnifier_create(void *data);
247 static void _magnifier_show(void *data);
248 static void _magnifier_hide(void *data);
249 static void _magnifier_move(void *data);
251 static const char SIG_CHANGED[] = "changed";
252 static const char SIG_ACTIVATED[] = "activated";
253 static const char SIG_PRESS[] = "press";
254 static const char SIG_LONGPRESSED[] = "longpressed";
255 static const char SIG_CLICKED[] = "clicked";
256 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
257 static const char SIG_FOCUSED[] = "focused";
258 static const char SIG_UNFOCUSED[] = "unfocused";
259 static const char SIG_SELECTION_PASTE[] = "selection,paste";
260 static const char SIG_SELECTION_COPY[] = "selection,copy";
261 static const char SIG_SELECTION_CUT[] = "selection,cut";
262 static const char SIG_SELECTION_START[] = "selection,start";
263 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
264 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
265 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
266 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
267 static const char SIG_MATCHLIST_CLICKED[] = "matchlist,clicked";
268 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
269 static const Evas_Smart_Cb_Description _signals[] = {
273 {SIG_LONGPRESSED, ""},
275 {SIG_CLICKED_DOUBLE, ""},
278 {SIG_SELECTION_PASTE, ""},
279 {SIG_SELECTION_COPY, ""},
280 {SIG_SELECTION_CUT, ""},
281 {SIG_SELECTION_START, ""},
282 {SIG_SELECTION_CHANGED, ""},
283 {SIG_SELECTION_CLEARED, ""},
284 {SIG_CURSOR_CHANGED, ""},
285 {SIG_ANCHOR_CLICKED, ""},
286 {SIG_PREEDIT_CHANGED, ""},
287 {SIG_MATCHLIST_CLICKED, ""},
291 typedef enum _Elm_Entry_Magnifier_Type
293 _ENTRY_MAGNIFIER_FIXEDSIZE = 0,
294 _ENTRY_MAGNIFIER_FILLWIDTH,
295 _ENTRY_MAGNIFIER_CIRCULAR,
296 } Elm_Entry_Magnifier_Type;
299 static Eina_List *entries = NULL;
303 void (*obj_hook) (Evas_Object *obj);
304 void (*obj_unhook) (Evas_Object *obj);
305 void (*obj_longpress) (Evas_Object *obj);
306 void (*obj_hidemenu) (Evas_Object *obj);
307 void (*obj_mouseup) (Evas_Object *obj);
311 _module(Evas_Object *obj __UNUSED__)
313 static Elm_Module *m = NULL;
314 if (m) goto ok; // already found - just use
315 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
317 m->api = malloc(sizeof(Mod_Api));
318 if (!m->api) return NULL;
319 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
320 _elm_module_symbol_get(m, "obj_hook");
321 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
322 _elm_module_symbol_get(m, "obj_unhook");
323 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
324 _elm_module_symbol_get(m, "obj_longpress");
325 ((Mod_Api *)(m->api) )->obj_hidemenu = // called on hide menu
326 _elm_module_symbol_get(m, "obj_hidemenu");
327 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
328 _elm_module_symbol_get(m, "obj_mouseup");
329 ok: // ok - return api
334 _buf_append(char *buf, const char *str, int *len, int *alloc)
336 int len2 = strlen(str);
337 if ((*len + len2) >= *alloc)
339 char *buf2 = realloc(buf, *alloc + len2 + 512);
340 if (!buf2) return NULL;
342 *alloc += (512 + len2);
344 strcpy(buf + *len, str);
350 _load_file(const char *file)
354 int alloc = 0, len = 0;
355 char *text = NULL, buf[16384 + 1];
357 f = fopen(file, "rb");
359 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
363 tmp_text = _buf_append(text, buf, &len, &alloc);
364 if (!tmp_text) break;
372 _load_plain(const char *file)
376 text = _load_file(file);
381 text2 = elm_entry_utf8_to_markup(text);
389 _load(Evas_Object *obj)
391 Widget_Data *wd = elm_widget_data_get(obj);
396 elm_entry_entry_set(obj, "");
401 case ELM_TEXT_FORMAT_PLAIN_UTF8:
402 text = _load_plain(wd->file);
404 case ELM_TEXT_FORMAT_MARKUP_UTF8:
405 text = _load_file(wd->file);
413 elm_entry_entry_set(obj, text);
417 elm_entry_entry_set(obj, "");
421 _save_markup_utf8(const char *file, const char *text)
425 if ((!text) || (!text[0]))
427 ecore_file_unlink(file);
430 f = fopen(file, "wb");
433 // FIXME: report a write error
436 fputs(text, f); // FIXME: catch error
441 _save_plain_utf8(const char *file, const char *text)
445 text2 = elm_entry_markup_to_utf8(text);
448 _save_markup_utf8(file, text2);
453 _save(Evas_Object *obj)
455 Widget_Data *wd = elm_widget_data_get(obj);
457 if (!wd->file) return;
460 case ELM_TEXT_FORMAT_PLAIN_UTF8:
461 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
463 case ELM_TEXT_FORMAT_MARKUP_UTF8:
464 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
472 _delay_write(void *data)
474 Widget_Data *wd = elm_widget_data_get(data);
475 if (!wd) return ECORE_CALLBACK_CANCEL;
477 wd->delay_write = NULL;
478 return ECORE_CALLBACK_CANCEL;
481 static Elm_Entry_Text_Filter *
482 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
484 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
485 if (!tf) return NULL;
488 if (func == elm_entry_filter_limit_size)
490 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
497 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
503 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
506 else if (func == elm_entry_filter_accept_set)
508 Elm_Entry_Filter_Accept_Set *as = data, *as2;
515 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
522 as2->accepted = eina_stringshare_add(as->accepted);
524 as2->accepted = NULL;
526 as2->rejected = eina_stringshare_add(as->rejected);
528 as2->rejected = NULL;
537 _filter_free(Elm_Entry_Text_Filter *tf)
539 if (tf->func == elm_entry_filter_limit_size)
541 Elm_Entry_Filter_Limit_Size *lim = tf->data;
544 else if (tf->func == elm_entry_filter_accept_set)
546 Elm_Entry_Filter_Accept_Set *as = tf->data;
549 if (as->accepted) eina_stringshare_del(as->accepted);
550 if (as->rejected) eina_stringshare_del(as->rejected);
558 _del_pre_hook(Evas_Object *obj)
560 Widget_Data *wd = elm_widget_data_get(obj);
564 ecore_timer_del(wd->delay_write);
565 wd->delay_write = NULL;
566 if (wd->autosave) _save(obj);
571 _del_hook(Evas_Object *obj)
573 Widget_Data *wd = elm_widget_data_get(obj);
574 Elm_Entry_Context_Menu_Item *it;
575 Elm_Entry_Item_Provider *ip;
576 Elm_Entry_Text_Filter *tf;
578 if (wd->file) eina_stringshare_del(wd->file);
580 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
581 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
583 entries = eina_list_remove(entries, obj);
584 #ifdef HAVE_ELEMENTARY_X
585 if (wd->sel_notify_handler)
586 ecore_event_handler_del(wd->sel_notify_handler);
587 if (wd->sel_clear_handler)
588 ecore_event_handler_del(wd->sel_clear_handler);
590 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
591 if (wd->text) eina_stringshare_del(wd->text);
592 if (wd->bg) evas_object_del(wd->bg);
593 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
594 if (wd->append_text_idler)
596 ecore_idler_del(wd->append_text_idler);
597 free(wd->append_text_left);
598 wd->append_text_left = NULL;
599 wd->append_text_idler = NULL;
601 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
602 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
603 if (wd->mgf_proxy) evas_object_del(wd->mgf_proxy);
604 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
605 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
607 EINA_LIST_FREE(wd->items, it)
609 eina_stringshare_del(it->label);
610 eina_stringshare_del(it->icon_file);
611 eina_stringshare_del(it->icon_group);
614 EINA_LIST_FREE(wd->item_providers, ip)
618 EINA_LIST_FREE(wd->text_filters, tf)
626 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
628 Widget_Data *wd = elm_widget_data_get(obj);
629 edje_object_mirrored_set(wd->ent, rtl);
633 _theme_hook(Evas_Object *obj)
635 Widget_Data *wd = elm_widget_data_get(obj);
637 Ecore_IMF_Context *ic;
638 _elm_widget_mirrored_reload(obj);
639 _mirrored_set(obj, elm_widget_mirrored_get(obj));
641 t = eina_stringshare_add(elm_entry_entry_get(obj));
642 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
643 if (_elm_config->desktop_entry)
644 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
645 elm_entry_entry_set(obj, t);
646 eina_stringshare_del(t);
647 if (elm_widget_disabled_get(obj))
648 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
649 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
650 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
651 if (elm_widget_focus_get(obj))
652 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
653 edje_object_message_signal_process(wd->ent);
654 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
655 elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
656 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
657 elm_widget_style_get(obj));
663 edj = elm_smart_scroller_edje_object_get(wd->scroller);
664 str = edje_object_data_get(edj, "focus_highlight");
665 if ((str) && (!strcmp(str, "on")))
666 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
668 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
673 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", EINA_FALSE);
674 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", EINA_FALSE);
678 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
679 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
682 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
685 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
692 _disable_hook(Evas_Object *obj)
694 Widget_Data *wd = elm_widget_data_get(obj);
696 if (elm_widget_disabled_get(obj))
698 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
699 wd->disabled = EINA_TRUE;
703 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
704 wd->disabled = EINA_FALSE;
709 _recalc_cursor_geometry(Evas_Object *obj)
711 Widget_Data *wd = elm_widget_data_get(obj);
713 evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
714 if (!wd->deferred_recalc_job)
716 Evas_Coord cx, cy, cw, ch;
717 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
721 elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
722 wd->cur_changed = EINA_FALSE;
726 wd->deferred_cur = EINA_TRUE;
730 _elm_win_recalc_job(void *data)
732 Widget_Data *wd = elm_widget_data_get(data);
733 Evas_Coord minh = -1, resw = -1, minw = -1;
735 wd->deferred_recalc_job = NULL;
737 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
738 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
739 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
742 /* This is a hack to workaround the way min size hints are treated.
743 * If the minimum width is smaller than the restricted width, it means
744 * the mininmum doesn't matter. */
747 Evas_Coord ominw = -1;
748 evas_object_size_hint_min_get(data, &ominw, NULL);
751 evas_object_size_hint_min_set(data, minw, minh);
753 evas_object_size_hint_max_set(data, -1, minh);
755 evas_object_size_hint_max_set(data, -1, -1);
757 if (wd->deferred_cur)
759 Evas_Coord cx, cy, cw, ch;
760 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
764 elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
765 wd->cur_changed = EINA_FALSE;
771 _sizing_eval(Evas_Object *obj)
773 Widget_Data *wd = elm_widget_data_get(obj);
774 Evas_Coord minw = -1, minh = -1;
775 Evas_Coord resw, resh;
778 evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
781 if ((resw == wd->lastw) && (!wd->changed)) return;
782 wd->changed = EINA_FALSE;
786 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
788 evas_object_resize(wd->scroller, resw, resh);
789 edje_object_size_min_calc
790 (elm_smart_scroller_edje_object_get(wd->scroller),
792 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
793 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
796 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
798 if ((minw > 0) && (vw < minw)) vw = minw;
799 if (minh > vh) vh = minh;
801 if (wd->single_line) h = vmh + minh;
803 evas_object_resize(wd->ent, vw, vh);
804 evas_object_size_hint_min_get(obj, &w, NULL);
805 evas_object_size_hint_min_set(obj, w, h);
807 evas_object_size_hint_max_set(obj, -1, h);
809 evas_object_size_hint_max_set(obj, -1, -1);
813 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
814 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
819 if (!wd->changed) return;
820 wd->changed = EINA_FALSE;
824 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
826 edje_object_size_min_calc(wd->ent, &minw, &minh);
829 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
831 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
833 if ((minw > 0) && (vw < minw)) vw = minw;
834 if (minh > 0) vh = minh;
836 evas_object_resize(wd->ent, vw, vh);
837 edje_object_size_min_calc
838 (elm_smart_scroller_edje_object_get(wd->scroller),
840 if (wd->single_line) h = vmh + minh;
842 evas_object_size_hint_min_get(obj, &w, NULL);
843 evas_object_size_hint_min_set(obj, w, h);
845 evas_object_size_hint_max_set(obj, -1, h);
847 evas_object_size_hint_max_set(obj, -1, -1);
851 edje_object_size_min_calc(wd->ent, &minw, &minh);
854 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
855 evas_object_size_hint_min_set(obj, minw, minh);
857 evas_object_size_hint_max_set(obj, -1, minh);
859 evas_object_size_hint_max_set(obj, -1, -1);
863 _recalc_cursor_geometry(obj);
867 _check_enable_returnkey(Evas_Object *obj)
869 Widget_Data *wd = elm_widget_data_get(obj);
872 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
875 if (!wd->autoreturnkey) return;
877 if (_entry_length_get(obj) == 0)
879 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
883 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
888 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
890 Widget_Data *wd = elm_widget_data_get(obj);
891 Evas_Object *top = elm_widget_top_get(obj);
893 if (!wd->editable) return;
894 if (elm_widget_focus_get(obj))
896 printf("[Elm_entry::Focused] obj : %p\n", obj);
897 evas_object_focus_set(wd->ent, EINA_TRUE);
898 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
899 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
900 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
901 _check_enable_returnkey(obj);
902 wd->mgf_type = _ENTRY_MAGNIFIER_FILLWIDTH;
903 _magnifier_create(obj);
907 printf("[Elm_entry::Unfocused] obj : %p\n", obj);
908 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
909 evas_object_focus_set(wd->ent, EINA_FALSE);
910 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
911 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
913 if ((wd->api) && (wd->api->obj_hidemenu))
915 wd->api->obj_hidemenu(obj);
921 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
923 Widget_Data *wd = elm_widget_data_get(obj);
925 edje_object_signal_emit(wd->ent, emission, source);
927 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
932 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
934 Widget_Data *wd = elm_widget_data_get(obj);
936 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
938 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
939 emission, source, func_cb, data);
943 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
945 Widget_Data *wd = elm_widget_data_get(obj);
946 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
949 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
950 emission, source, func_cb, data);
954 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
956 Widget_Data *wd = elm_widget_data_get(obj);
957 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
961 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
963 Widget_Data *wd = elm_widget_data_get(obj);
965 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
969 _show_region_hook(void *data, Evas_Object *obj)
971 Widget_Data *wd = elm_widget_data_get(data);
972 Evas_Coord x, y, w, h;
974 elm_widget_show_region_get(obj, &x, &y, &w, &h);
976 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
980 _hoversel_position(Evas_Object *obj)
982 Widget_Data *wd = elm_widget_data_get(obj);
983 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
988 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
997 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
999 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
1002 cx += (cw - mw) / 2;
1007 cy += (ch - mh) / 2;
1010 evas_object_move(wd->hoversel, x + cx, y + cy);
1011 evas_object_resize(wd->hoversel, cw, ch);
1015 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1017 Widget_Data *wd = elm_widget_data_get(data);
1019 if (wd->hoversel) _hoversel_position(data);
1023 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1025 Widget_Data *wd = elm_widget_data_get(data);
1032 else if (wd->scroll)
1034 Evas_Coord vw = 0, vh = 0;
1036 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
1037 if (vw < wd->entmw) vw = wd->entmw;
1038 if (vh < wd->entmh) vh = wd->entmh;
1039 evas_object_resize(wd->ent, vw, vh);
1041 if (wd->hoversel) _hoversel_position(data);
1045 _hover_del(void *data)
1047 Widget_Data *wd = elm_widget_data_get(data);
1052 evas_object_del(wd->hoversel);
1053 wd->hoversel = NULL;
1055 wd->hovdeljob = NULL;
1059 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1061 Widget_Data *wd = elm_widget_data_get(data);
1064 if (wd->hoversel) evas_object_hide(wd->hoversel);
1067 if (!_elm_config->desktop_entry)
1070 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1073 elm_widget_scroll_freeze_pop(data);
1074 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
1075 wd->hovdeljob = ecore_job_add(_hover_del, data);
1079 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1081 Widget_Data *wd = elm_widget_data_get(data);
1083 wd->selmode = EINA_TRUE;
1084 edje_object_part_text_select_none(wd->ent, "elm.text");
1085 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1086 edje_object_part_text_select_all(wd->ent, "elm.text");
1087 elm_object_scroll_freeze_pop(data);
1091 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1093 Widget_Data *wd = elm_widget_data_get(data);
1095 wd->selmode = EINA_TRUE;
1096 edje_object_part_text_select_none(wd->ent, "elm.text");
1097 if (!_elm_config->desktop_entry)
1100 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1102 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1103 if (!_elm_config->desktop_entry)
1104 elm_object_scroll_freeze_pop(data);
1105 //elm_widget_scroll_hold_push(data);
1109 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1111 Widget_Data *wd = elm_widget_data_get(data);
1113 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1114 if (wd->sel_notify_handler)
1116 #ifdef HAVE_ELEMENTARY_X
1117 Elm_Sel_Format formats;
1118 wd->selection_asked = EINA_TRUE;
1119 formats = ELM_SEL_FORMAT_MARKUP;
1121 formats |= ELM_SEL_FORMAT_IMAGE;
1122 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
1128 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1130 Widget_Data *wd = elm_widget_data_get(obj);
1134 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1135 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
1136 if (seltype == ELM_SEL_CLIPBOARD)
1137 eina_stringshare_replace(&wd->cut_sel, sel);
1141 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1143 Widget_Data *wd = elm_widget_data_get(data);
1146 wd->selmode = EINA_FALSE;
1147 if (!_elm_config->desktop_entry)
1148 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1149 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1150 if (!_elm_config->desktop_entry)
1151 elm_widget_scroll_hold_pop(data);
1152 _store_selection(ELM_SEL_CLIPBOARD, data);
1153 edje_object_part_text_insert(wd->ent, "elm.text", "");
1154 edje_object_part_text_select_none(wd->ent, "elm.text");
1158 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1160 Widget_Data *wd = elm_widget_data_get(data);
1162 wd->selmode = EINA_FALSE;
1163 if (!_elm_config->desktop_entry)
1165 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1166 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1167 elm_widget_scroll_hold_pop(data);
1169 _store_selection(ELM_SEL_CLIPBOARD, data);
1170 // edje_object_part_text_select_none(wd->ent, "elm.text");
1174 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1176 Widget_Data *wd = elm_widget_data_get(data);
1178 wd->selmode = EINA_FALSE;
1179 if (!_elm_config->desktop_entry)
1180 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1181 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1182 if (!_elm_config->desktop_entry)
1183 elm_widget_scroll_hold_pop(data);
1184 edje_object_part_text_select_none(wd->ent, "elm.text");
1188 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
1190 Widget_Data *wd = elm_widget_data_get(data);
1194 #ifdef HAVE_ELEMENTARY_X
1195 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
1197 cnpwidgetdata = data;
1198 elm_cbhm_helper_init(obj);
1199 if (elm_entry_cnp_textonly_get(obj))
1200 elm_cbhm_send_raw_data("show0");
1202 elm_cbhm_send_raw_data("show1");
1208 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1210 Widget_Data *wd = elm_widget_data_get(data);
1212 cnpwidgetdata = data;
1218 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1220 Elm_Entry_Context_Menu_Item *it = data;
1221 Evas_Object *obj2 = it->obj;
1222 if (it->func) it->func(it->data, obj2, NULL);
1226 _menu_press(Evas_Object *obj)
1228 Widget_Data *wd = elm_widget_data_get(obj);
1231 const Elm_Entry_Context_Menu_Item *it;
1233 if ((wd->api) && (wd->api->obj_longpress))
1235 wd->api->obj_longpress(obj);
1237 else if (wd->context_menu)
1239 const char *context_menu_orientation;
1241 if (wd->hoversel) evas_object_del(wd->hoversel);
1242 else elm_widget_scroll_freeze_push(obj);
1243 wd->hoversel = elm_hoversel_add(obj);
1244 context_menu_orientation = edje_object_data_get
1245 (wd->ent, "context_menu_orientation");
1246 if ((context_menu_orientation) &&
1247 (!strcmp(context_menu_orientation, "horizontal")))
1248 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1249 elm_object_style_set(wd->hoversel, "entry");
1250 elm_widget_sub_object_add(obj, wd->hoversel);
1251 elm_object_text_set(wd->hoversel, "Text");
1252 top = elm_widget_top_get(obj);
1253 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1254 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1258 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1260 if (1) // need way to detect if someone has a selection
1263 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1267 if ((!wd->password) && (wd->editable))
1268 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1269 _clipboard_menu, obj);
1276 if (wd->have_selection)
1278 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1281 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1284 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1288 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1289 _clipboard_menu, obj);
1293 EINA_LIST_FOREACH(wd->items, l, it)
1295 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1296 it->icon_type, _item_clicked, it);
1300 _hoversel_position(obj);
1301 evas_object_show(wd->hoversel);
1302 elm_hoversel_hover_begin(wd->hoversel);
1304 if (!_elm_config->desktop_entry)
1306 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1307 edje_object_part_text_select_abort(wd->ent, "elm.text");
1313 _magnifier_hide(void *data)
1315 Widget_Data *wd = elm_widget_data_get(data);
1318 evas_object_hide(wd->mgf_bg);
1319 evas_object_hide(wd->mgf_clip);
1322 elm_smart_scroller_freeze_set(wd->scroller, EINA_FALSE);
1326 _magnifier_show(void *data)
1328 Widget_Data *wd = elm_widget_data_get(data);
1331 evas_object_show(wd->mgf_bg);
1332 evas_object_show(wd->mgf_clip);
1336 _magnifier_move(void *data)
1338 Widget_Data *wd = elm_widget_data_get(data);
1341 Evas_Coord x, y, w, h, fs;
1342 Evas_Coord cx, cy, cw, ch, ox, oy;
1344 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1348 evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1349 elm_smart_scroller_child_pos_get(wd->scroller, &ox, &oy);
1354 evas_object_geometry_get(data, &x, &y, &w, &h);
1357 fs = elm_finger_size_get();
1359 if ((cy + y) - wd->mgf_height - fs < 0)
1360 oy = -1 * ((cy + y) - wd->mgf_height - fs);
1362 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1363 evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1364 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1365 evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1369 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);
1373 _magnifier_create(void *data)
1375 Widget_Data *wd = elm_widget_data_get(data);
1376 Evas_Coord x, y, w, h;
1377 const char* key_data = NULL;
1383 evas_object_image_source_unset(wd->mgf_proxy);
1384 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1385 evas_object_hide(wd->mgf_proxy);
1386 evas_object_clip_unset(wd->mgf_proxy);
1387 evas_object_del(wd->mgf_proxy);
1389 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1390 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1393 evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1395 evas_object_geometry_get(data, &x, &y, &w, &h);
1397 wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1399 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1400 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1401 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1402 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1406 wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1407 evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1408 edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1410 key_data = edje_object_data_get(wd->mgf_bg, "height");
1411 if (key_data) wd->mgf_height = atoi(key_data);
1412 key_data = edje_object_data_get(wd->mgf_bg, "scale");
1413 if (key_data) wd->mgf_scale = atof(key_data);
1415 if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1416 evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1420 elm_smart_scroller_freeze_set(wd->scroller, EINA_TRUE);
1421 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(wd->scroller));
1422 evas_object_image_source_set(wd->mgf_proxy, wd->scroller);
1426 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1427 evas_object_image_source_set(wd->mgf_proxy, data);
1429 evas_object_resize(wd->mgf_proxy, w * wd->mgf_scale, h * wd->mgf_scale);
1430 evas_object_image_fill_set(wd->mgf_proxy, 0, 0, w * wd->mgf_scale, h * wd->mgf_scale);
1431 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1432 evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1433 evas_object_show(wd->mgf_proxy);
1434 evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1436 evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1437 evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1441 _long_press(void *data)
1443 Widget_Data *wd = elm_widget_data_get(data);
1444 if (!wd) return ECORE_CALLBACK_CANCEL;
1446 wd->long_pressed = EINA_TRUE;
1448 if (wd->longpress_timer)
1450 ecore_timer_del(wd->longpress_timer);
1451 wd->longpress_timer = NULL;
1454 _cancel(data, NULL, NULL);
1456 _magnifier_create(data);
1457 _magnifier_move(data);
1458 _magnifier_show(data);
1459 elm_object_scroll_freeze_push(data);
1461 wd->longpress_timer = NULL;
1462 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1463 return ECORE_CALLBACK_CANCEL;
1467 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1469 Widget_Data *wd = elm_widget_data_get(data);
1470 Evas_Event_Mouse_Down *ev = event_info;
1472 if (wd->disabled) return;
1473 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1474 wd->downx = ev->canvas.x;
1475 wd->downy = ev->canvas.y;
1476 wd->long_pressed = EINA_FALSE;
1477 if (ev->button == 1)
1479 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1480 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1485 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1487 Widget_Data *wd = elm_widget_data_get(data);
1488 Evas_Event_Mouse_Up *ev = event_info;
1490 if (wd->disabled) return;
1491 if (ev->button == 1)
1493 if (!wd->double_clicked)
1495 if ((wd->api) && (wd->api->obj_mouseup))
1497 wd->api->obj_mouseup(data);
1501 if (wd->longpress_timer)
1503 ecore_timer_del(wd->longpress_timer);
1504 wd->longpress_timer = NULL;
1507 _magnifier_hide(data);
1508 elm_object_scroll_freeze_pop(data);
1510 if (wd->long_pressed)
1516 else if (ev->button == 3)
1524 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1526 Widget_Data *wd = elm_widget_data_get(data);
1527 Evas_Event_Mouse_Move *ev = event_info;
1529 if (wd->disabled) return;
1532 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1534 if (wd->longpress_timer)
1536 ecore_timer_del(wd->longpress_timer);
1537 wd->longpress_timer = NULL;
1540 else if (wd->longpress_timer)
1544 dx = wd->downx - ev->cur.canvas.x;
1546 dy = wd->downy - ev->cur.canvas.y;
1549 ((_elm_config->finger_size / 2) *
1550 (_elm_config->finger_size / 2)))
1552 ecore_timer_del(wd->longpress_timer);
1553 wd->longpress_timer = NULL;
1557 else if (wd->longpress_timer)
1561 dx = wd->downx - ev->cur.canvas.x;
1563 dy = wd->downy - ev->cur.canvas.y;
1566 ((_elm_config->finger_size / 2) *
1567 (_elm_config->finger_size / 2)))
1569 ecore_timer_del(wd->longpress_timer);
1570 wd->longpress_timer = NULL;
1574 if (ev->buttons == 1)
1576 if (wd->long_pressed)
1578 _magnifier_show(data);
1579 _magnifier_move(data);
1585 _getbase(Evas_Object *obj)
1587 Widget_Data *wd = elm_widget_data_get(obj);
1588 if (!wd) return "base";
1591 if (wd->password) return "base-password";
1594 if (wd->single_line) return "base-single";
1597 switch (wd->linewrap)
1600 return "base-charwrap";
1603 case ELM_WRAP_MIXED:
1604 return "base-mixedwrap";
1607 return "base-nowrap";
1614 if (wd->password) return "base-password";
1617 if (wd->single_line) return "base-single-noedit";
1620 switch (wd->linewrap)
1623 return "base-noedit-charwrap";
1625 return "base-noedit";
1626 case ELM_WRAP_MIXED:
1627 return "base-noedit-mixedwrap";
1630 return "base-nowrap-noedit";
1640 _entry_length_get(Evas_Object *obj)
1643 const char *str = elm_entry_entry_get(obj);
1646 char *plain_str = _elm_util_mkup_to_text(str);
1647 if (!plain_str) return 0;
1649 len = strlen(plain_str);
1656 _matchlist_show(void *data)
1658 Widget_Data *wd = elm_widget_data_get(data);
1659 const char *text = NULL;
1661 char *str_list = NULL, *str_result = NULL;
1662 char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1665 Eina_Bool textfound = EINA_FALSE;
1668 if (elm_widget_disabled_get(data)) return;
1670 wd->matchlist_job = NULL;
1672 if (wd->matchlist_list_clicked)
1674 evas_object_hide(wd->hover);
1675 wd->matchlist_list_clicked = EINA_FALSE;
1678 text = elm_entry_entry_get(data);
1681 textlen = strlen(text);
1683 if (textlen < wd->matchlist_threshold)
1685 evas_object_hide(wd->hover);
1689 evas_object_hide(wd->hover);
1693 elm_list_clear(wd->list);
1694 EINA_LIST_FOREACH(wd->match_list, l, str_list)
1696 if (wd->matchlist_case_sensitive)
1697 str_result = strstr(str_list, text);
1699 str_result = strcasestr(str_list, text);
1703 str_mkup = malloc(strlen(str_list) + 16);
1704 if (str_mkup == NULL) return;
1706 textlen = strlen(str_list) - strlen(str_result);
1707 str_front = malloc(textlen + 1);
1708 if (str_front == NULL) return;
1710 memset(str_front, 0, textlen + 1);
1711 strncpy(str_front, str_list, textlen);
1713 textlen = strlen(text);
1714 str_mid = malloc(textlen + 1);
1715 if (str_mid == NULL) return;
1717 memset(str_mid, 0, textlen + 1);
1718 strncpy(str_mid, str_list + strlen(str_front), textlen);
1720 sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1722 elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1724 if (str_mkup) free(str_mkup);
1725 if (str_front) free(str_front);
1726 if (str_mid) free(str_mid);
1728 textfound=EINA_TRUE;
1737 elm_list_go(wd->list);
1738 evas_object_show(wd->hover);
1739 evas_object_raise(wd->hover);
1743 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1745 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1746 Widget_Data *wd = elm_widget_data_get(data);
1747 if ((it == NULL) || (wd == NULL))
1750 const char *text = elm_list_item_label_get(it);
1751 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1756 elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1757 elm_entry_cursor_end_set(data);
1758 wd->matchlist_list_clicked = EINA_TRUE;
1760 evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1763 elm_widget_focus_set(data, EINA_TRUE);
1767 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
1769 Widget_Data *wd = elm_widget_data_get(obj);
1774 Evas_Coord max_w = 9999, max_h = 9999;
1775 const char* key_data = NULL;
1777 wd->matchlist_threshold = 1;
1778 wd->hover = elm_hover_add(elm_widget_parent_get(obj));
1779 elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
1780 elm_hover_target_set(wd->hover, obj);
1781 elm_object_style_set(wd->hover, "matchlist");
1783 wd->layout = elm_layout_add(wd->hover);
1784 elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
1785 wd->list = elm_list_add(wd->layout);
1786 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
1787 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1788 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1789 elm_object_style_set(wd->list, "matchlist");
1791 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
1792 if (key_data) max_w = atoi(key_data);
1793 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
1794 if (key_data) max_h = atoi(key_data);
1796 elm_list_go(wd->list);
1797 evas_object_size_hint_max_set(wd->list, max_w, max_h);
1798 evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
1799 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
1800 elm_hover_content_set(wd->hover, "bottom", wd->layout);
1802 wd->match_list = match_list;
1807 evas_object_del(wd->hover);
1809 wd->match_list = NULL;
1812 wd->matchlist_case_sensitive = case_sensitive;
1816 _entry_changed_common_handling(void *data, const char *event)
1818 Widget_Data *wd = elm_widget_data_get(data);
1819 Evas_Coord minw, minh;
1821 wd->changed = EINA_TRUE;
1822 /* Reset the size hints which are no more relevant.
1823 * Keep the height, this is a hack, but doesn't really matter
1824 * cause we'll re-eval in a moment. */
1827 evas_object_size_hint_min_get(data, &minw, &minh);
1828 evas_object_size_hint_min_set(data, minw, minh);
1832 evas_object_size_hint_min_get(data, NULL, &minh);
1833 evas_object_size_hint_min_set(data, -1, minh);
1837 if (wd->text) eina_stringshare_del(wd->text);
1839 _check_enable_returnkey(data);
1840 evas_object_smart_callback_call(data, event, NULL);
1841 if (wd->delay_write)
1843 ecore_timer_del(wd->delay_write);
1844 wd->delay_write = NULL;
1847 if ((wd->single_line) && (wd->match_list))
1849 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1850 wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1852 if ((!wd->autosave) || (!wd->file)) return;
1853 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1857 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1859 _entry_changed_common_handling(data, SIG_CHANGED);
1863 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1865 _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1870 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1872 Widget_Data *wd = elm_widget_data_get(data);
1873 elm_object_scroll_freeze_push(data);
1875 if ((wd->api) && (wd->api->obj_hidemenu))
1877 wd->api->obj_hidemenu(data);
1880 _magnifier_create(data);
1881 _magnifier_move(data);
1882 _magnifier_show(data);
1886 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1888 Widget_Data *wd = elm_widget_data_get(data);
1889 elm_object_scroll_freeze_pop(data);
1891 if (wd->have_selection)
1893 _magnifier_hide(data);
1899 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1901 _magnifier_move(data);
1902 _magnifier_show(data);
1906 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1908 _magnifier_hide(data);
1913 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1915 Widget_Data *wd = elm_widget_data_get(data);
1919 EINA_LIST_FOREACH(entries, l, entry)
1921 if (entry != data) elm_entry_select_none(entry);
1923 wd->have_selection = EINA_TRUE;
1924 wd->selmode = EINA_TRUE;
1925 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1926 #ifdef HAVE_ELEMENTARY_X
1927 if (wd->sel_notify_handler)
1929 const char *txt = elm_entry_selection_get(data);
1932 top = elm_widget_top_get(data);
1933 if ((top) && (elm_win_xwindow_get(top)))
1934 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1940 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1942 Evas_Coord cx, cy, cw, ch;
1943 Widget_Data *wd = elm_widget_data_get(data);
1946 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1947 if (!wd->deferred_recalc_job)
1948 elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
1951 wd->deferred_cur = EINA_TRUE;
1955 wd->ch = ch + elm_finger_size_get();
1960 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1962 Evas_Coord cx, cy, cw, ch;
1963 Widget_Data *wd = elm_widget_data_get(data);
1965 wd->have_selection = EINA_TRUE;
1966 wd->selmode = EINA_TRUE;
1967 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1968 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1969 elm_entry_selection_get(data));
1971 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1972 if (!wd->deferred_recalc_job)
1973 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get(), EINA_FALSE);
1976 wd->deferred_cur = EINA_TRUE;
1980 wd->ch = ch + elm_finger_size_get();
1985 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1987 Widget_Data *wd = elm_widget_data_get(data);
1989 if (!wd->have_selection) return;
1990 wd->have_selection = EINA_FALSE;
1991 wd->selmode = EINA_FALSE;
1992 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1993 if (wd->sel_notify_handler)
1997 #ifdef HAVE_ELEMENTARY_X
2000 top = elm_widget_top_get(data);
2001 if ((top) && (elm_win_xwindow_get(top)))
2002 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
2005 eina_stringshare_del(wd->cut_sel);
2010 #ifdef HAVE_ELEMENTARY_X
2013 top = elm_widget_top_get(data);
2014 if ((top) && (elm_win_xwindow_get(top)))
2015 elm_selection_clear(ELM_SEL_PRIMARY, data);
2020 if ((wd->api) && (wd->api->obj_hidemenu))
2022 wd->api->obj_hidemenu(data);
2027 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2029 Widget_Data *wd = elm_widget_data_get(data);
2031 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2032 if (wd->sel_notify_handler)
2034 #ifdef HAVE_ELEMENTARY_X
2037 top = elm_widget_top_get(data);
2038 if ((top) && (elm_win_xwindow_get(top)))
2040 wd->selection_asked = EINA_TRUE;
2041 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
2049 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2051 Widget_Data *wd = elm_widget_data_get(data);
2053 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
2054 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2055 elm_entry_selection_get(data));
2059 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2061 Widget_Data *wd = elm_widget_data_get(data);
2063 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
2064 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2065 elm_entry_selection_get(data));
2066 edje_object_part_text_insert(wd->ent, "elm.text", "");
2067 wd->changed = EINA_TRUE;
2072 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2074 Widget_Data *wd = elm_widget_data_get(data);
2076 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2077 wd->cur_changed = EINA_TRUE;
2078 _recalc_cursor_geometry(data);
2082 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2084 Widget_Data *wd = elm_widget_data_get(data);
2089 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2091 Widget_Data *wd = elm_widget_data_get(data);
2096 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
2098 Widget_Data *wd = elm_widget_data_get(data);
2099 Elm_Entry_Anchor_Info ei;
2100 char *buf2, *p, *p2, *n;
2102 p = strrchr(emission, ',');
2105 const Eina_List *geoms;
2109 while (p2 >= emission)
2111 if (*p2 == ',') break;
2115 buf2 = alloca(5 + p - p2);
2116 strncpy(buf2, p2, p - p2);
2119 ei.button = atoi(buf2);
2120 ei.x = ei.y = ei.w = ei.h = 0;
2122 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
2125 Evas_Textblock_Rectangle *r;
2127 Evas_Coord px, py, x, y;
2129 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
2130 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
2131 EINA_LIST_FOREACH(geoms, l, r)
2133 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
2134 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
2145 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
2150 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2152 Widget_Data *wd = elm_widget_data_get(data);
2157 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2159 Widget_Data *wd = elm_widget_data_get(data);
2164 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2166 Widget_Data *wd = elm_widget_data_get(data);
2171 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2173 Widget_Data *wd = elm_widget_data_get(data);
2175 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
2179 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2181 Widget_Data *wd = elm_widget_data_get(data);
2183 wd->double_clicked = EINA_FALSE;
2184 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
2186 if ((wd->api) && (wd->api->obj_hidemenu))
2188 wd->api->obj_hidemenu(data);
2193 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2195 Widget_Data *wd = elm_widget_data_get(data);
2197 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
2201 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2203 Widget_Data *wd = elm_widget_data_get(data);
2205 wd->double_clicked = EINA_TRUE;
2206 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
2209 #ifdef HAVE_ELEMENTARY_X
2211 _event_selection_notify(void *data, int type __UNUSED__, void *event)
2213 Widget_Data *wd = elm_widget_data_get(data);
2214 Ecore_X_Event_Selection_Notify *ev = event;
2215 if (!wd) return ECORE_CALLBACK_PASS_ON;
2216 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
2217 return ECORE_CALLBACK_PASS_ON;
2219 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2220 (ev->selection == ECORE_X_SELECTION_PRIMARY))
2222 Ecore_X_Selection_Data_Text *text_data;
2224 text_data = ev->data;
2225 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2227 if (text_data->text)
2229 char *txt = _elm_util_text_to_mkup(text_data->text);
2233 elm_entry_entry_insert(data, txt);
2238 wd->selection_asked = EINA_FALSE;
2240 else if (ev->selection == ECORE_X_SELECTION_XDND)
2242 Ecore_X_Selection_Data_Text *text_data;
2244 text_data = ev->data;
2245 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2247 if (text_data->text)
2249 char *txt = _elm_util_text_to_mkup(text_data->text);
2253 /* Massive FIXME: this should be at the drag point */
2254 elm_entry_entry_insert(data, txt);
2259 wd->drag_selection_asked = EINA_FALSE;
2261 ecore_x_dnd_send_finished();
2264 return ECORE_CALLBACK_PASS_ON;
2268 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2271 Widget_Data *wd = elm_widget_data_get(data);
2272 Ecore_X_Event_Selection_Clear *ev = event;
2273 if (!wd) return ECORE_CALLBACK_PASS_ON;
2274 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2275 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2276 (ev->selection == ECORE_X_SELECTION_PRIMARY))
2278 elm_entry_select_none(data);
2283 Evas_Object *top = elm_widget_top_get(data);
2284 Ecore_X_Event_Selection_Clear *ev = event;
2287 return ECORE_CALLBACK_PASS_ON;
2289 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2291 return ECORE_CALLBACK_PASS_ON;
2294 if (cnpwidgetdata == data)
2296 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
2300 return ECORE_CALLBACK_PASS_ON;
2304 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2309 wd = elm_widget_data_get(obj);
2310 if (!wd) return EINA_FALSE;
2311 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
2313 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2314 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2315 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2316 EDJE_CURSOR_MAIN,drop->x,drop->y);
2317 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2318 elm_entry_entry_insert(obj, drop->data);
2319 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2320 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2326 static Evas_Object *
2327 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2329 Widget_Data *wd = elm_widget_data_get(data);
2332 Elm_Entry_Item_Provider *ip;
2334 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2336 o = ip->func(ip->data, data, item);
2339 if (!strncmp(item, "file://", 7))
2341 const char *fname = item + 7;
2343 o = evas_object_image_filled_add(evas_object_evas_get(data));
2344 evas_object_image_file_set(o, fname, NULL);
2345 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2347 evas_object_show(o);
2352 o = edje_object_add(evas_object_evas_get(data));
2353 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2357 o = edje_object_add(evas_object_evas_get(data));
2358 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2359 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2364 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2366 const char *srcstring = NULL;
2367 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2368 char *curlocater, *replocater;
2369 char *starttag, *endtag;
2370 int tagtxtlen = 0, insertflag = 0;
2372 srcstring = eina_strbuf_string_get(srcbuf);
2373 curlocater = strstr(srcstring, key);
2375 if (!curlocater || !srcstring)
2383 starttag = strchr(srcstring, '<');
2384 endtag = strchr(srcstring, '>');
2385 tagtxtlen = endtag - starttag;
2386 if (tagtxtlen <= 0) tagtxtlen = 0;
2387 if (starttag < curlocater && curlocater < endtag) break;
2388 if (endtag != NULL && endtag+1 != NULL)
2389 srcstring = endtag+1;
2392 } while (strlen(srcstring) > 1);
2394 if (starttag && endtag && tagtxtlen > strlen(key))
2396 repbuf = eina_strbuf_new();
2397 diffbuf = eina_strbuf_new();
2398 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2399 srcstring = eina_strbuf_string_get(repbuf);
2400 curlocater = strstr(srcstring, key);
2402 if (curlocater != NULL)
2404 replocater = curlocater + strlen(key) + 1;
2406 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2409 if (replocater-curlocater > strlen(key)+1)
2411 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2420 eina_strbuf_reset(repbuf);
2428 if (repbuf == NULL) repbuf = eina_strbuf_new();
2429 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2433 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2434 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2440 eina_strbuf_prepend(diffbuf, "<");
2441 eina_strbuf_append(diffbuf, ">");
2442 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2446 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2447 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2451 if (repbuf) eina_strbuf_free(repbuf);
2452 if (diffbuf) eina_strbuf_free(diffbuf);
2458 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2460 Eina_Strbuf *sharebuf = NULL;
2462 sharebuf = eina_strbuf_new();
2463 eina_strbuf_append(sharebuf, *srcstring);
2464 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2465 eina_stringshare_del(*srcstring);
2466 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2467 eina_strbuf_free(sharebuf);
2473 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2475 Widget_Data *wd = elm_widget_data_get(data);
2477 Elm_Entry_Text_Filter *tf;
2479 if (type == EDJE_TEXT_FILTER_FORMAT)
2482 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2484 tf->func(tf->data, data, text);
2490 /* This function is used to insert text by chunks in jobs */
2492 _text_append_idler(void *data)
2496 Evas_Object *obj = (Evas_Object *) data;
2497 Widget_Data *wd = elm_widget_data_get(obj);
2498 if (wd->text) eina_stringshare_del(wd->text);
2500 wd->changed = EINA_TRUE;
2502 start = wd->append_text_position;
2503 if(start + _CHUNK_SIZE < wd->append_text_len)
2505 wd->append_text_position = (start + _CHUNK_SIZE);
2506 /* Go to the start of the nearest codepoint, because we don't want
2507 * to cut it in the middle */
2508 eina_unicode_utf8_get_prev(wd->append_text_left,
2509 &wd->append_text_position);
2513 wd->append_text_position = wd->append_text_len;
2516 backup = wd->append_text_left[wd->append_text_position];
2517 wd->append_text_left[wd->append_text_position] = '\0';
2519 edje_object_part_text_append(wd->ent, "elm.text",
2520 wd->append_text_left + start);
2522 wd->append_text_left[wd->append_text_position] = backup;
2524 /* If there's still more to go, renew the idler, else, cleanup */
2525 if (wd->append_text_position < wd->append_text_len)
2527 return ECORE_CALLBACK_RENEW;
2531 free(wd->append_text_left);
2532 wd->append_text_left = NULL;
2533 wd->append_text_idler = NULL;
2534 return ECORE_CALLBACK_CANCEL;
2539 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2541 int i = 0, unit_size;
2542 int current_len = strlen(*text);
2543 char *new_text = *text;
2544 if (unit >= LENGTH_UNIT_LAST) return;
2547 if (*new_text == '<')
2549 while (*new_text != '>')
2552 if (!*new_text) break;
2559 if (*new_text == '&')
2561 while (*(new_text + index) != ';')
2564 if (!*(new_text + index)) break;
2568 index = evas_string_char_next_get(new_text, index, NULL);
2569 markup = malloc(index + 1);
2570 strncpy(markup, new_text, index);
2572 if (unit == LENGTH_UNIT_BYTE)
2573 unit_size = strlen(elm_entry_markup_to_utf8(markup));
2574 else if (unit == LENGTH_UNIT_CHAR)
2575 unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
2581 if (can_add < unit_size)
2585 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2591 strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
2592 current_len -= index;
2593 (*text)[current_len] = 0;
2598 can_add -= unit_size;
2603 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2607 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2610 ELM_CHECK_WIDTYPE(obj, widtype);
2611 if (item && strcmp(item, "default")) return;
2612 Widget_Data *wd = elm_widget_data_get(obj);
2614 if (!entry) entry = "";
2615 if (wd->text) eina_stringshare_del(wd->text);
2617 wd->changed = EINA_TRUE;
2619 /* Clear currently pending job if there is one */
2620 if (wd->append_text_idler)
2622 ecore_idler_del(wd->append_text_idler);
2623 free(wd->append_text_left);
2624 wd->append_text_left = NULL;
2625 wd->append_text_idler = NULL;
2628 len = strlen(entry);
2629 /* Split to ~_CHUNK_SIZE chunks */
2630 if (len > _CHUNK_SIZE)
2632 wd->append_text_left = (char *) malloc(len + 1);
2635 /* If we decided to use the idler */
2636 if (wd->append_text_left)
2638 /* Need to clear the entry first */
2639 edje_object_part_text_set(wd->ent, "elm.text", "");
2640 memcpy(wd->append_text_left, entry, len + 1);
2641 wd->append_text_position = 0;
2642 wd->append_text_len = len;
2643 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2647 edje_object_part_text_set(wd->ent, "elm.text", entry);
2652 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2654 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2655 Widget_Data *wd = elm_widget_data_get(obj);
2656 if (item && strcmp(item, "default")) return NULL;
2658 if (!wd) return NULL;
2662 return elm_entry_markup_to_utf8(wd->text);
2666 text = edje_object_part_text_get(wd->ent, "elm.text");
2669 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2672 eina_stringshare_replace(&wd->text, text);
2673 if (wd->password) return elm_entry_markup_to_utf8(wd->text);
2678 * This adds an entry to @p parent object.
2680 * @param parent The parent object
2681 * @return The new object or NULL if it cannot be created
2686 elm_entry_add(Evas_Object *parent)
2688 Evas_Object *obj, *top;
2692 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2694 ELM_SET_WIDTYPE(widtype, "entry");
2695 elm_widget_type_set(obj, "entry");
2696 elm_widget_sub_object_add(parent, obj);
2697 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2698 elm_widget_data_set(obj, wd);
2699 elm_widget_del_hook_set(obj, _del_hook);
2700 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2701 elm_widget_theme_hook_set(obj, _theme_hook);
2702 elm_widget_disable_hook_set(obj, _disable_hook);
2703 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2704 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2705 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2706 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2707 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2708 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2709 elm_widget_can_focus_set(obj, EINA_TRUE);
2710 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2711 elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2712 elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2714 wd->scroller = elm_smart_scroller_add(e);
2715 elm_widget_sub_object_add(obj, wd->scroller);
2716 elm_smart_scroller_widget_set(wd->scroller, obj);
2717 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
2718 elm_widget_style_get(obj));
2719 evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2720 evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
2721 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2722 elm_smart_scroller_propagate_events_set(wd->scroller, EINA_TRUE);
2724 wd->linewrap = ELM_WRAP_WORD;
2725 wd->editable = EINA_TRUE;
2726 wd->disabled = EINA_FALSE;
2727 wd->context_menu = EINA_TRUE;
2728 wd->autosave = EINA_TRUE;
2729 wd->textonly = EINA_FALSE;
2730 wd->autoperiod = EINA_TRUE;
2732 wd->ent = edje_object_add(e);
2733 elm_widget_sub_object_add(obj, wd->ent);
2734 edje_object_item_provider_set(wd->ent, _get_item, obj);
2735 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2736 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2737 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2739 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2741 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2743 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2745 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2746 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2747 _signal_entry_changed, obj);
2748 edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2749 _signal_preedit_changed, obj);
2750 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2751 _signal_handler_move_start, obj);
2752 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2753 _signal_handler_move_end, obj);
2754 edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2755 _signal_handler_moving, obj);
2756 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2757 _signal_selection_start, obj);
2758 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2759 _signal_selection_end, obj);
2760 edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2761 _signal_magnifier_changed, obj);
2762 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2763 _signal_selection_changed, obj);
2764 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2765 _signal_selection_cleared, obj);
2766 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2767 _signal_entry_paste_request, obj);
2768 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2769 _signal_entry_copy_notify, obj);
2770 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2771 _signal_entry_cut_notify, obj);
2772 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2773 _signal_cursor_changed, obj);
2774 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2775 _signal_anchor_down, obj);
2776 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2777 _signal_anchor_up, obj);
2778 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2779 _signal_anchor_clicked, obj);
2780 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2781 _signal_anchor_move, obj);
2782 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2783 _signal_anchor_in, obj);
2784 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2785 _signal_anchor_out, obj);
2786 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2787 _signal_key_enter, obj);
2788 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2789 _signal_mouse_down, obj);
2790 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2791 _signal_mouse_clicked, obj);
2792 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2793 _signal_mouse_double, obj);
2794 edje_object_part_text_set(wd->ent, "elm.text", "");
2795 if (_elm_config->desktop_entry)
2796 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2797 elm_widget_resize_object_set(obj, wd->ent);
2800 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2802 #ifdef HAVE_ELEMENTARY_X
2803 top = elm_widget_top_get(obj);
2804 if ((top) && (elm_win_xwindow_get(top)))
2806 wd->sel_notify_handler =
2807 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2808 _event_selection_notify, obj);
2809 wd->sel_clear_handler =
2810 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2811 _event_selection_clear, obj);
2814 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2815 _drag_drop_cb, NULL);
2818 entries = eina_list_prepend(entries, obj);
2820 // module - find module for entry
2821 wd->api = _module(obj);
2822 // if found - hook in
2823 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2825 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2826 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2827 // TODO: and save some bytes, making descriptions per-class and not instance!
2828 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2832 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2834 ELM_CHECK_WIDTYPE(obj, widtype);
2835 Widget_Data *wd = elm_widget_data_get(obj);
2837 ext_mod->cancel = _cancel;
2838 ext_mod->copy = _copy;
2839 ext_mod->cut = _cut;
2840 ext_mod->paste = _paste;
2841 ext_mod->select = _select;
2842 ext_mod->selectall = _selectall;
2843 ext_mod->ent = wd->ent;
2844 ext_mod->items = wd->items;
2845 ext_mod->longpress_timer = wd->longpress_timer;
2846 ext_mod->editable = wd->editable;
2847 ext_mod->have_selection = wd->have_selection;
2848 ext_mod->password = wd->password;
2849 ext_mod->selmode = wd->selmode;
2850 ext_mod->cnpinit = _cnpinit;
2851 ext_mod->context_menu = wd->context_menu;
2852 ext_mod->textonly = wd->textonly;
2856 * This sets the entry object not to line wrap. All input will
2857 * be on a single line, and the entry box will extend with user input.
2859 * @param obj The entry object
2860 * @param single_line If true, the text in the entry
2861 * will be on a single line.
2866 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2868 ELM_CHECK_WIDTYPE(obj, widtype);
2869 Widget_Data *wd = elm_widget_data_get(obj);
2871 if (wd->single_line == single_line) return;
2872 wd->single_line = single_line;
2873 wd->linewrap = ELM_WRAP_NONE;
2874 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2878 if (wd->single_line)
2880 elm_smart_scroller_policy_set(wd->scroller,
2881 ELM_SMART_SCROLLER_POLICY_OFF,
2882 ELM_SMART_SCROLLER_POLICY_OFF);
2883 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2887 const Elm_Scroller_Policy map[3] =
2889 ELM_SMART_SCROLLER_POLICY_AUTO,
2890 ELM_SMART_SCROLLER_POLICY_ON,
2891 ELM_SMART_SCROLLER_POLICY_OFF
2893 elm_smart_scroller_policy_set(wd->scroller,
2896 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2903 * This returns true if the entry has been set to single line mode.
2904 * See also elm_entry_single_line_set().
2906 * @param obj The entry object
2907 * @return single_line If true, the text in the entry is set to display
2913 elm_entry_single_line_get(const Evas_Object *obj)
2915 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2916 Widget_Data *wd = elm_widget_data_get(obj);
2917 if (!wd) return EINA_FALSE;
2918 return wd->single_line;
2922 * This sets the entry object to password mode. All text entered
2923 * and/or displayed within the widget will be replaced with asterisks (*).
2925 * @param obj The entry object
2926 * @param password If true, password mode is enabled.
2931 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2933 ELM_CHECK_WIDTYPE(obj, widtype);
2934 Widget_Data *wd = elm_widget_data_get(obj);
2936 if (wd->password == password) return;
2937 wd->password = password;
2938 wd->single_line = EINA_TRUE;
2939 wd->linewrap = ELM_WRAP_NONE;
2944 * This returns whether password mode is enabled.
2945 * See also elm_entry_password_set().
2947 * @param obj The entry object
2948 * @return If true, the entry is set to display all characters
2954 elm_entry_password_get(const Evas_Object *obj)
2956 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2957 Widget_Data *wd = elm_widget_data_get(obj);
2958 if (!wd) return EINA_FALSE;
2959 return wd->password;
2963 * This sets the text displayed within the entry to @p entry.
2965 * @param obj The entry object
2966 * @param entry The text to be displayed
2971 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2973 _elm_entry_text_set(obj, NULL, entry);
2977 * This appends @p entry to the text of the entry.
2979 * @param obj The entry object
2980 * @param entry The text to be displayed
2985 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2988 ELM_CHECK_WIDTYPE(obj, widtype);
2989 Widget_Data *wd = elm_widget_data_get(obj);
2991 if (!entry) entry = "";
2992 wd->changed = EINA_TRUE;
2994 len = strlen(entry);
2995 if (wd->append_text_left)
2998 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
3004 wd->append_text_left = tmpbuf;
3005 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
3006 wd->append_text_len += len;
3010 /* FIXME: Add chunked appending here (like in entry_set) */
3011 edje_object_part_text_append(wd->ent, "elm.text", entry);
3016 * This returns the text currently shown in object @p entry.
3017 * See also elm_entry_entry_set().
3019 * @param obj The entry object
3020 * @return The currently displayed text or NULL on failure
3025 elm_entry_entry_get(const Evas_Object *obj)
3027 return _elm_entry_text_get(obj, NULL);
3031 * This returns EINA_TRUE if the entry is empty/there was an error
3032 * and EINA_FALSE if it is not empty.
3034 * @param obj The entry object
3035 * @return If the entry is empty or not.
3040 elm_entry_is_empty(const Evas_Object *obj)
3042 /* FIXME: until there's support for that in textblock, we just check
3043 * to see if the there is text or not. */
3044 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3045 Widget_Data *wd = elm_widget_data_get(obj);
3046 const Evas_Object *tb;
3047 //Evas_Textblock_Cursor *cur;
3049 if (!wd) return EINA_TRUE;
3052 /* It's a hack until we get the support suggested above.
3053 * We just create a cursor, point it to the begining, and then
3054 * try to advance it, if it can advance, the tb is not empty,
3055 * otherwise it is. */
3056 tb = edje_object_part_object_get(wd->ent, "elm.text");
3057 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
3058 actually, ok for the time being, thsese hackish stuff will be removed
3059 once evas 1.0 is out*/
3060 evas_textblock_cursor_pos_set(cur, 0);
3061 ret = evas_textblock_cursor_char_next(cur);
3062 evas_textblock_cursor_free(cur);
3067 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
3068 if (!str) return EINA_TRUE;
3070 ret = (strlen(str) == 0);
3076 * This returns all selected text within the entry.
3078 * @param obj The entry object
3079 * @return The selected text within the entry or NULL on failure
3084 elm_entry_selection_get(const Evas_Object *obj)
3086 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3087 Widget_Data *wd = elm_widget_data_get(obj);
3088 if (!wd) return NULL;
3089 return edje_object_part_text_selection_get(wd->ent, "elm.text");
3093 * This inserts text in @p entry where the current cursor position.
3095 * This inserts text at the cursor position is as if it was typed
3096 * by the user (note this also allows markup which a user
3097 * can't just "type" as it would be converted to escaped text, so this
3098 * call can be used to insert things like emoticon items or bold push/pop
3099 * tags, other font and color change tags etc.)
3101 * @param obj The entry object
3102 * @param entry The text to insert
3107 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
3109 ELM_CHECK_WIDTYPE(obj, widtype);
3110 Widget_Data *wd = elm_widget_data_get(obj);
3112 edje_object_part_text_insert(wd->ent, "elm.text", entry);
3114 #ifdef HAVE_ELEMENTARY_X
3115 if (cnpwidgetdata == obj)
3116 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
3119 wd->changed = EINA_TRUE;
3124 * This enables word line wrapping in the entry object. It is the opposite
3125 * of elm_entry_single_line_set(). Additionally, setting this disables
3126 * character line wrapping.
3128 * @param obj The entry object
3129 * @param wrap If true, the entry will be wrapped once it reaches the end
3130 * of the object. Wrapping will occur at the end of the word before the end of the
3136 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
3138 ELM_CHECK_WIDTYPE(obj, widtype);
3139 Widget_Data *wd = elm_widget_data_get(obj);
3141 if (wd->linewrap == wrap) return;
3143 wd->linewrap = wrap;
3148 * Set wrap width of the entry
3150 * @param obj The entry object
3151 * @param w The wrap width in pixels at a minimum where words need to wrap
3155 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
3157 Widget_Data *wd = elm_widget_data_get(obj);
3158 if (wd->wrap_w == w) return;
3164 * get wrap width of the entry
3166 * @param obj The entry object
3167 * @return The wrap width in pixels at a minimum where words need to wrap
3171 elm_entry_wrap_width_get(const Evas_Object *obj)
3173 Widget_Data *wd = elm_widget_data_get(obj);
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 * Get the input method context in the entry widget
3934 * @param obj The entry object
3935 * @return The input method context
3939 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3941 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3942 Widget_Data *wd = elm_widget_data_get(obj);
3943 if (!wd || !wd->ent) return NULL;
3945 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3949 * Set whether entry should enable the return key on soft keyboard automatically
3951 * @param obj The entry object
3952 * @param on If true, entry enables the return key on soft keyboard automatically.
3957 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3959 ELM_CHECK_WIDTYPE(obj, widtype);
3960 Widget_Data *wd = elm_widget_data_get(obj);
3963 wd->autoreturnkey = on;
3964 _check_enable_returnkey(obj);
3968 * Set whether entry should support auto capitalization
3970 * @param obj The entry object
3971 * @param on If true, entry suports auto capitalization.
3976 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3978 ELM_CHECK_WIDTYPE(obj, widtype);
3979 Widget_Data *wd = elm_widget_data_get(obj);
3983 wd->autocapital = EINA_FALSE;
3985 wd->autocapital = autocap;
3987 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3988 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3989 wd->autocapital = EINA_FALSE;
3991 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3995 * Set whether entry should support auto period
3997 * @param obj The entry object
3998 * @param on If true, entry suports auto period.
4003 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
4005 ELM_CHECK_WIDTYPE(obj, widtype);
4006 Widget_Data *wd = elm_widget_data_get(obj);
4010 wd->autoperiod = EINA_FALSE;
4012 wd->autoperiod = autoperiod;
4014 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4015 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4016 wd->autoperiod = EINA_FALSE;
4018 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
4022 * Set the font size on the entry object
4024 * @param obj The entry object
4025 * @param size font size
4030 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
4032 ELM_CHECK_WIDTYPE(obj, widtype);
4033 Widget_Data *wd = elm_widget_data_get(obj);
4034 Eina_Strbuf *fontbuf = NULL;
4039 t = eina_stringshare_add(elm_entry_entry_get(obj));
4040 fontbuf = eina_strbuf_new();
4041 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
4043 if (fontsize == 0) removeflag = 1; // remove fontsize tag
4045 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
4047 elm_entry_entry_set(obj, t);
4051 eina_strbuf_free(fontbuf);
4052 eina_stringshare_del(t);
4056 * Set the text align on the entry object
4058 * @param obj The entry object
4059 * @param align align mode
4064 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
4066 ELM_CHECK_WIDTYPE(obj, widtype);
4067 Widget_Data *wd = elm_widget_data_get(obj);
4072 t = eina_stringshare_add(elm_entry_entry_get(obj));
4074 if (len <= 0) return;
4076 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
4077 elm_entry_entry_set(obj, t);
4081 eina_stringshare_del(t);
4085 * Set the text color on the entry object
4087 * @param obj The entry object
4088 * @param r Red property background color of The entry object
4089 * @param g Green property background color of The entry object
4090 * @param b Blue property background color of The entry object
4091 * @param a Alpha property background alpha of The entry object
4096 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4098 ELM_CHECK_WIDTYPE(obj, widtype);
4099 Widget_Data *wd = elm_widget_data_get(obj);
4100 Eina_Strbuf *colorbuf = NULL;
4105 t = eina_stringshare_add(elm_entry_entry_get(obj));
4107 if (len <= 0) return;
4108 colorbuf = eina_strbuf_new();
4109 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
4111 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
4113 elm_entry_entry_set(obj, t);
4117 eina_strbuf_free(colorbuf);
4118 eina_stringshare_del(t);
4122 * Set background color of the entry
4124 * @param obj The entry object
4125 * @param r Red property background color of The entry object
4126 * @param g Green property background color of The entry object
4127 * @param b Blue property background color of The entry object
4128 * @param a Alpha property background alpha of The entry object
4132 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4134 ELM_CHECK_WIDTYPE(obj, widtype);
4135 Widget_Data *wd = elm_widget_data_get(obj);
4136 evas_object_color_set(wd->bg, r, g, b, a);
4138 if (wd->bgcolor == EINA_FALSE)
4141 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
4146 * Filter inserted text based on user defined character and byte limits
4148 * Add this filter to an entry to limit the characters that it will accept
4149 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
4150 * The funtion works on the UTF-8 representation of the string, converting
4151 * it from the set markup, thus not accounting for any format in it.
4153 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
4154 * it as data when setting the filter. In it it's possible to set limits
4155 * by character count or bytes (any of them is disabled if 0), and both can
4156 * be set at the same time. In that case, it first checks for characters,
4159 * The function will cut the inserted text in order to allow only the first
4160 * number of characters that are still allowed. The cut is made in
4161 * characters, even when limiting by bytes, in order to always contain
4162 * valid ones and avoid half unicode characters making it in.
4167 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
4169 Elm_Entry_Filter_Limit_Size *lim = data;
4172 const char *(*text_get)(const Evas_Object *);
4173 const char *widget_type;
4175 EINA_SAFETY_ON_NULL_RETURN(data);
4176 EINA_SAFETY_ON_NULL_RETURN(entry);
4177 EINA_SAFETY_ON_NULL_RETURN(text);
4179 /* hack. I don't want to copy the entire function to work with
4181 widget_type = elm_widget_type_get(entry);
4182 if (!strcmp(widget_type, "entry"))
4183 text_get = elm_entry_entry_get;
4187 current = elm_entry_markup_to_utf8(text_get(entry));
4189 if (lim->max_char_count > 0)
4191 len = evas_string_char_len_get(current);
4192 if (len >= lim->max_char_count)
4194 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4200 newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
4201 if ((len + newlen) > lim->max_char_count)
4202 _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
4204 else if (lim->max_byte_count > 0)
4206 len = strlen(current);
4207 if (len >= lim->max_byte_count)
4209 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4215 newlen = strlen(elm_entry_markup_to_utf8(*text));
4216 if ((len + newlen) > lim->max_byte_count)
4217 _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
4223 * Filter inserted text based on accepted or rejected sets of characters
4225 * Add this filter to an entry to restrict the set of accepted characters
4226 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
4227 * This structure contains both accepted and rejected sets, but they are
4228 * mutually exclusive. If accepted is set, it will be used, otherwise it
4229 * goes on to the rejected set.
4232 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
4234 Elm_Entry_Filter_Accept_Set *as = data;
4238 int read_idx, last_read_idx = 0, read_char;
4240 EINA_SAFETY_ON_NULL_RETURN(data);
4241 EINA_SAFETY_ON_NULL_RETURN(text);
4243 if ((!as->accepted) && (!as->rejected))
4249 goes_in = EINA_TRUE;
4254 goes_in = EINA_FALSE;
4258 read_idx = evas_string_char_next_get(*text, 0, &read_char);
4261 int cmp_idx, cmp_char;
4262 Eina_Bool in_set = EINA_FALSE;
4264 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4267 if (read_char == cmp_char)
4272 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4274 if (in_set == goes_in)
4276 int size = read_idx - last_read_idx;
4277 const char *src = (*text) + last_read_idx;
4279 memcpy(insert, *text + last_read_idx, size);
4282 last_read_idx = read_idx;
4283 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4289 * This sets the file (and implicitly loads it) for the text to display and
4290 * then edit. All changes are written back to the file after a short delay if
4291 * the entry object is set to autosave.
4293 * @param obj The entry object
4294 * @param file The path to the file to load and save
4295 * @param format The file format
4300 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4302 ELM_CHECK_WIDTYPE(obj, widtype);
4303 Widget_Data *wd = elm_widget_data_get(obj);
4305 if (wd->delay_write)
4307 ecore_timer_del(wd->delay_write);
4308 wd->delay_write = NULL;
4310 if (wd->autosave) _save(obj);
4311 eina_stringshare_replace(&wd->file, file);
4312 wd->format = format;
4317 * Gets the file to load and save and the file format
4319 * @param obj The entry object
4320 * @param file The path to the file to load and save
4321 * @param format The file format
4326 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4328 ELM_CHECK_WIDTYPE(obj, widtype);
4329 Widget_Data *wd = elm_widget_data_get(obj);
4331 if (file) *file = wd->file;
4332 if (format) *format = wd->format;
4336 * This function writes any changes made to the file set with
4337 * elm_entry_file_set()
4339 * @param obj The entry object
4344 elm_entry_file_save(Evas_Object *obj)
4346 ELM_CHECK_WIDTYPE(obj, widtype);
4347 Widget_Data *wd = elm_widget_data_get(obj);
4349 if (wd->delay_write)
4351 ecore_timer_del(wd->delay_write);
4352 wd->delay_write = NULL;
4355 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4359 * This sets the entry object to 'autosave' the loaded text file or not.
4361 * @param obj The entry object
4362 * @param autosave Autosave the loaded file or not
4367 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4369 ELM_CHECK_WIDTYPE(obj, widtype);
4370 Widget_Data *wd = elm_widget_data_get(obj);
4372 wd->autosave = !!autosave;
4376 * This gets the entry object's 'autosave' status.
4378 * @param obj The entry object
4379 * @return Autosave the loaded file or not
4384 elm_entry_autosave_get(const Evas_Object *obj)
4386 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4387 Widget_Data *wd = elm_widget_data_get(obj);
4388 if (!wd) return EINA_FALSE;
4389 return wd->autosave;
4393 * Control pasting of text and images for the widget.
4395 * Normally the entry allows both text and images to be pasted. By setting
4396 * textonly to be true, this prevents images from being pasted.
4398 * Note this only changes the behaviour of text.
4400 * @param obj The entry object
4401 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
4406 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4408 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4409 ELM_CHECK_WIDTYPE(obj, widtype);
4410 Widget_Data *wd = elm_widget_data_get(obj);
4412 textonly = !!textonly;
4413 if (wd->textonly == textonly) return;
4414 wd->textonly = !!textonly;
4415 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
4416 #ifdef HAVE_ELEMENTARY_X
4417 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
4422 * Getting elm_entry text paste/drop mode.
4424 * In textonly mode, only text may be pasted or dropped into the widget.
4426 * @param obj The entry object
4427 * @return If the widget only accepts text from pastes.
4432 elm_entry_cnp_textonly_get(const Evas_Object *obj)
4434 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4435 Widget_Data *wd = elm_widget_data_get(obj);
4436 if (!wd) return EINA_FALSE;
4437 return wd->textonly;
4441 * Enable or disable scrolling in entry
4443 * Normally the entry is not scrollable unless you enable it with this call.
4445 * @param obj The entry object
4446 * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
4451 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
4453 ELM_CHECK_WIDTYPE(obj, widtype);
4454 Widget_Data *wd = elm_widget_data_get(obj);
4457 if (wd->scroll == scroll) return;
4458 wd->scroll = scroll;
4461 elm_widget_sub_object_del(obj, wd->scroller);
4462 elm_widget_resize_object_set(obj, wd->scroller);
4463 elm_widget_sub_object_add(obj, wd->ent);
4464 elm_smart_scroller_child_set(wd->scroller, wd->ent);
4465 evas_object_show(wd->scroller);
4466 elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
4467 if (wd->single_line)
4469 elm_smart_scroller_policy_set(wd->scroller,
4470 ELM_SMART_SCROLLER_POLICY_OFF,
4471 ELM_SMART_SCROLLER_POLICY_OFF);
4472 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4476 const Elm_Scroller_Policy map[3] =
4478 ELM_SMART_SCROLLER_POLICY_AUTO,
4479 ELM_SMART_SCROLLER_POLICY_ON,
4480 ELM_SMART_SCROLLER_POLICY_OFF
4482 elm_smart_scroller_policy_set(wd->scroller,
4485 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4490 elm_smart_scroller_child_set(wd->scroller, NULL);
4491 elm_widget_sub_object_del(obj, wd->ent);
4492 elm_widget_resize_object_set(obj, wd->ent);
4493 evas_object_smart_member_add(wd->scroller, obj);
4494 elm_widget_sub_object_add(obj, wd->scroller);
4495 evas_object_hide(wd->scroller);
4496 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
4503 * Get the scrollable state of the entry
4505 * Normally the entry is not scrollable. This gets the scrollable state
4506 * of the entry. See elm_entry_scrollable_set() for more information.
4508 * @param obj The entry object
4509 * @return The scrollable state
4514 elm_entry_scrollable_get(const Evas_Object *obj)
4516 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4517 Widget_Data *wd = elm_widget_data_get(obj);
4518 if (!wd) return EINA_FALSE;
4523 * This sets a widget to be displayed to the left of a scrolled entry.
4525 * @param obj The scrolled entry object
4526 * @param icon The widget to display on the left side of the scrolled
4529 * @note A previously set widget will be destroyed.
4530 * @note If the object being set does not have minimum size hints set,
4531 * it won't get properly displayed.
4534 * @see elm_entry_end_set
4537 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
4539 ELM_CHECK_WIDTYPE(obj, widtype);
4540 Widget_Data *wd = elm_widget_data_get(obj);
4543 EINA_SAFETY_ON_NULL_RETURN(icon);
4544 if (wd->icon == icon) return;
4545 if (wd->icon) evas_object_del(wd->icon);
4547 edje = elm_smart_scroller_edje_object_get(wd->scroller);
4549 edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
4550 edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
4555 * Gets the leftmost widget of the scrolled entry. This object is
4556 * owned by the scrolled entry and should not be modified.
4558 * @param obj The scrolled entry object
4559 * @return the left widget inside the scroller
4564 elm_entry_icon_get(const Evas_Object *obj)
4566 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4567 Widget_Data *wd = elm_widget_data_get(obj);
4568 if (!wd) return NULL;
4573 * Unset the leftmost widget of the scrolled entry, unparenting and
4576 * @param obj The scrolled entry object
4577 * @return the previously set icon sub-object of this entry, on
4580 * @see elm_entry_icon_set()
4585 elm_entry_icon_unset(Evas_Object *obj)
4587 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4588 Widget_Data *wd = elm_widget_data_get(obj);
4589 Evas_Object *ret = NULL;
4590 if (!wd) return NULL;
4593 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4594 if (!edje) return NULL;
4596 edje_object_part_unswallow(edje, wd->icon);
4597 edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
4605 * Sets the visibility of the left-side widget of the scrolled entry,
4606 * set by @elm_entry_icon_set().
4608 * @param obj The scrolled entry object
4609 * @param setting EINA_TRUE if the object should be displayed,
4610 * EINA_FALSE if not.
4615 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
4617 ELM_CHECK_WIDTYPE(obj, widtype);
4618 Widget_Data *wd = elm_widget_data_get(obj);
4619 if ((!wd) || (!wd->icon)) return;
4621 evas_object_hide(wd->icon);
4623 evas_object_show(wd->icon);
4628 * This sets a widget to be displayed to the end of a scrolled entry.
4630 * @param obj The scrolled entry object
4631 * @param end The widget to display on the right side of the scrolled
4634 * @note A previously set widget will be destroyed.
4635 * @note If the object being set does not have minimum size hints set,
4636 * it won't get properly displayed.
4639 * @see elm_entry_icon_set
4642 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
4644 ELM_CHECK_WIDTYPE(obj, widtype);
4645 Widget_Data *wd = elm_widget_data_get(obj);
4648 EINA_SAFETY_ON_NULL_RETURN(end);
4649 if (wd->end == end) return;
4650 if (wd->end) evas_object_del(wd->end);
4652 edje = elm_smart_scroller_edje_object_get(wd->scroller);
4654 edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
4655 edje_object_signal_emit(edje, "elm,action,show,end", "elm");
4660 * Gets the endmost widget of the scrolled entry. This object is owned
4661 * by the scrolled entry and should not be modified.
4663 * @param obj The scrolled entry object
4664 * @return the right widget inside the scroller
4669 elm_entry_end_get(const Evas_Object *obj)
4671 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4672 Widget_Data *wd = elm_widget_data_get(obj);
4673 if (!wd) return NULL;
4678 * Unset the endmost widget of the scrolled entry, unparenting and
4681 * @param obj The scrolled entry object
4682 * @return the previously set icon sub-object of this entry, on
4685 * @see elm_entry_icon_set()
4690 elm_entry_end_unset(Evas_Object *obj)
4692 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4693 Widget_Data *wd = elm_widget_data_get(obj);
4694 Evas_Object *ret = NULL;
4695 if (!wd) return NULL;
4698 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4699 if (!edje) return NULL;
4701 edje_object_part_unswallow(edje, wd->end);
4702 edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
4710 * Sets the visibility of the end widget of the scrolled entry, set by
4711 * @elm_entry_end_set().
4713 * @param obj The scrolled entry object
4714 * @param setting EINA_TRUE if the object should be displayed,
4715 * EINA_FALSE if not.
4720 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
4722 ELM_CHECK_WIDTYPE(obj, widtype);
4723 Widget_Data *wd = elm_widget_data_get(obj);
4724 if ((!wd) || (!wd->end)) return;
4726 evas_object_hide(wd->end);
4728 evas_object_show(wd->end);
4733 * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
4735 * @param obj The scrolled entry object
4736 * @param h The horizontal scrollbar policy to apply
4737 * @param v The vertical scrollbar policy to apply
4742 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
4744 ELM_CHECK_WIDTYPE(obj, widtype);
4745 Widget_Data *wd = elm_widget_data_get(obj);
4746 const Elm_Scroller_Policy map[3] =
4748 ELM_SMART_SCROLLER_POLICY_AUTO,
4749 ELM_SMART_SCROLLER_POLICY_ON,
4750 ELM_SMART_SCROLLER_POLICY_OFF
4755 elm_smart_scroller_policy_set(wd->scroller,
4761 * This enables/disables bouncing within the entry.
4763 * @param obj The scrolled entry object
4764 * @param h The horizontal bounce state
4765 * @param v The vertical bounce state
4770 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
4772 ELM_CHECK_WIDTYPE(obj, widtype);
4773 Widget_Data *wd = elm_widget_data_get(obj);
4775 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
4779 * Get the bounce mode
4781 * @param obj The Entry object
4782 * @param h_bounce Allow bounce horizontally
4783 * @param v_bounce Allow bounce vertically
4788 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
4790 ELM_CHECK_WIDTYPE(obj, widtype);
4791 Widget_Data *wd = elm_widget_data_get(obj);
4793 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
4797 * This sets the attribute to show the input panel automatically.
4799 * @param obj The entry object
4800 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4805 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4807 ELM_CHECK_WIDTYPE(obj, widtype);
4808 Widget_Data *wd = elm_widget_data_get(obj);
4811 wd->input_panel_enable = enabled;
4812 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4816 * Set the input panel layout of the entry
4818 * @param obj The entry object
4819 * @param layout the layout to set
4824 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4826 ELM_CHECK_WIDTYPE(obj, widtype);
4827 Widget_Data *wd = elm_widget_data_get(obj);
4830 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4833 wd->input_panel_layout = layout;
4835 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4839 * Set the magnifier style of the entry
4841 * @param obj The entry object
4842 * @param type the magnifier style to set
4847 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4849 ELM_CHECK_WIDTYPE(obj, widtype);
4850 Widget_Data *wd = elm_widget_data_get(obj);
4853 wd->mgf_type = type;
4854 _magnifier_create(obj);
4857 EINA_DEPRECATED EAPI void
4858 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
4860 if (wrap) elm_entry_line_wrap_set(obj, ELM_WRAP_CHAR);