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;
906 printf("[Elm_entry::Unfocused] obj : %p\n", obj);
907 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
908 evas_object_focus_set(wd->ent, EINA_FALSE);
909 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
910 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
912 if ((wd->api) && (wd->api->obj_hidemenu))
914 wd->api->obj_hidemenu(obj);
920 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
922 Widget_Data *wd = elm_widget_data_get(obj);
924 edje_object_signal_emit(wd->ent, emission, source);
926 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
931 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
933 Widget_Data *wd = elm_widget_data_get(obj);
935 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
937 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
938 emission, source, func_cb, data);
942 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
944 Widget_Data *wd = elm_widget_data_get(obj);
945 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
948 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
949 emission, source, func_cb, data);
953 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
955 Widget_Data *wd = elm_widget_data_get(obj);
956 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
960 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
962 Widget_Data *wd = elm_widget_data_get(obj);
964 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
968 _show_region_hook(void *data, Evas_Object *obj)
970 Widget_Data *wd = elm_widget_data_get(data);
971 Evas_Coord x, y, w, h;
973 elm_widget_show_region_get(obj, &x, &y, &w, &h);
975 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
979 _hoversel_position(Evas_Object *obj)
981 Widget_Data *wd = elm_widget_data_get(obj);
982 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
987 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
996 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
998 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
1001 cx += (cw - mw) / 2;
1006 cy += (ch - mh) / 2;
1009 evas_object_move(wd->hoversel, x + cx, y + cy);
1010 evas_object_resize(wd->hoversel, cw, ch);
1014 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1016 Widget_Data *wd = elm_widget_data_get(data);
1018 if (wd->hoversel) _hoversel_position(data);
1022 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1024 Widget_Data *wd = elm_widget_data_get(data);
1031 else if (wd->scroll)
1033 Evas_Coord vw = 0, vh = 0;
1035 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
1036 if (vw < wd->entmw) vw = wd->entmw;
1037 if (vh < wd->entmh) vh = wd->entmh;
1038 evas_object_resize(wd->ent, vw, vh);
1040 if (wd->hoversel) _hoversel_position(data);
1044 _hover_del(void *data)
1046 Widget_Data *wd = elm_widget_data_get(data);
1051 evas_object_del(wd->hoversel);
1052 wd->hoversel = NULL;
1054 wd->hovdeljob = NULL;
1058 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1060 Widget_Data *wd = elm_widget_data_get(data);
1063 if (wd->hoversel) evas_object_hide(wd->hoversel);
1066 if (!_elm_config->desktop_entry)
1069 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1072 elm_widget_scroll_freeze_pop(data);
1073 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
1074 wd->hovdeljob = ecore_job_add(_hover_del, data);
1078 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1080 Widget_Data *wd = elm_widget_data_get(data);
1082 wd->selmode = EINA_TRUE;
1083 edje_object_part_text_select_none(wd->ent, "elm.text");
1084 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1085 edje_object_part_text_select_all(wd->ent, "elm.text");
1086 elm_object_scroll_freeze_pop(data);
1090 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1092 Widget_Data *wd = elm_widget_data_get(data);
1094 wd->selmode = EINA_TRUE;
1095 edje_object_part_text_select_none(wd->ent, "elm.text");
1096 if (!_elm_config->desktop_entry)
1099 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1101 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1102 if (!_elm_config->desktop_entry)
1103 elm_object_scroll_freeze_pop(data);
1104 //elm_widget_scroll_hold_push(data);
1108 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1110 Widget_Data *wd = elm_widget_data_get(data);
1112 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1113 if (wd->sel_notify_handler)
1115 #ifdef HAVE_ELEMENTARY_X
1116 Elm_Sel_Format formats;
1117 wd->selection_asked = EINA_TRUE;
1118 formats = ELM_SEL_FORMAT_MARKUP;
1120 formats |= ELM_SEL_FORMAT_IMAGE;
1121 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
1127 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1129 Widget_Data *wd = elm_widget_data_get(obj);
1133 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1134 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
1135 if (seltype == ELM_SEL_CLIPBOARD)
1136 eina_stringshare_replace(&wd->cut_sel, sel);
1140 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1142 Widget_Data *wd = elm_widget_data_get(data);
1145 wd->selmode = EINA_FALSE;
1146 if (!_elm_config->desktop_entry)
1147 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1148 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1149 if (!_elm_config->desktop_entry)
1150 elm_widget_scroll_hold_pop(data);
1151 _store_selection(ELM_SEL_CLIPBOARD, data);
1152 edje_object_part_text_insert(wd->ent, "elm.text", "");
1153 edje_object_part_text_select_none(wd->ent, "elm.text");
1157 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1159 Widget_Data *wd = elm_widget_data_get(data);
1161 wd->selmode = EINA_FALSE;
1162 if (!_elm_config->desktop_entry)
1164 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1165 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1166 elm_widget_scroll_hold_pop(data);
1168 _store_selection(ELM_SEL_CLIPBOARD, data);
1169 // edje_object_part_text_select_none(wd->ent, "elm.text");
1173 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1175 Widget_Data *wd = elm_widget_data_get(data);
1177 wd->selmode = EINA_FALSE;
1178 if (!_elm_config->desktop_entry)
1179 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1180 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1181 if (!_elm_config->desktop_entry)
1182 elm_widget_scroll_hold_pop(data);
1183 edje_object_part_text_select_none(wd->ent, "elm.text");
1187 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
1189 Widget_Data *wd = elm_widget_data_get(data);
1193 #ifdef HAVE_ELEMENTARY_X
1194 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
1196 cnpwidgetdata = data;
1197 elm_cbhm_helper_init(obj);
1198 if (elm_entry_cnp_textonly_get(obj))
1199 elm_cbhm_send_raw_data("show0");
1201 elm_cbhm_send_raw_data("show1");
1207 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1209 Widget_Data *wd = elm_widget_data_get(data);
1211 cnpwidgetdata = data;
1217 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1219 Elm_Entry_Context_Menu_Item *it = data;
1220 Evas_Object *obj2 = it->obj;
1221 if (it->func) it->func(it->data, obj2, NULL);
1225 _menu_press(Evas_Object *obj)
1227 Widget_Data *wd = elm_widget_data_get(obj);
1230 const Elm_Entry_Context_Menu_Item *it;
1232 if ((wd->api) && (wd->api->obj_longpress))
1234 wd->api->obj_longpress(obj);
1236 else if (wd->context_menu)
1238 const char *context_menu_orientation;
1240 if (wd->hoversel) evas_object_del(wd->hoversel);
1241 else elm_widget_scroll_freeze_push(obj);
1242 wd->hoversel = elm_hoversel_add(obj);
1243 context_menu_orientation = edje_object_data_get
1244 (wd->ent, "context_menu_orientation");
1245 if ((context_menu_orientation) &&
1246 (!strcmp(context_menu_orientation, "horizontal")))
1247 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1248 elm_object_style_set(wd->hoversel, "entry");
1249 elm_widget_sub_object_add(obj, wd->hoversel);
1250 elm_object_text_set(wd->hoversel, "Text");
1251 top = elm_widget_top_get(obj);
1252 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1253 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1257 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1259 if (1) // need way to detect if someone has a selection
1262 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1266 if ((!wd->password) && (wd->editable))
1267 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1268 _clipboard_menu, obj);
1275 if (wd->have_selection)
1277 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1280 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1283 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1287 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1288 _clipboard_menu, obj);
1292 EINA_LIST_FOREACH(wd->items, l, it)
1294 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1295 it->icon_type, _item_clicked, it);
1299 _hoversel_position(obj);
1300 evas_object_show(wd->hoversel);
1301 elm_hoversel_hover_begin(wd->hoversel);
1303 if (!_elm_config->desktop_entry)
1305 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1306 edje_object_part_text_select_abort(wd->ent, "elm.text");
1312 _magnifier_hide(void *data)
1314 Widget_Data *wd = elm_widget_data_get(data);
1317 evas_object_hide(wd->mgf_bg);
1318 evas_object_hide(wd->mgf_clip);
1321 elm_smart_scroller_freeze_set(wd->scroller, EINA_FALSE);
1325 _magnifier_show(void *data)
1327 Widget_Data *wd = elm_widget_data_get(data);
1330 evas_object_show(wd->mgf_bg);
1331 evas_object_show(wd->mgf_clip);
1335 _magnifier_move(void *data)
1337 Widget_Data *wd = elm_widget_data_get(data);
1340 Evas_Coord x, y, w, h, fs;
1341 Evas_Coord cx, cy, cw, ch, ox, oy;
1343 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1347 evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1348 elm_smart_scroller_child_pos_get(wd->scroller, &ox, &oy);
1353 evas_object_geometry_get(data, &x, &y, &w, &h);
1356 fs = elm_finger_size_get();
1358 if ((cy + y) - wd->mgf_height - fs < 0)
1359 oy = -1 * ((cy + y) - wd->mgf_height - fs);
1361 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1362 evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1363 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1364 evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1368 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);
1372 _magnifier_create(void *data)
1374 Widget_Data *wd = elm_widget_data_get(data);
1375 Evas_Coord x, y, w, h, mw, mh;
1376 const char* key_data = NULL;
1382 evas_object_image_source_unset(wd->mgf_proxy);
1383 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1384 evas_object_hide(wd->mgf_proxy);
1385 evas_object_clip_unset(wd->mgf_proxy);
1386 evas_object_del(wd->mgf_proxy);
1388 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1389 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1392 evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1394 evas_object_geometry_get(data, &x, &y, &w, &h);
1396 if ((w <= 0) || (h <= 0))
1399 wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1401 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1402 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1403 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1404 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1408 wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1409 evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1410 edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1412 key_data = edje_object_data_get(wd->mgf_bg, "height");
1413 if (key_data) wd->mgf_height = atoi(key_data);
1414 key_data = edje_object_data_get(wd->mgf_bg, "scale");
1415 if (key_data) wd->mgf_scale = atof(key_data);
1417 if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1418 evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1422 elm_smart_scroller_freeze_set(wd->scroller, EINA_TRUE);
1423 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(wd->scroller));
1424 evas_object_image_source_set(wd->mgf_proxy, wd->scroller);
1428 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1429 evas_object_image_source_set(wd->mgf_proxy, data);
1432 mw = (Evas_Coord)((float)w * wd->mgf_scale);
1433 mh = (Evas_Coord)((float)h * wd->mgf_scale);
1434 if ((mw <= 0) || (mh <= 0))
1437 evas_object_resize(wd->mgf_proxy, mw, mh);
1438 evas_object_image_fill_set(wd->mgf_proxy, 0, 0, mw, mh);
1439 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1440 evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1441 evas_object_show(wd->mgf_proxy);
1442 evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1444 evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1445 evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1449 _long_press(void *data)
1451 Widget_Data *wd = elm_widget_data_get(data);
1452 if (!wd) return ECORE_CALLBACK_CANCEL;
1454 wd->long_pressed = EINA_TRUE;
1456 if (wd->longpress_timer)
1458 ecore_timer_del(wd->longpress_timer);
1459 wd->longpress_timer = NULL;
1462 _cancel(data, NULL, NULL);
1464 _magnifier_create(data);
1465 _magnifier_move(data);
1466 _magnifier_show(data);
1467 elm_object_scroll_freeze_push(data);
1469 wd->longpress_timer = NULL;
1470 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1471 return ECORE_CALLBACK_CANCEL;
1475 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1477 Widget_Data *wd = elm_widget_data_get(data);
1478 Evas_Event_Mouse_Down *ev = event_info;
1480 if (wd->disabled) return;
1481 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1482 wd->downx = ev->canvas.x;
1483 wd->downy = ev->canvas.y;
1484 wd->long_pressed = EINA_FALSE;
1485 if (ev->button == 1)
1487 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1488 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1493 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1495 Widget_Data *wd = elm_widget_data_get(data);
1496 Evas_Event_Mouse_Up *ev = event_info;
1498 if (wd->disabled) return;
1499 if (ev->button == 1)
1501 if (!wd->double_clicked)
1503 if ((wd->api) && (wd->api->obj_mouseup))
1505 wd->api->obj_mouseup(data);
1509 if (wd->longpress_timer)
1511 ecore_timer_del(wd->longpress_timer);
1512 wd->longpress_timer = NULL;
1515 _magnifier_hide(data);
1516 elm_object_scroll_freeze_pop(data);
1518 if (wd->long_pressed)
1524 else if (ev->button == 3)
1532 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1534 Widget_Data *wd = elm_widget_data_get(data);
1535 Evas_Event_Mouse_Move *ev = event_info;
1537 if (wd->disabled) return;
1540 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1542 if (wd->longpress_timer)
1544 ecore_timer_del(wd->longpress_timer);
1545 wd->longpress_timer = NULL;
1548 else if (wd->longpress_timer)
1552 dx = wd->downx - ev->cur.canvas.x;
1554 dy = wd->downy - ev->cur.canvas.y;
1557 ((_elm_config->finger_size / 2) *
1558 (_elm_config->finger_size / 2)))
1560 ecore_timer_del(wd->longpress_timer);
1561 wd->longpress_timer = NULL;
1565 else if (wd->longpress_timer)
1569 dx = wd->downx - ev->cur.canvas.x;
1571 dy = wd->downy - ev->cur.canvas.y;
1574 ((_elm_config->finger_size / 2) *
1575 (_elm_config->finger_size / 2)))
1577 ecore_timer_del(wd->longpress_timer);
1578 wd->longpress_timer = NULL;
1582 if (ev->buttons == 1)
1584 if (wd->long_pressed)
1586 _magnifier_show(data);
1587 _magnifier_move(data);
1593 _getbase(Evas_Object *obj)
1595 Widget_Data *wd = elm_widget_data_get(obj);
1596 if (!wd) return "base";
1599 if (wd->password) return "base-password";
1602 if (wd->single_line) return "base-single";
1605 switch (wd->linewrap)
1608 return "base-charwrap";
1611 case ELM_WRAP_MIXED:
1612 return "base-mixedwrap";
1615 return "base-nowrap";
1622 if (wd->password) return "base-password";
1625 if (wd->single_line) return "base-single-noedit";
1628 switch (wd->linewrap)
1631 return "base-noedit-charwrap";
1633 return "base-noedit";
1634 case ELM_WRAP_MIXED:
1635 return "base-noedit-mixedwrap";
1638 return "base-nowrap-noedit";
1648 _entry_length_get(Evas_Object *obj)
1651 const char *str = elm_entry_entry_get(obj);
1654 char *plain_str = _elm_util_mkup_to_text(str);
1655 if (!plain_str) return 0;
1657 len = strlen(plain_str);
1664 _matchlist_show(void *data)
1666 Widget_Data *wd = elm_widget_data_get(data);
1667 const char *text = NULL;
1669 char *str_list = NULL, *str_result = NULL;
1670 char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1673 Eina_Bool textfound = EINA_FALSE;
1676 if (elm_widget_disabled_get(data)) return;
1678 wd->matchlist_job = NULL;
1680 if (wd->matchlist_list_clicked)
1682 evas_object_hide(wd->hover);
1683 wd->matchlist_list_clicked = EINA_FALSE;
1686 text = elm_entry_entry_get(data);
1689 textlen = strlen(text);
1691 if (textlen < wd->matchlist_threshold)
1693 evas_object_hide(wd->hover);
1697 evas_object_hide(wd->hover);
1701 elm_list_clear(wd->list);
1702 EINA_LIST_FOREACH(wd->match_list, l, str_list)
1704 if (wd->matchlist_case_sensitive)
1705 str_result = strstr(str_list, text);
1707 str_result = strcasestr(str_list, text);
1711 str_mkup = malloc(strlen(str_list) + 16);
1712 if (str_mkup == NULL) return;
1714 textlen = strlen(str_list) - strlen(str_result);
1715 str_front = malloc(textlen + 1);
1716 if (str_front == NULL) return;
1718 memset(str_front, 0, textlen + 1);
1719 strncpy(str_front, str_list, textlen);
1721 textlen = strlen(text);
1722 str_mid = malloc(textlen + 1);
1723 if (str_mid == NULL) return;
1725 memset(str_mid, 0, textlen + 1);
1726 strncpy(str_mid, str_list + strlen(str_front), textlen);
1728 sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1730 elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1732 if (str_mkup) free(str_mkup);
1733 if (str_front) free(str_front);
1734 if (str_mid) free(str_mid);
1736 textfound=EINA_TRUE;
1745 elm_list_go(wd->list);
1746 evas_object_show(wd->hover);
1747 evas_object_raise(wd->hover);
1751 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1753 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1754 Widget_Data *wd = elm_widget_data_get(data);
1755 if ((it == NULL) || (wd == NULL))
1758 const char *text = elm_list_item_label_get(it);
1759 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1764 elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1765 elm_entry_cursor_end_set(data);
1766 wd->matchlist_list_clicked = EINA_TRUE;
1768 evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1771 elm_widget_focus_set(data, EINA_TRUE);
1775 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
1777 Widget_Data *wd = elm_widget_data_get(obj);
1782 Evas_Coord max_w = 9999, max_h = 9999;
1783 const char* key_data = NULL;
1785 wd->matchlist_threshold = 1;
1786 wd->hover = elm_hover_add(elm_widget_parent_get(obj));
1787 elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
1788 elm_hover_target_set(wd->hover, obj);
1789 elm_object_style_set(wd->hover, "matchlist");
1791 wd->layout = elm_layout_add(wd->hover);
1792 elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
1793 wd->list = elm_list_add(wd->layout);
1794 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
1795 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1796 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1797 elm_object_style_set(wd->list, "matchlist");
1799 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
1800 if (key_data) max_w = atoi(key_data);
1801 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
1802 if (key_data) max_h = atoi(key_data);
1804 elm_list_go(wd->list);
1805 evas_object_size_hint_max_set(wd->list, max_w, max_h);
1806 evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
1807 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
1808 elm_hover_content_set(wd->hover, "bottom", wd->layout);
1810 wd->match_list = match_list;
1815 evas_object_del(wd->hover);
1817 wd->match_list = NULL;
1820 wd->matchlist_case_sensitive = case_sensitive;
1824 _entry_changed_common_handling(void *data, const char *event)
1826 Widget_Data *wd = elm_widget_data_get(data);
1827 Evas_Coord minw, minh;
1829 wd->changed = EINA_TRUE;
1830 /* Reset the size hints which are no more relevant.
1831 * Keep the height, this is a hack, but doesn't really matter
1832 * cause we'll re-eval in a moment. */
1835 evas_object_size_hint_min_get(data, &minw, &minh);
1836 evas_object_size_hint_min_set(data, minw, minh);
1840 evas_object_size_hint_min_get(data, NULL, &minh);
1841 evas_object_size_hint_min_set(data, -1, minh);
1845 if (wd->text) eina_stringshare_del(wd->text);
1847 _check_enable_returnkey(data);
1848 evas_object_smart_callback_call(data, event, NULL);
1849 if (wd->delay_write)
1851 ecore_timer_del(wd->delay_write);
1852 wd->delay_write = NULL;
1855 if ((wd->single_line) && (wd->match_list))
1857 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1858 wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1860 if ((!wd->autosave) || (!wd->file)) return;
1861 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1865 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1867 _entry_changed_common_handling(data, SIG_CHANGED);
1871 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1873 _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1878 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1880 Widget_Data *wd = elm_widget_data_get(data);
1881 elm_object_scroll_freeze_push(data);
1883 if ((wd->api) && (wd->api->obj_hidemenu))
1885 wd->api->obj_hidemenu(data);
1888 _magnifier_create(data);
1889 _magnifier_move(data);
1890 _magnifier_show(data);
1894 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1896 Widget_Data *wd = elm_widget_data_get(data);
1897 elm_object_scroll_freeze_pop(data);
1899 if (wd->have_selection)
1901 _magnifier_hide(data);
1907 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1909 _magnifier_move(data);
1910 _magnifier_show(data);
1914 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1916 _magnifier_hide(data);
1921 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1923 Widget_Data *wd = elm_widget_data_get(data);
1927 EINA_LIST_FOREACH(entries, l, entry)
1929 if (entry != data) elm_entry_select_none(entry);
1931 wd->have_selection = EINA_TRUE;
1932 wd->selmode = EINA_TRUE;
1933 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1934 #ifdef HAVE_ELEMENTARY_X
1935 if (wd->sel_notify_handler)
1937 const char *txt = elm_entry_selection_get(data);
1940 top = elm_widget_top_get(data);
1941 if ((top) && (elm_win_xwindow_get(top)))
1942 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1948 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1950 Evas_Coord cx, cy, cw, ch;
1951 Widget_Data *wd = elm_widget_data_get(data);
1954 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1955 if (!wd->deferred_recalc_job)
1956 elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
1959 wd->deferred_cur = EINA_TRUE;
1963 wd->ch = ch + elm_finger_size_get();
1968 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1970 Evas_Coord cx, cy, cw, ch;
1971 Widget_Data *wd = elm_widget_data_get(data);
1973 wd->have_selection = EINA_TRUE;
1974 wd->selmode = EINA_TRUE;
1975 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1976 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1977 elm_entry_selection_get(data));
1979 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1980 if (!wd->deferred_recalc_job)
1981 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get(), EINA_FALSE);
1984 wd->deferred_cur = EINA_TRUE;
1988 wd->ch = ch + elm_finger_size_get();
1993 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1995 Widget_Data *wd = elm_widget_data_get(data);
1997 if (!wd->have_selection) return;
1998 wd->have_selection = EINA_FALSE;
1999 wd->selmode = EINA_FALSE;
2000 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
2001 if (wd->sel_notify_handler)
2005 #ifdef HAVE_ELEMENTARY_X
2008 top = elm_widget_top_get(data);
2009 if ((top) && (elm_win_xwindow_get(top)))
2010 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
2013 eina_stringshare_del(wd->cut_sel);
2018 #ifdef HAVE_ELEMENTARY_X
2021 top = elm_widget_top_get(data);
2022 if ((top) && (elm_win_xwindow_get(top)))
2023 elm_selection_clear(ELM_SEL_PRIMARY, data);
2028 if ((wd->api) && (wd->api->obj_hidemenu))
2030 wd->api->obj_hidemenu(data);
2035 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2037 Widget_Data *wd = elm_widget_data_get(data);
2039 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2040 if (wd->sel_notify_handler)
2042 #ifdef HAVE_ELEMENTARY_X
2045 top = elm_widget_top_get(data);
2046 if ((top) && (elm_win_xwindow_get(top)))
2048 wd->selection_asked = EINA_TRUE;
2049 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
2057 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2059 Widget_Data *wd = elm_widget_data_get(data);
2061 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
2062 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2063 elm_entry_selection_get(data));
2067 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2069 Widget_Data *wd = elm_widget_data_get(data);
2071 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
2072 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2073 elm_entry_selection_get(data));
2074 edje_object_part_text_insert(wd->ent, "elm.text", "");
2075 wd->changed = EINA_TRUE;
2080 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2082 Widget_Data *wd = elm_widget_data_get(data);
2084 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2085 wd->cur_changed = EINA_TRUE;
2086 _recalc_cursor_geometry(data);
2090 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2092 Widget_Data *wd = elm_widget_data_get(data);
2097 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2099 Widget_Data *wd = elm_widget_data_get(data);
2104 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
2106 Widget_Data *wd = elm_widget_data_get(data);
2107 Elm_Entry_Anchor_Info ei;
2108 char *buf2, *p, *p2, *n;
2110 p = strrchr(emission, ',');
2113 const Eina_List *geoms;
2117 while (p2 >= emission)
2119 if (*p2 == ',') break;
2123 buf2 = alloca(5 + p - p2);
2124 strncpy(buf2, p2, p - p2);
2127 ei.button = atoi(buf2);
2128 ei.x = ei.y = ei.w = ei.h = 0;
2130 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
2133 Evas_Textblock_Rectangle *r;
2135 Evas_Coord px, py, x, y;
2137 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
2138 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
2139 EINA_LIST_FOREACH(geoms, l, r)
2141 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
2142 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
2153 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
2158 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2160 Widget_Data *wd = elm_widget_data_get(data);
2165 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2167 Widget_Data *wd = elm_widget_data_get(data);
2172 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2174 Widget_Data *wd = elm_widget_data_get(data);
2179 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2181 Widget_Data *wd = elm_widget_data_get(data);
2183 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
2187 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2189 Widget_Data *wd = elm_widget_data_get(data);
2191 wd->double_clicked = EINA_FALSE;
2192 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
2194 if ((wd->api) && (wd->api->obj_hidemenu))
2196 wd->api->obj_hidemenu(data);
2201 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2203 Widget_Data *wd = elm_widget_data_get(data);
2205 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
2209 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2211 Widget_Data *wd = elm_widget_data_get(data);
2213 wd->double_clicked = EINA_TRUE;
2214 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
2217 #ifdef HAVE_ELEMENTARY_X
2219 _event_selection_notify(void *data, int type __UNUSED__, void *event)
2221 Widget_Data *wd = elm_widget_data_get(data);
2222 Ecore_X_Event_Selection_Notify *ev = event;
2223 if (!wd) return ECORE_CALLBACK_PASS_ON;
2224 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
2225 return ECORE_CALLBACK_PASS_ON;
2227 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2228 (ev->selection == ECORE_X_SELECTION_PRIMARY))
2230 Ecore_X_Selection_Data_Text *text_data;
2232 text_data = ev->data;
2233 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2235 if (text_data->text)
2237 char *txt = _elm_util_text_to_mkup(text_data->text);
2241 elm_entry_entry_insert(data, txt);
2246 wd->selection_asked = EINA_FALSE;
2248 else if (ev->selection == ECORE_X_SELECTION_XDND)
2250 Ecore_X_Selection_Data_Text *text_data;
2252 text_data = ev->data;
2253 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2255 if (text_data->text)
2257 char *txt = _elm_util_text_to_mkup(text_data->text);
2261 /* Massive FIXME: this should be at the drag point */
2262 elm_entry_entry_insert(data, txt);
2267 wd->drag_selection_asked = EINA_FALSE;
2269 ecore_x_dnd_send_finished();
2272 return ECORE_CALLBACK_PASS_ON;
2276 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2279 Widget_Data *wd = elm_widget_data_get(data);
2280 Ecore_X_Event_Selection_Clear *ev = event;
2281 if (!wd) return ECORE_CALLBACK_PASS_ON;
2282 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2283 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2284 (ev->selection == ECORE_X_SELECTION_PRIMARY))
2286 elm_entry_select_none(data);
2291 Evas_Object *top = elm_widget_top_get(data);
2292 Ecore_X_Event_Selection_Clear *ev = event;
2295 return ECORE_CALLBACK_PASS_ON;
2297 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2299 return ECORE_CALLBACK_PASS_ON;
2302 if (cnpwidgetdata == data)
2304 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
2308 return ECORE_CALLBACK_PASS_ON;
2312 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2317 wd = elm_widget_data_get(obj);
2318 if (!wd) return EINA_FALSE;
2319 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
2321 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2322 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2323 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2324 EDJE_CURSOR_MAIN,drop->x,drop->y);
2325 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2326 elm_entry_entry_insert(obj, drop->data);
2327 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2328 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2334 static Evas_Object *
2335 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2337 Widget_Data *wd = elm_widget_data_get(data);
2340 Elm_Entry_Item_Provider *ip;
2342 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2344 o = ip->func(ip->data, data, item);
2347 if (!strncmp(item, "file://", 7))
2349 const char *fname = item + 7;
2351 o = evas_object_image_filled_add(evas_object_evas_get(data));
2352 evas_object_image_file_set(o, fname, NULL);
2353 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2355 evas_object_show(o);
2360 o = edje_object_add(evas_object_evas_get(data));
2361 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2365 o = edje_object_add(evas_object_evas_get(data));
2366 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2367 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2372 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2374 const char *srcstring = NULL;
2375 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2376 char *curlocater, *replocater;
2377 char *starttag, *endtag;
2378 int tagtxtlen = 0, insertflag = 0;
2380 srcstring = eina_strbuf_string_get(srcbuf);
2381 curlocater = strstr(srcstring, key);
2383 if (!curlocater || !srcstring)
2391 starttag = strchr(srcstring, '<');
2392 endtag = strchr(srcstring, '>');
2393 tagtxtlen = endtag - starttag;
2394 if (tagtxtlen <= 0) tagtxtlen = 0;
2395 if (starttag < curlocater && curlocater < endtag) break;
2396 if (endtag != NULL && endtag+1 != NULL)
2397 srcstring = endtag+1;
2400 } while (strlen(srcstring) > 1);
2402 if (starttag && endtag && tagtxtlen > strlen(key))
2404 repbuf = eina_strbuf_new();
2405 diffbuf = eina_strbuf_new();
2406 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2407 srcstring = eina_strbuf_string_get(repbuf);
2408 curlocater = strstr(srcstring, key);
2410 if (curlocater != NULL)
2412 replocater = curlocater + strlen(key) + 1;
2414 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2417 if (replocater-curlocater > strlen(key)+1)
2419 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2428 eina_strbuf_reset(repbuf);
2436 if (repbuf == NULL) repbuf = eina_strbuf_new();
2437 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2441 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2442 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2448 eina_strbuf_prepend(diffbuf, "<");
2449 eina_strbuf_append(diffbuf, ">");
2450 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2454 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2455 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2459 if (repbuf) eina_strbuf_free(repbuf);
2460 if (diffbuf) eina_strbuf_free(diffbuf);
2466 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2468 Eina_Strbuf *sharebuf = NULL;
2470 sharebuf = eina_strbuf_new();
2471 eina_strbuf_append(sharebuf, *srcstring);
2472 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2473 eina_stringshare_del(*srcstring);
2474 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2475 eina_strbuf_free(sharebuf);
2481 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2483 Widget_Data *wd = elm_widget_data_get(data);
2485 Elm_Entry_Text_Filter *tf;
2487 if (type == EDJE_TEXT_FILTER_FORMAT)
2490 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2492 tf->func(tf->data, data, text);
2498 /* This function is used to insert text by chunks in jobs */
2500 _text_append_idler(void *data)
2504 Evas_Object *obj = (Evas_Object *) data;
2505 Widget_Data *wd = elm_widget_data_get(obj);
2506 if (wd->text) eina_stringshare_del(wd->text);
2508 wd->changed = EINA_TRUE;
2510 start = wd->append_text_position;
2511 if(start + _CHUNK_SIZE < wd->append_text_len)
2513 wd->append_text_position = (start + _CHUNK_SIZE);
2514 /* Go to the start of the nearest codepoint, because we don't want
2515 * to cut it in the middle */
2516 eina_unicode_utf8_get_prev(wd->append_text_left,
2517 &wd->append_text_position);
2521 wd->append_text_position = wd->append_text_len;
2524 backup = wd->append_text_left[wd->append_text_position];
2525 wd->append_text_left[wd->append_text_position] = '\0';
2527 edje_object_part_text_append(wd->ent, "elm.text",
2528 wd->append_text_left + start);
2530 wd->append_text_left[wd->append_text_position] = backup;
2532 /* If there's still more to go, renew the idler, else, cleanup */
2533 if (wd->append_text_position < wd->append_text_len)
2535 return ECORE_CALLBACK_RENEW;
2539 free(wd->append_text_left);
2540 wd->append_text_left = NULL;
2541 wd->append_text_idler = NULL;
2542 return ECORE_CALLBACK_CANCEL;
2547 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2549 int i = 0, unit_size;
2550 int current_len = strlen(*text);
2551 char *new_text = *text;
2552 if (unit >= LENGTH_UNIT_LAST) return;
2555 if (*new_text == '<')
2557 while (*new_text != '>')
2560 if (!*new_text) break;
2567 if (*new_text == '&')
2569 while (*(new_text + index) != ';')
2572 if (!*(new_text + index)) break;
2576 index = evas_string_char_next_get(new_text, index, NULL);
2577 markup = malloc(index + 1);
2578 strncpy(markup, new_text, index);
2580 if (unit == LENGTH_UNIT_BYTE)
2581 unit_size = strlen(elm_entry_markup_to_utf8(markup));
2582 else if (unit == LENGTH_UNIT_CHAR)
2583 unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
2589 if (can_add < unit_size)
2593 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2599 strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
2600 current_len -= index;
2601 (*text)[current_len] = 0;
2606 can_add -= unit_size;
2611 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2615 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2618 ELM_CHECK_WIDTYPE(obj, widtype);
2619 if (item && strcmp(item, "default")) return;
2620 Widget_Data *wd = elm_widget_data_get(obj);
2622 if (!entry) entry = "";
2623 if (wd->text) eina_stringshare_del(wd->text);
2625 wd->changed = EINA_TRUE;
2627 /* Clear currently pending job if there is one */
2628 if (wd->append_text_idler)
2630 ecore_idler_del(wd->append_text_idler);
2631 free(wd->append_text_left);
2632 wd->append_text_left = NULL;
2633 wd->append_text_idler = NULL;
2636 len = strlen(entry);
2637 /* Split to ~_CHUNK_SIZE chunks */
2638 if (len > _CHUNK_SIZE)
2640 wd->append_text_left = (char *) malloc(len + 1);
2643 /* If we decided to use the idler */
2644 if (wd->append_text_left)
2646 /* Need to clear the entry first */
2647 edje_object_part_text_set(wd->ent, "elm.text", "");
2648 memcpy(wd->append_text_left, entry, len + 1);
2649 wd->append_text_position = 0;
2650 wd->append_text_len = len;
2651 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2655 edje_object_part_text_set(wd->ent, "elm.text", entry);
2660 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2662 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2663 Widget_Data *wd = elm_widget_data_get(obj);
2664 if (item && strcmp(item, "default")) return NULL;
2666 if (!wd) return NULL;
2670 return elm_entry_markup_to_utf8(wd->text);
2674 text = edje_object_part_text_get(wd->ent, "elm.text");
2677 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2680 eina_stringshare_replace(&wd->text, text);
2681 if (wd->password) return elm_entry_markup_to_utf8(wd->text);
2686 * This adds an entry to @p parent object.
2688 * @param parent The parent object
2689 * @return The new object or NULL if it cannot be created
2694 elm_entry_add(Evas_Object *parent)
2696 Evas_Object *obj, *top;
2700 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2702 ELM_SET_WIDTYPE(widtype, "entry");
2703 elm_widget_type_set(obj, "entry");
2704 elm_widget_sub_object_add(parent, obj);
2705 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2706 elm_widget_data_set(obj, wd);
2707 elm_widget_del_hook_set(obj, _del_hook);
2708 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2709 elm_widget_theme_hook_set(obj, _theme_hook);
2710 elm_widget_disable_hook_set(obj, _disable_hook);
2711 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2712 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2713 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2714 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2715 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2716 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2717 elm_widget_can_focus_set(obj, EINA_TRUE);
2718 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2719 elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2720 elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2722 wd->scroller = elm_smart_scroller_add(e);
2723 elm_widget_sub_object_add(obj, wd->scroller);
2724 elm_smart_scroller_widget_set(wd->scroller, obj);
2725 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
2726 elm_widget_style_get(obj));
2727 evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2728 evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
2729 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2730 elm_smart_scroller_propagate_events_set(wd->scroller, EINA_TRUE);
2732 wd->linewrap = ELM_WRAP_WORD;
2733 wd->editable = EINA_TRUE;
2734 wd->disabled = EINA_FALSE;
2735 wd->context_menu = EINA_TRUE;
2736 wd->autosave = EINA_TRUE;
2737 wd->textonly = EINA_FALSE;
2738 wd->autoperiod = EINA_TRUE;
2740 wd->ent = edje_object_add(e);
2741 elm_widget_sub_object_add(obj, wd->ent);
2742 edje_object_item_provider_set(wd->ent, _get_item, obj);
2743 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2744 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2745 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2747 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2749 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2751 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2753 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2754 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2755 _signal_entry_changed, obj);
2756 edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2757 _signal_preedit_changed, obj);
2758 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2759 _signal_handler_move_start, obj);
2760 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2761 _signal_handler_move_end, obj);
2762 edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2763 _signal_handler_moving, obj);
2764 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2765 _signal_selection_start, obj);
2766 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2767 _signal_selection_end, obj);
2768 edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2769 _signal_magnifier_changed, obj);
2770 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2771 _signal_selection_changed, obj);
2772 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2773 _signal_selection_cleared, obj);
2774 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2775 _signal_entry_paste_request, obj);
2776 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2777 _signal_entry_copy_notify, obj);
2778 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2779 _signal_entry_cut_notify, obj);
2780 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2781 _signal_cursor_changed, obj);
2782 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2783 _signal_anchor_down, obj);
2784 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2785 _signal_anchor_up, obj);
2786 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2787 _signal_anchor_clicked, obj);
2788 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2789 _signal_anchor_move, obj);
2790 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2791 _signal_anchor_in, obj);
2792 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2793 _signal_anchor_out, obj);
2794 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2795 _signal_key_enter, obj);
2796 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2797 _signal_mouse_down, obj);
2798 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2799 _signal_mouse_clicked, obj);
2800 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2801 _signal_mouse_double, obj);
2802 edje_object_part_text_set(wd->ent, "elm.text", "");
2803 if (_elm_config->desktop_entry)
2804 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2805 elm_widget_resize_object_set(obj, wd->ent);
2808 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2810 #ifdef HAVE_ELEMENTARY_X
2811 top = elm_widget_top_get(obj);
2812 if ((top) && (elm_win_xwindow_get(top)))
2814 wd->sel_notify_handler =
2815 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2816 _event_selection_notify, obj);
2817 wd->sel_clear_handler =
2818 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2819 _event_selection_clear, obj);
2822 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2823 _drag_drop_cb, NULL);
2826 entries = eina_list_prepend(entries, obj);
2828 // module - find module for entry
2829 wd->api = _module(obj);
2830 // if found - hook in
2831 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2833 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2834 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2835 // TODO: and save some bytes, making descriptions per-class and not instance!
2836 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2840 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2842 ELM_CHECK_WIDTYPE(obj, widtype);
2843 Widget_Data *wd = elm_widget_data_get(obj);
2845 ext_mod->cancel = _cancel;
2846 ext_mod->copy = _copy;
2847 ext_mod->cut = _cut;
2848 ext_mod->paste = _paste;
2849 ext_mod->select = _select;
2850 ext_mod->selectall = _selectall;
2851 ext_mod->ent = wd->ent;
2852 ext_mod->items = wd->items;
2853 ext_mod->longpress_timer = wd->longpress_timer;
2854 ext_mod->editable = wd->editable;
2855 ext_mod->have_selection = wd->have_selection;
2856 ext_mod->password = wd->password;
2857 ext_mod->selmode = wd->selmode;
2858 ext_mod->cnpinit = _cnpinit;
2859 ext_mod->context_menu = wd->context_menu;
2860 ext_mod->textonly = wd->textonly;
2864 * This sets the entry object not to line wrap. All input will
2865 * be on a single line, and the entry box will extend with user input.
2867 * @param obj The entry object
2868 * @param single_line If true, the text in the entry
2869 * will be on a single line.
2874 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2876 ELM_CHECK_WIDTYPE(obj, widtype);
2877 Widget_Data *wd = elm_widget_data_get(obj);
2879 if (wd->single_line == single_line) return;
2880 wd->single_line = single_line;
2881 wd->linewrap = ELM_WRAP_NONE;
2882 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2886 if (wd->single_line)
2888 elm_smart_scroller_policy_set(wd->scroller,
2889 ELM_SMART_SCROLLER_POLICY_OFF,
2890 ELM_SMART_SCROLLER_POLICY_OFF);
2891 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2895 const Elm_Scroller_Policy map[3] =
2897 ELM_SMART_SCROLLER_POLICY_AUTO,
2898 ELM_SMART_SCROLLER_POLICY_ON,
2899 ELM_SMART_SCROLLER_POLICY_OFF
2901 elm_smart_scroller_policy_set(wd->scroller,
2904 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2911 * This returns true if the entry has been set to single line mode.
2912 * See also elm_entry_single_line_set().
2914 * @param obj The entry object
2915 * @return single_line If true, the text in the entry is set to display
2921 elm_entry_single_line_get(const Evas_Object *obj)
2923 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2924 Widget_Data *wd = elm_widget_data_get(obj);
2925 if (!wd) return EINA_FALSE;
2926 return wd->single_line;
2930 * This sets the entry object to password mode. All text entered
2931 * and/or displayed within the widget will be replaced with asterisks (*).
2933 * @param obj The entry object
2934 * @param password If true, password mode is enabled.
2939 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2941 ELM_CHECK_WIDTYPE(obj, widtype);
2942 Widget_Data *wd = elm_widget_data_get(obj);
2944 if (wd->password == password) return;
2945 wd->password = password;
2946 wd->single_line = EINA_TRUE;
2947 wd->linewrap = ELM_WRAP_NONE;
2952 * This returns whether password mode is enabled.
2953 * See also elm_entry_password_set().
2955 * @param obj The entry object
2956 * @return If true, the entry is set to display all characters
2962 elm_entry_password_get(const Evas_Object *obj)
2964 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2965 Widget_Data *wd = elm_widget_data_get(obj);
2966 if (!wd) return EINA_FALSE;
2967 return wd->password;
2971 * This sets the text displayed within the entry to @p entry.
2973 * @param obj The entry object
2974 * @param entry The text to be displayed
2979 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2981 _elm_entry_text_set(obj, NULL, entry);
2985 * This appends @p entry to the text of the entry.
2987 * @param obj The entry object
2988 * @param entry The text to be displayed
2993 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2996 ELM_CHECK_WIDTYPE(obj, widtype);
2997 Widget_Data *wd = elm_widget_data_get(obj);
2999 if (!entry) entry = "";
3000 wd->changed = EINA_TRUE;
3002 len = strlen(entry);
3003 if (wd->append_text_left)
3006 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
3012 wd->append_text_left = tmpbuf;
3013 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
3014 wd->append_text_len += len;
3018 /* FIXME: Add chunked appending here (like in entry_set) */
3019 edje_object_part_text_append(wd->ent, "elm.text", entry);
3024 * This returns the text currently shown in object @p entry.
3025 * See also elm_entry_entry_set().
3027 * @param obj The entry object
3028 * @return The currently displayed text or NULL on failure
3033 elm_entry_entry_get(const Evas_Object *obj)
3035 return _elm_entry_text_get(obj, NULL);
3039 * This returns EINA_TRUE if the entry is empty/there was an error
3040 * and EINA_FALSE if it is not empty.
3042 * @param obj The entry object
3043 * @return If the entry is empty or not.
3048 elm_entry_is_empty(const Evas_Object *obj)
3050 /* FIXME: until there's support for that in textblock, we just check
3051 * to see if the there is text or not. */
3052 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3053 Widget_Data *wd = elm_widget_data_get(obj);
3054 const Evas_Object *tb;
3055 //Evas_Textblock_Cursor *cur;
3057 if (!wd) return EINA_TRUE;
3060 /* It's a hack until we get the support suggested above.
3061 * We just create a cursor, point it to the begining, and then
3062 * try to advance it, if it can advance, the tb is not empty,
3063 * otherwise it is. */
3064 tb = edje_object_part_object_get(wd->ent, "elm.text");
3065 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
3066 actually, ok for the time being, thsese hackish stuff will be removed
3067 once evas 1.0 is out*/
3068 evas_textblock_cursor_pos_set(cur, 0);
3069 ret = evas_textblock_cursor_char_next(cur);
3070 evas_textblock_cursor_free(cur);
3075 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
3076 if (!str) return EINA_TRUE;
3078 ret = (strlen(str) == 0);
3084 * This returns all selected text within the entry.
3086 * @param obj The entry object
3087 * @return The selected text within the entry or NULL on failure
3092 elm_entry_selection_get(const Evas_Object *obj)
3094 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3095 Widget_Data *wd = elm_widget_data_get(obj);
3096 if (!wd) return NULL;
3097 return edje_object_part_text_selection_get(wd->ent, "elm.text");
3101 * This inserts text in @p entry where the current cursor position.
3103 * This inserts text at the cursor position is as if it was typed
3104 * by the user (note this also allows markup which a user
3105 * can't just "type" as it would be converted to escaped text, so this
3106 * call can be used to insert things like emoticon items or bold push/pop
3107 * tags, other font and color change tags etc.)
3109 * @param obj The entry object
3110 * @param entry The text to insert
3115 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
3117 ELM_CHECK_WIDTYPE(obj, widtype);
3118 Widget_Data *wd = elm_widget_data_get(obj);
3120 edje_object_part_text_insert(wd->ent, "elm.text", entry);
3122 #ifdef HAVE_ELEMENTARY_X
3123 if (cnpwidgetdata == obj)
3124 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
3127 wd->changed = EINA_TRUE;
3132 * This enables word line wrapping in the entry object. It is the opposite
3133 * of elm_entry_single_line_set(). Additionally, setting this disables
3134 * character line wrapping.
3136 * @param obj The entry object
3137 * @param wrap If true, the entry will be wrapped once it reaches the end
3138 * of the object. Wrapping will occur at the end of the word before the end of the
3144 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
3146 ELM_CHECK_WIDTYPE(obj, widtype);
3147 Widget_Data *wd = elm_widget_data_get(obj);
3149 if (wd->linewrap == wrap) return;
3151 wd->linewrap = wrap;
3156 * Set wrap width of the entry
3158 * @param obj The entry object
3159 * @param w The wrap width in pixels at a minimum where words need to wrap
3163 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
3165 Widget_Data *wd = elm_widget_data_get(obj);
3166 if (wd->wrap_w == w) return;
3172 * get wrap width of the entry
3174 * @param obj The entry object
3175 * @return The wrap width in pixels at a minimum where words need to wrap
3179 elm_entry_wrap_width_get(const Evas_Object *obj)
3181 Widget_Data *wd = elm_widget_data_get(obj);
3186 * Get the wrapping behavior of the entry.
3187 * See also elm_entry_line_wrap_set().
3189 * @param obj The entry object
3195 elm_entry_line_wrap_get(const Evas_Object *obj)
3197 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3198 Widget_Data *wd = elm_widget_data_get(obj);
3199 if (!wd) return EINA_FALSE;
3200 return wd->linewrap;
3204 * This sets the editable attribute of the entry.
3206 * @param obj The entry object
3207 * @param editable If true, the entry will be editable by the user.
3208 * If false, it will be set to the disabled state.
3213 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
3215 ELM_CHECK_WIDTYPE(obj, widtype);
3216 Widget_Data *wd = elm_widget_data_get(obj);
3218 if (wd->editable == editable) return;
3219 wd->editable = editable;
3222 #ifdef HAVE_ELEMENTARY_X
3224 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
3226 elm_drop_target_del(obj);
3231 * This gets the editable attribute of the entry.
3232 * See also elm_entry_editable_set().
3234 * @param obj The entry object
3235 * @return If true, the entry is editable by the user.
3236 * If false, it is not editable by the user
3241 elm_entry_editable_get(const Evas_Object *obj)
3243 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3244 Widget_Data *wd = elm_widget_data_get(obj);
3245 if (!wd) return EINA_FALSE;
3246 return wd->editable;
3250 * This drops any existing text selection within the entry.
3252 * @param obj The entry object
3257 elm_entry_select_none(Evas_Object *obj)
3259 ELM_CHECK_WIDTYPE(obj, widtype);
3260 Widget_Data *wd = elm_widget_data_get(obj);
3264 wd->selmode = EINA_FALSE;
3265 if (!_elm_config->desktop_entry)
3266 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3267 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3269 wd->have_selection = EINA_FALSE;
3270 edje_object_part_text_select_none(wd->ent, "elm.text");
3274 * This selects all text within the entry.
3276 * @param obj The entry object
3281 elm_entry_select_all(Evas_Object *obj)
3283 ELM_CHECK_WIDTYPE(obj, widtype);
3284 Widget_Data *wd = elm_widget_data_get(obj);
3288 wd->selmode = EINA_FALSE;
3289 if (!_elm_config->desktop_entry)
3290 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3291 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3293 wd->have_selection = EINA_TRUE;
3294 edje_object_part_text_select_all(wd->ent, "elm.text");
3298 * This function returns the geometry of the cursor.
3300 * It's useful if you want to draw something on the cursor (or where it is),
3301 * or for example in the case of scrolled entry where you want to show the
3304 * @param obj The entry object
3305 * @param x returned geometry
3306 * @param y returned geometry
3307 * @param w returned geometry
3308 * @param h returned geometry
3309 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3314 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3316 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3317 Widget_Data *wd = elm_widget_data_get(obj);
3318 if (!wd) return EINA_FALSE;
3319 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3324 * This moves the cursor one place to the right within the entry.
3326 * @param obj The entry object
3327 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3332 elm_entry_cursor_next(Evas_Object *obj)
3334 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3335 Widget_Data *wd = elm_widget_data_get(obj);
3336 if (!wd) return EINA_FALSE;
3337 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3341 * This moves the cursor one place to the left within the entry.
3343 * @param obj The entry object
3344 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3349 elm_entry_cursor_prev(Evas_Object *obj)
3351 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3352 Widget_Data *wd = elm_widget_data_get(obj);
3353 if (!wd) return EINA_FALSE;
3354 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3358 * This moves the cursor one line up within the entry.
3360 * @param obj The entry object
3361 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3366 elm_entry_cursor_up(Evas_Object *obj)
3368 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3369 Widget_Data *wd = elm_widget_data_get(obj);
3370 if (!wd) return EINA_FALSE;
3371 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3375 * This moves the cursor one line down within the entry.
3377 * @param obj The entry object
3378 * @return EINA_TRUE upon success, EINA_FALSE upon failure
3383 elm_entry_cursor_down(Evas_Object *obj)
3385 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3386 Widget_Data *wd = elm_widget_data_get(obj);
3387 if (!wd) return EINA_FALSE;
3388 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3392 * This moves the cursor to the beginning of the entry.
3394 * @param obj The entry object
3399 elm_entry_cursor_begin_set(Evas_Object *obj)
3401 ELM_CHECK_WIDTYPE(obj, widtype);
3402 Widget_Data *wd = elm_widget_data_get(obj);
3404 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3408 * This moves the cursor to the end of the entry.
3410 * @param obj The entry object
3415 elm_entry_cursor_end_set(Evas_Object *obj)
3417 ELM_CHECK_WIDTYPE(obj, widtype);
3418 Widget_Data *wd = elm_widget_data_get(obj);
3421 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3424 elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
3425 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
3430 * This moves the cursor to the beginning of the current line.
3432 * @param obj The entry object
3437 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3439 ELM_CHECK_WIDTYPE(obj, widtype);
3440 Widget_Data *wd = elm_widget_data_get(obj);
3442 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3446 * This moves the cursor to the end of the current line.
3448 * @param obj The entry object
3453 elm_entry_cursor_line_end_set(Evas_Object *obj)
3455 ELM_CHECK_WIDTYPE(obj, widtype);
3456 Widget_Data *wd = elm_widget_data_get(obj);
3458 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3462 * This begins a selection within the entry as though
3463 * the user were holding down the mouse button to make a selection.
3465 * @param obj The entry object
3470 elm_entry_cursor_selection_begin(Evas_Object *obj)
3472 ELM_CHECK_WIDTYPE(obj, widtype);
3473 Widget_Data *wd = elm_widget_data_get(obj);
3475 edje_object_part_text_select_begin(wd->ent, "elm.text");
3479 * This ends a selection within the entry as though
3480 * the user had just released the mouse button while making a selection.
3482 * @param obj The entry object
3487 elm_entry_cursor_selection_end(Evas_Object *obj)
3489 ELM_CHECK_WIDTYPE(obj, widtype);
3490 Widget_Data *wd = elm_widget_data_get(obj);
3492 edje_object_part_text_select_extend(wd->ent, "elm.text");
3496 * TODO: fill this in
3498 * @param obj The entry object
3499 * @return TODO: fill this in
3504 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3506 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3507 Widget_Data *wd = elm_widget_data_get(obj);
3508 if (!wd) return EINA_FALSE;
3509 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3513 * This returns whether the cursor is visible.
3515 * @param obj The entry object
3516 * @return If true, the cursor is visible.
3521 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3523 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3524 Widget_Data *wd = elm_widget_data_get(obj);
3525 if (!wd) return EINA_FALSE;
3526 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3530 * TODO: fill this in
3532 * @param obj The entry object
3533 * @return TODO: fill this in
3538 elm_entry_cursor_content_get(const Evas_Object *obj)
3540 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3541 Widget_Data *wd = elm_widget_data_get(obj);
3542 if (!wd) return NULL;
3543 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3547 * Sets the cursor position in the entry to the given value
3549 * @param obj The entry object
3550 * @param pos The position of the cursor
3555 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3557 ELM_CHECK_WIDTYPE(obj, widtype);
3558 Widget_Data *wd = elm_widget_data_get(obj);
3560 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3561 edje_object_message_signal_process(wd->ent);
3565 * Retrieves the current position of the cursor in the entry
3567 * @param obj The entry object
3568 * @return The cursor position
3573 elm_entry_cursor_pos_get(const Evas_Object *obj)
3575 ELM_CHECK_WIDTYPE(obj, widtype) 0;
3576 Widget_Data *wd = elm_widget_data_get(obj);
3578 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3582 * This executes a "cut" action on the selected text in the entry.
3584 * @param obj The entry object
3589 elm_entry_selection_cut(Evas_Object *obj)
3591 ELM_CHECK_WIDTYPE(obj, widtype);
3592 Widget_Data *wd = elm_widget_data_get(obj);
3594 _cut(obj, NULL, NULL);
3598 * This executes a "copy" action on the selected text in the entry.
3600 * @param obj The entry object
3605 elm_entry_selection_copy(Evas_Object *obj)
3607 ELM_CHECK_WIDTYPE(obj, widtype);
3608 Widget_Data *wd = elm_widget_data_get(obj);
3610 _copy(obj, NULL, NULL);
3614 * This executes a "paste" action in the entry.
3616 * @param obj The entry object
3621 elm_entry_selection_paste(Evas_Object *obj)
3623 ELM_CHECK_WIDTYPE(obj, widtype);
3624 Widget_Data *wd = elm_widget_data_get(obj);
3626 _paste(obj, NULL, NULL);
3630 * This clears and frees the items in a entry's contextual (right click) menu.
3632 * @param obj The entry object
3637 elm_entry_context_menu_clear(Evas_Object *obj)
3639 ELM_CHECK_WIDTYPE(obj, widtype);
3640 Widget_Data *wd = elm_widget_data_get(obj);
3641 Elm_Entry_Context_Menu_Item *it;
3643 EINA_LIST_FREE(wd->items, it)
3645 eina_stringshare_del(it->label);
3646 eina_stringshare_del(it->icon_file);
3647 eina_stringshare_del(it->icon_group);
3653 * This adds an item to the entry's contextual menu.
3655 * @param obj The entry object
3656 * @param label The item's text label
3657 * @param icon_file The item's icon file
3658 * @param icon_type The item's icon type
3659 * @param func The callback to execute when the item is clicked
3660 * @param data The data to associate with the item for related functions
3665 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)
3667 ELM_CHECK_WIDTYPE(obj, widtype);
3668 Widget_Data *wd = elm_widget_data_get(obj);
3669 Elm_Entry_Context_Menu_Item *it;
3671 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3673 wd->items = eina_list_append(wd->items, it);
3675 it->label = eina_stringshare_add(label);
3676 it->icon_file = eina_stringshare_add(icon_file);
3677 it->icon_type = icon_type;
3679 it->data = (void *)data;
3683 * This disables the entry's contextual (right click) menu.
3685 * @param obj The entry object
3686 * @param disabled If true, the menu is disabled
3691 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3693 ELM_CHECK_WIDTYPE(obj, widtype);
3694 Widget_Data *wd = elm_widget_data_get(obj);
3696 if (wd->context_menu == !disabled) return;
3697 wd->context_menu = !disabled;
3701 * This returns whether the entry's contextual (right click) menu is disabled.
3703 * @param obj The entry object
3704 * @return If true, the menu is disabled
3709 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3711 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3712 Widget_Data *wd = elm_widget_data_get(obj);
3713 if (!wd) return EINA_FALSE;
3714 return !wd->context_menu;
3718 * This appends a custom item provider to the list for that entry
3720 * This appends the given callback. The list is walked from beginning to end
3721 * with each function called given the item href string in the text. If the
3722 * function returns an object handle other than NULL (it should create an
3723 * and object to do this), then this object is used to replace that item. If
3724 * not the next provider is called until one provides an item object, or the
3725 * default provider in entry does.
3727 * @param obj The entry object
3728 * @param func The function called to provide the item object
3729 * @param data The data passed to @p func
3734 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3736 ELM_CHECK_WIDTYPE(obj, widtype);
3737 Widget_Data *wd = elm_widget_data_get(obj);
3739 EINA_SAFETY_ON_NULL_RETURN(func);
3740 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3744 wd->item_providers = eina_list_append(wd->item_providers, ip);
3748 * This prepends a custom item provider to the list for that entry
3750 * This prepends the given callback. See elm_entry_item_provider_append() for
3753 * @param obj The entry object
3754 * @param func The function called to provide the item object
3755 * @param data The data passed to @p func
3760 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3762 ELM_CHECK_WIDTYPE(obj, widtype);
3763 Widget_Data *wd = elm_widget_data_get(obj);
3765 EINA_SAFETY_ON_NULL_RETURN(func);
3766 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3770 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3774 * This removes a custom item provider to the list for that entry
3776 * This removes the given callback. See elm_entry_item_provider_append() for
3779 * @param obj The entry object
3780 * @param func The function called to provide the item object
3781 * @param data The data passed to @p func
3786 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3788 ELM_CHECK_WIDTYPE(obj, widtype);
3789 Widget_Data *wd = elm_widget_data_get(obj);
3791 Elm_Entry_Item_Provider *ip;
3793 EINA_SAFETY_ON_NULL_RETURN(func);
3794 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3796 if ((ip->func == func) && ((!data) || (ip->data == data)))
3798 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3806 * Append a filter function for text inserted in the entry
3808 * Append the given callback to the list. This functions will be called
3809 * whenever any text is inserted into the entry, with the text to be inserted
3810 * as a parameter. The callback function is free to alter the text in any way
3811 * it wants, but it must remember to free the given pointer and update it.
3812 * If the new text is to be discarded, the function can free it and set it text
3813 * parameter to NULL. This will also prevent any following filters from being
3816 * @param obj The entry object
3817 * @param func The function to use as text filter
3818 * @param data User data to pass to @p func
3823 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3826 Elm_Entry_Text_Filter *tf;
3827 ELM_CHECK_WIDTYPE(obj, widtype);
3829 wd = elm_widget_data_get(obj);
3831 EINA_SAFETY_ON_NULL_RETURN(func);
3833 tf = _filter_new(func, data);
3836 wd->text_filters = eina_list_append(wd->text_filters, tf);
3840 * Prepend a filter function for text insdrted in the entry
3842 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3843 * for more information
3845 * @param obj The entry object
3846 * @param func The function to use as text filter
3847 * @param data User data to pass to @p func
3852 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3855 Elm_Entry_Text_Filter *tf;
3856 ELM_CHECK_WIDTYPE(obj, widtype);
3858 wd = elm_widget_data_get(obj);
3860 EINA_SAFETY_ON_NULL_RETURN(func);
3862 tf = _filter_new(func, data);
3865 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3869 * Remove a filter from the list
3871 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3872 * for more information.
3874 * @param obj The entry object
3875 * @param func The filter function to remove
3876 * @param data The user data passed when adding the function
3881 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3885 Elm_Entry_Text_Filter *tf;
3886 ELM_CHECK_WIDTYPE(obj, widtype);
3888 wd = elm_widget_data_get(obj);
3890 EINA_SAFETY_ON_NULL_RETURN(func);
3892 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3894 if ((tf->func == func) && ((!data) || (tf->data == data)))
3896 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3904 * This converts a markup (HTML-like) string into UTF-8.
3905 * Returning string is obtained with malloc.
3906 * After use the returned string, it should be freed.
3908 * @param s The string (in markup) to be converted
3909 * @return The converted string (in UTF-8). It should be freed.
3914 elm_entry_markup_to_utf8(const char *s)
3916 char *ss = _elm_util_mkup_to_text(s);
3917 if (!ss) ss = strdup("");
3922 * This converts a UTF-8 string into markup (HTML-like).
3923 * Returning string is obtained with malloc.
3924 * After use the returned string, it should be freed.
3926 * @param s The string (in UTF-8) to be converted
3927 * @return The converted string (in markup). It should be freed.
3932 elm_entry_utf8_to_markup(const char *s)
3934 char *ss = _elm_util_text_to_mkup(s);
3935 if (!ss) ss = strdup("");
3940 * Get the input method context in the entry widget
3942 * @param obj The entry object
3943 * @return The input method context
3947 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3949 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3950 Widget_Data *wd = elm_widget_data_get(obj);
3951 if (!wd || !wd->ent) return NULL;
3953 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3957 * Set whether entry should enable the return key on soft keyboard automatically
3959 * @param obj The entry object
3960 * @param on If true, entry enables the return key on soft keyboard automatically.
3965 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3967 ELM_CHECK_WIDTYPE(obj, widtype);
3968 Widget_Data *wd = elm_widget_data_get(obj);
3971 wd->autoreturnkey = on;
3972 _check_enable_returnkey(obj);
3976 * Set whether entry should support auto capitalization
3978 * @param obj The entry object
3979 * @param on If true, entry suports auto capitalization.
3984 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3986 ELM_CHECK_WIDTYPE(obj, widtype);
3987 Widget_Data *wd = elm_widget_data_get(obj);
3991 wd->autocapital = EINA_FALSE;
3993 wd->autocapital = autocap;
3995 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3996 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3997 wd->autocapital = EINA_FALSE;
3999 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
4003 * Set whether entry should support auto period
4005 * @param obj The entry object
4006 * @param on If true, entry suports auto period.
4011 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
4013 ELM_CHECK_WIDTYPE(obj, widtype);
4014 Widget_Data *wd = elm_widget_data_get(obj);
4018 wd->autoperiod = EINA_FALSE;
4020 wd->autoperiod = autoperiod;
4022 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4023 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4024 wd->autoperiod = EINA_FALSE;
4026 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
4030 * Set the font size on the entry object
4032 * @param obj The entry object
4033 * @param size font size
4038 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
4040 ELM_CHECK_WIDTYPE(obj, widtype);
4041 Widget_Data *wd = elm_widget_data_get(obj);
4042 Eina_Strbuf *fontbuf = NULL;
4047 t = eina_stringshare_add(elm_entry_entry_get(obj));
4048 fontbuf = eina_strbuf_new();
4049 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
4051 if (fontsize == 0) removeflag = 1; // remove fontsize tag
4053 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
4055 elm_entry_entry_set(obj, t);
4059 eina_strbuf_free(fontbuf);
4060 eina_stringshare_del(t);
4064 * Set the text align on the entry object
4066 * @param obj The entry object
4067 * @param align align mode
4072 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
4074 ELM_CHECK_WIDTYPE(obj, widtype);
4075 Widget_Data *wd = elm_widget_data_get(obj);
4080 t = eina_stringshare_add(elm_entry_entry_get(obj));
4082 if (len <= 0) return;
4084 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
4085 elm_entry_entry_set(obj, t);
4089 eina_stringshare_del(t);
4093 * Set the text color on the entry object
4095 * @param obj The entry object
4096 * @param r Red property background color of The entry object
4097 * @param g Green property background color of The entry object
4098 * @param b Blue property background color of The entry object
4099 * @param a Alpha property background alpha of The entry object
4104 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4106 ELM_CHECK_WIDTYPE(obj, widtype);
4107 Widget_Data *wd = elm_widget_data_get(obj);
4108 Eina_Strbuf *colorbuf = NULL;
4113 t = eina_stringshare_add(elm_entry_entry_get(obj));
4115 if (len <= 0) return;
4116 colorbuf = eina_strbuf_new();
4117 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
4119 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
4121 elm_entry_entry_set(obj, t);
4125 eina_strbuf_free(colorbuf);
4126 eina_stringshare_del(t);
4130 * Set background color of the entry
4132 * @param obj The entry object
4133 * @param r Red property background color of The entry object
4134 * @param g Green property background color of The entry object
4135 * @param b Blue property background color of The entry object
4136 * @param a Alpha property background alpha of The entry object
4140 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4142 ELM_CHECK_WIDTYPE(obj, widtype);
4143 Widget_Data *wd = elm_widget_data_get(obj);
4144 evas_object_color_set(wd->bg, r, g, b, a);
4146 if (wd->bgcolor == EINA_FALSE)
4149 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
4154 * Filter inserted text based on user defined character and byte limits
4156 * Add this filter to an entry to limit the characters that it will accept
4157 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
4158 * The funtion works on the UTF-8 representation of the string, converting
4159 * it from the set markup, thus not accounting for any format in it.
4161 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
4162 * it as data when setting the filter. In it it's possible to set limits
4163 * by character count or bytes (any of them is disabled if 0), and both can
4164 * be set at the same time. In that case, it first checks for characters,
4167 * The function will cut the inserted text in order to allow only the first
4168 * number of characters that are still allowed. The cut is made in
4169 * characters, even when limiting by bytes, in order to always contain
4170 * valid ones and avoid half unicode characters making it in.
4175 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
4177 Elm_Entry_Filter_Limit_Size *lim = data;
4180 const char *(*text_get)(const Evas_Object *);
4181 const char *widget_type;
4183 EINA_SAFETY_ON_NULL_RETURN(data);
4184 EINA_SAFETY_ON_NULL_RETURN(entry);
4185 EINA_SAFETY_ON_NULL_RETURN(text);
4187 /* hack. I don't want to copy the entire function to work with
4189 widget_type = elm_widget_type_get(entry);
4190 if (!strcmp(widget_type, "entry"))
4191 text_get = elm_entry_entry_get;
4195 current = elm_entry_markup_to_utf8(text_get(entry));
4197 if (lim->max_char_count > 0)
4199 len = evas_string_char_len_get(current);
4200 if (len >= lim->max_char_count)
4202 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4208 newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
4209 if ((len + newlen) > lim->max_char_count)
4210 _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
4212 else if (lim->max_byte_count > 0)
4214 len = strlen(current);
4215 if (len >= lim->max_byte_count)
4217 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4223 newlen = strlen(elm_entry_markup_to_utf8(*text));
4224 if ((len + newlen) > lim->max_byte_count)
4225 _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
4231 * Filter inserted text based on accepted or rejected sets of characters
4233 * Add this filter to an entry to restrict the set of accepted characters
4234 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
4235 * This structure contains both accepted and rejected sets, but they are
4236 * mutually exclusive. If accepted is set, it will be used, otherwise it
4237 * goes on to the rejected set.
4240 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
4242 Elm_Entry_Filter_Accept_Set *as = data;
4246 int read_idx, last_read_idx = 0, read_char;
4248 EINA_SAFETY_ON_NULL_RETURN(data);
4249 EINA_SAFETY_ON_NULL_RETURN(text);
4251 if ((!as->accepted) && (!as->rejected))
4257 goes_in = EINA_TRUE;
4262 goes_in = EINA_FALSE;
4266 read_idx = evas_string_char_next_get(*text, 0, &read_char);
4269 int cmp_idx, cmp_char;
4270 Eina_Bool in_set = EINA_FALSE;
4272 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4275 if (read_char == cmp_char)
4280 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4282 if (in_set == goes_in)
4284 int size = read_idx - last_read_idx;
4285 const char *src = (*text) + last_read_idx;
4287 memcpy(insert, *text + last_read_idx, size);
4290 last_read_idx = read_idx;
4291 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4297 * This sets the file (and implicitly loads it) for the text to display and
4298 * then edit. All changes are written back to the file after a short delay if
4299 * the entry object is set to autosave.
4301 * @param obj The entry object
4302 * @param file The path to the file to load and save
4303 * @param format The file format
4308 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4310 ELM_CHECK_WIDTYPE(obj, widtype);
4311 Widget_Data *wd = elm_widget_data_get(obj);
4313 if (wd->delay_write)
4315 ecore_timer_del(wd->delay_write);
4316 wd->delay_write = NULL;
4318 if (wd->autosave) _save(obj);
4319 eina_stringshare_replace(&wd->file, file);
4320 wd->format = format;
4325 * Gets the file to load and save and the file format
4327 * @param obj The entry object
4328 * @param file The path to the file to load and save
4329 * @param format The file format
4334 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4336 ELM_CHECK_WIDTYPE(obj, widtype);
4337 Widget_Data *wd = elm_widget_data_get(obj);
4339 if (file) *file = wd->file;
4340 if (format) *format = wd->format;
4344 * This function writes any changes made to the file set with
4345 * elm_entry_file_set()
4347 * @param obj The entry object
4352 elm_entry_file_save(Evas_Object *obj)
4354 ELM_CHECK_WIDTYPE(obj, widtype);
4355 Widget_Data *wd = elm_widget_data_get(obj);
4357 if (wd->delay_write)
4359 ecore_timer_del(wd->delay_write);
4360 wd->delay_write = NULL;
4363 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4367 * This sets the entry object to 'autosave' the loaded text file or not.
4369 * @param obj The entry object
4370 * @param autosave Autosave the loaded file or not
4375 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4377 ELM_CHECK_WIDTYPE(obj, widtype);
4378 Widget_Data *wd = elm_widget_data_get(obj);
4380 wd->autosave = !!autosave;
4384 * This gets the entry object's 'autosave' status.
4386 * @param obj The entry object
4387 * @return Autosave the loaded file or not
4392 elm_entry_autosave_get(const Evas_Object *obj)
4394 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4395 Widget_Data *wd = elm_widget_data_get(obj);
4396 if (!wd) return EINA_FALSE;
4397 return wd->autosave;
4401 * Control pasting of text and images for the widget.
4403 * Normally the entry allows both text and images to be pasted. By setting
4404 * textonly to be true, this prevents images from being pasted.
4406 * Note this only changes the behaviour of text.
4408 * @param obj The entry object
4409 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
4414 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4416 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4417 ELM_CHECK_WIDTYPE(obj, widtype);
4418 Widget_Data *wd = elm_widget_data_get(obj);
4420 textonly = !!textonly;
4421 if (wd->textonly == textonly) return;
4422 wd->textonly = !!textonly;
4423 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
4424 #ifdef HAVE_ELEMENTARY_X
4425 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
4430 * Getting elm_entry text paste/drop mode.
4432 * In textonly mode, only text may be pasted or dropped into the widget.
4434 * @param obj The entry object
4435 * @return If the widget only accepts text from pastes.
4440 elm_entry_cnp_textonly_get(const Evas_Object *obj)
4442 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4443 Widget_Data *wd = elm_widget_data_get(obj);
4444 if (!wd) return EINA_FALSE;
4445 return wd->textonly;
4449 * Enable or disable scrolling in entry
4451 * Normally the entry is not scrollable unless you enable it with this call.
4453 * @param obj The entry object
4454 * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
4459 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
4461 ELM_CHECK_WIDTYPE(obj, widtype);
4462 Widget_Data *wd = elm_widget_data_get(obj);
4465 if (wd->scroll == scroll) return;
4466 wd->scroll = scroll;
4469 elm_widget_sub_object_del(obj, wd->scroller);
4470 elm_widget_resize_object_set(obj, wd->scroller);
4471 elm_widget_sub_object_add(obj, wd->ent);
4472 elm_smart_scroller_child_set(wd->scroller, wd->ent);
4473 evas_object_show(wd->scroller);
4474 elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
4475 if (wd->single_line)
4477 elm_smart_scroller_policy_set(wd->scroller,
4478 ELM_SMART_SCROLLER_POLICY_OFF,
4479 ELM_SMART_SCROLLER_POLICY_OFF);
4480 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4484 const Elm_Scroller_Policy map[3] =
4486 ELM_SMART_SCROLLER_POLICY_AUTO,
4487 ELM_SMART_SCROLLER_POLICY_ON,
4488 ELM_SMART_SCROLLER_POLICY_OFF
4490 elm_smart_scroller_policy_set(wd->scroller,
4493 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4498 elm_smart_scroller_child_set(wd->scroller, NULL);
4499 elm_widget_sub_object_del(obj, wd->ent);
4500 elm_widget_resize_object_set(obj, wd->ent);
4501 evas_object_smart_member_add(wd->scroller, obj);
4502 elm_widget_sub_object_add(obj, wd->scroller);
4503 evas_object_hide(wd->scroller);
4504 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
4511 * Get the scrollable state of the entry
4513 * Normally the entry is not scrollable. This gets the scrollable state
4514 * of the entry. See elm_entry_scrollable_set() for more information.
4516 * @param obj The entry object
4517 * @return The scrollable state
4522 elm_entry_scrollable_get(const Evas_Object *obj)
4524 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4525 Widget_Data *wd = elm_widget_data_get(obj);
4526 if (!wd) return EINA_FALSE;
4531 * This sets a widget to be displayed to the left of a scrolled entry.
4533 * @param obj The scrolled entry object
4534 * @param icon The widget to display on the left side of the scrolled
4537 * @note A previously set widget will be destroyed.
4538 * @note If the object being set does not have minimum size hints set,
4539 * it won't get properly displayed.
4542 * @see elm_entry_end_set
4545 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
4547 ELM_CHECK_WIDTYPE(obj, widtype);
4548 Widget_Data *wd = elm_widget_data_get(obj);
4551 EINA_SAFETY_ON_NULL_RETURN(icon);
4552 if (wd->icon == icon) return;
4553 if (wd->icon) evas_object_del(wd->icon);
4555 edje = elm_smart_scroller_edje_object_get(wd->scroller);
4557 edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
4558 edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
4563 * Gets the leftmost widget of the scrolled entry. This object is
4564 * owned by the scrolled entry and should not be modified.
4566 * @param obj The scrolled entry object
4567 * @return the left widget inside the scroller
4572 elm_entry_icon_get(const Evas_Object *obj)
4574 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4575 Widget_Data *wd = elm_widget_data_get(obj);
4576 if (!wd) return NULL;
4581 * Unset the leftmost widget of the scrolled entry, unparenting and
4584 * @param obj The scrolled entry object
4585 * @return the previously set icon sub-object of this entry, on
4588 * @see elm_entry_icon_set()
4593 elm_entry_icon_unset(Evas_Object *obj)
4595 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4596 Widget_Data *wd = elm_widget_data_get(obj);
4597 Evas_Object *ret = NULL;
4598 if (!wd) return NULL;
4601 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4602 if (!edje) return NULL;
4604 edje_object_part_unswallow(edje, wd->icon);
4605 edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
4613 * Sets the visibility of the left-side widget of the scrolled entry,
4614 * set by @elm_entry_icon_set().
4616 * @param obj The scrolled entry object
4617 * @param setting EINA_TRUE if the object should be displayed,
4618 * EINA_FALSE if not.
4623 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
4625 ELM_CHECK_WIDTYPE(obj, widtype);
4626 Widget_Data *wd = elm_widget_data_get(obj);
4627 if ((!wd) || (!wd->icon)) return;
4629 evas_object_hide(wd->icon);
4631 evas_object_show(wd->icon);
4636 * This sets a widget to be displayed to the end of a scrolled entry.
4638 * @param obj The scrolled entry object
4639 * @param end The widget to display on the right side of the scrolled
4642 * @note A previously set widget will be destroyed.
4643 * @note If the object being set does not have minimum size hints set,
4644 * it won't get properly displayed.
4647 * @see elm_entry_icon_set
4650 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
4652 ELM_CHECK_WIDTYPE(obj, widtype);
4653 Widget_Data *wd = elm_widget_data_get(obj);
4656 EINA_SAFETY_ON_NULL_RETURN(end);
4657 if (wd->end == end) return;
4658 if (wd->end) evas_object_del(wd->end);
4660 edje = elm_smart_scroller_edje_object_get(wd->scroller);
4662 edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
4663 edje_object_signal_emit(edje, "elm,action,show,end", "elm");
4668 * Gets the endmost widget of the scrolled entry. This object is owned
4669 * by the scrolled entry and should not be modified.
4671 * @param obj The scrolled entry object
4672 * @return the right widget inside the scroller
4677 elm_entry_end_get(const Evas_Object *obj)
4679 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4680 Widget_Data *wd = elm_widget_data_get(obj);
4681 if (!wd) return NULL;
4686 * Unset the endmost widget of the scrolled entry, unparenting and
4689 * @param obj The scrolled entry object
4690 * @return the previously set icon sub-object of this entry, on
4693 * @see elm_entry_icon_set()
4698 elm_entry_end_unset(Evas_Object *obj)
4700 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4701 Widget_Data *wd = elm_widget_data_get(obj);
4702 Evas_Object *ret = NULL;
4703 if (!wd) return NULL;
4706 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4707 if (!edje) return NULL;
4709 edje_object_part_unswallow(edje, wd->end);
4710 edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
4718 * Sets the visibility of the end widget of the scrolled entry, set by
4719 * @elm_entry_end_set().
4721 * @param obj The scrolled entry object
4722 * @param setting EINA_TRUE if the object should be displayed,
4723 * EINA_FALSE if not.
4728 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
4730 ELM_CHECK_WIDTYPE(obj, widtype);
4731 Widget_Data *wd = elm_widget_data_get(obj);
4732 if ((!wd) || (!wd->end)) return;
4734 evas_object_hide(wd->end);
4736 evas_object_show(wd->end);
4741 * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
4743 * @param obj The scrolled entry object
4744 * @param h The horizontal scrollbar policy to apply
4745 * @param v The vertical scrollbar policy to apply
4750 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
4752 ELM_CHECK_WIDTYPE(obj, widtype);
4753 Widget_Data *wd = elm_widget_data_get(obj);
4754 const Elm_Scroller_Policy map[3] =
4756 ELM_SMART_SCROLLER_POLICY_AUTO,
4757 ELM_SMART_SCROLLER_POLICY_ON,
4758 ELM_SMART_SCROLLER_POLICY_OFF
4763 elm_smart_scroller_policy_set(wd->scroller,
4769 * This enables/disables bouncing within the entry.
4771 * @param obj The scrolled entry object
4772 * @param h The horizontal bounce state
4773 * @param v The vertical bounce state
4778 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
4780 ELM_CHECK_WIDTYPE(obj, widtype);
4781 Widget_Data *wd = elm_widget_data_get(obj);
4783 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
4787 * Get the bounce mode
4789 * @param obj The Entry object
4790 * @param h_bounce Allow bounce horizontally
4791 * @param v_bounce Allow bounce vertically
4796 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
4798 ELM_CHECK_WIDTYPE(obj, widtype);
4799 Widget_Data *wd = elm_widget_data_get(obj);
4801 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
4805 * This sets the attribute to show the input panel automatically.
4807 * @param obj The entry object
4808 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4813 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4815 ELM_CHECK_WIDTYPE(obj, widtype);
4816 Widget_Data *wd = elm_widget_data_get(obj);
4819 wd->input_panel_enable = enabled;
4820 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4824 * Set the input panel layout of the entry
4826 * @param obj The entry object
4827 * @param layout the layout to set
4832 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4834 ELM_CHECK_WIDTYPE(obj, widtype);
4835 Widget_Data *wd = elm_widget_data_get(obj);
4838 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4841 wd->input_panel_layout = layout;
4843 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4847 * Set the magnifier style of the entry
4849 * @param obj The entry object
4850 * @param type the magnifier style to set
4855 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4857 ELM_CHECK_WIDTYPE(obj, widtype);
4858 Widget_Data *wd = elm_widget_data_get(obj);
4861 wd->mgf_type = type;
4862 _magnifier_create(obj);
4865 EINA_DEPRECATED EAPI void
4866 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
4868 if (wrap) elm_entry_line_wrap_set(obj, ELM_WRAP_CHAR);