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
97 typedef struct _Mod_Api Mod_Api;
99 typedef struct _Widget_Data Widget_Data;
100 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
101 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
102 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
108 Evas_Object *hoversel;
112 Evas_Object *mgf_proxy;
113 Evas_Object *mgf_clip;
115 Evas_Coord mgf_height;
118 Ecore_Job *deferred_recalc_job;
119 Ecore_Event_Handler *sel_notify_handler;
120 Ecore_Event_Handler *sel_clear_handler;
121 Ecore_Timer *longpress_timer;
122 Ecore_Timer *delay_write;
123 /* Only for clipboard */
128 Elm_Text_Format format;
130 Evas_Coord downx, downy;
131 Evas_Coord cx, cy, cw, ch;
133 Eina_List *item_providers;
134 Eina_List *text_filters;
135 Eina_List *match_list;
136 Ecore_Job *matchlist_job;
137 Ecore_Job *hovdeljob;
138 Mod_Api *api; // module api if supplied
141 Eina_Bool changed : 1;
142 Eina_Bool linewrap : 1;
143 Eina_Bool char_linewrap : 1;
144 Eina_Bool single_line : 1;
145 Eina_Bool password : 1;
146 Eina_Bool show_last_character : 1;
147 Eina_Bool editable : 1;
148 Eina_Bool selection_asked : 1;
149 Eina_Bool have_selection : 1;
150 Eina_Bool selmode : 1;
151 Eina_Bool deferred_cur : 1;
152 Eina_Bool disabled : 1;
153 Eina_Bool double_clicked : 1;
154 Eina_Bool long_pressed : 1;
155 Eina_Bool context_menu : 1;
156 Eina_Bool drag_selection_asked : 1;
157 Eina_Bool bgcolor : 1;
158 Eina_Bool can_write : 1;
159 Eina_Bool autosave : 1;
160 Eina_Bool textonly : 1;
161 Eina_Bool usedown : 1;
162 Eina_Bool autoreturnkey : 1;
163 Eina_Bool input_panel_enable : 1;
164 Eina_Bool autocapital : 1;
165 Elm_Input_Panel_Layout input_panel_layout;
166 Eina_Bool autoperiod : 1;
167 Eina_Bool matchlist_list_clicked : 1;
168 Eina_Bool matchlist_case_sensitive : 1;
169 int matchlist_threshold;
172 struct _Elm_Entry_Context_Menu_Item
176 const char *icon_file;
177 const char *icon_group;
178 Elm_Icon_Type icon_type;
183 struct _Elm_Entry_Item_Provider
185 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
189 struct _Elm_Entry_Text_Filter
191 void (*func) (void *data, Evas_Object *entry, char **text);
195 static const char *widtype = NULL;
197 static Evas_Object *cnpwidgetdata = NULL;
200 #ifdef HAVE_ELEMENTARY_X
201 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
203 static void _del_hook(Evas_Object *obj);
204 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
205 static void _theme_hook(Evas_Object *obj);
206 static void _disable_hook(Evas_Object *obj);
207 static void _sizing_eval(Evas_Object *obj);
208 static void _on_focus_hook(void *data, Evas_Object *obj);
209 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
210 static const char *_getbase(Evas_Object *obj);
211 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
212 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
213 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
214 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
215 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
216 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
217 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
218 static void _signal_handler_moving(void *data, Evas_Object *obj, const char *emission, const char *source);
219 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
220 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
221 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
222 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
223 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
224 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
225 static int _entry_length_get(Evas_Object *obj);
226 static void _magnifier_create(void *data);
227 static void _magnifier_show(void *data);
228 static void _magnifier_hide(void *data);
229 static void _magnifier_move(void *data);
231 static const char SIG_CHANGED[] = "changed";
232 static const char SIG_ACTIVATED[] = "activated";
233 static const char SIG_PRESS[] = "press";
234 static const char SIG_LONGPRESSED[] = "longpressed";
235 static const char SIG_CLICKED[] = "clicked";
236 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
237 static const char SIG_FOCUSED[] = "focused";
238 static const char SIG_UNFOCUSED[] = "unfocused";
239 static const char SIG_SELECTION_PASTE[] = "selection,paste";
240 static const char SIG_SELECTION_COPY[] = "selection,copy";
241 static const char SIG_SELECTION_CUT[] = "selection,cut";
242 static const char SIG_SELECTION_START[] = "selection,start";
243 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
244 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
245 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
246 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
247 static const char SIG_MATCHLIST_CLICKED[] = "matchlist,clicked";
248 static const Evas_Smart_Cb_Description _signals[] = {
252 {SIG_LONGPRESSED, ""},
254 {SIG_CLICKED_DOUBLE, ""},
257 {SIG_SELECTION_PASTE, ""},
258 {SIG_SELECTION_COPY, ""},
259 {SIG_SELECTION_CUT, ""},
260 {SIG_SELECTION_START, ""},
261 {SIG_SELECTION_CHANGED, ""},
262 {SIG_SELECTION_CLEARED, ""},
263 {SIG_CURSOR_CHANGED, ""},
264 {SIG_ANCHOR_CLICKED, ""},
265 {SIG_MATCHLIST_CLICKED, ""},
269 typedef enum _Elm_Entry_Magnifier_Type
271 _ENTRY_MAGNIFIER_FIXEDSIZE = 0,
272 _ENTRY_MAGNIFIER_FILLWIDTH,
273 _ENTRY_MAGNIFIER_CIRCULAR,
274 } Elm_Entry_Magnifier_Type;
277 static Eina_List *entries = NULL;
281 void (*obj_hook) (Evas_Object *obj);
282 void (*obj_unhook) (Evas_Object *obj);
283 void (*obj_longpress) (Evas_Object *obj);
284 void (*obj_hidemenu) (Evas_Object *obj);
285 void (*obj_mouseup) (Evas_Object *obj);
289 _module(Evas_Object *obj __UNUSED__)
291 static Elm_Module *m = NULL;
292 if (m) goto ok; // already found - just use
293 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
295 m->api = malloc(sizeof(Mod_Api));
296 if (!m->api) return NULL;
297 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
298 _elm_module_symbol_get(m, "obj_hook");
299 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
300 _elm_module_symbol_get(m, "obj_unhook");
301 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
302 _elm_module_symbol_get(m, "obj_longpress");
303 ((Mod_Api *)(m->api) )->obj_hidemenu = // called on hide menu
304 _elm_module_symbol_get(m, "obj_hidemenu");
305 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
306 _elm_module_symbol_get(m, "obj_mouseup");
307 ok: // ok - return api
312 _buf_append(char *buf, const char *str, int *len, int *alloc)
314 int len2 = strlen(str);
315 if ((*len + len2) >= *alloc)
317 char *buf2 = realloc(buf, *alloc + len2 + 512);
318 if (!buf2) return NULL;
320 *alloc += (512 + len2);
322 strcpy(buf + *len, str);
328 _load_file(const char *file)
332 int alloc = 0, len = 0;
333 char *text = NULL, buf[16384 + 1];
335 f = fopen(file, "rb");
337 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
341 tmp_text = _buf_append(text, buf, &len, &alloc);
342 if (!tmp_text) break;
350 _load_plain(const char *file)
354 text = _load_file(file);
359 text2 = elm_entry_utf8_to_markup(text);
367 _load(Evas_Object *obj)
369 Widget_Data *wd = elm_widget_data_get(obj);
374 elm_entry_entry_set(obj, "");
379 case ELM_TEXT_FORMAT_PLAIN_UTF8:
380 text = _load_plain(wd->file);
382 case ELM_TEXT_FORMAT_MARKUP_UTF8:
383 text = _load_file(wd->file);
391 elm_entry_entry_set(obj, text);
395 elm_entry_entry_set(obj, "");
399 _save_markup_utf8(const char *file, const char *text)
403 if ((!text) || (!text[0]))
405 ecore_file_unlink(file);
408 f = fopen(file, "wb");
411 // FIXME: report a write error
414 fputs(text, f); // FIXME: catch error
419 _save_plain_utf8(const char *file, const char *text)
423 text2 = elm_entry_markup_to_utf8(text);
426 _save_markup_utf8(file, text2);
431 _save(Evas_Object *obj)
433 Widget_Data *wd = elm_widget_data_get(obj);
435 if (!wd->file) return;
438 case ELM_TEXT_FORMAT_PLAIN_UTF8:
439 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
441 case ELM_TEXT_FORMAT_MARKUP_UTF8:
442 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
450 _delay_write(void *data)
452 Widget_Data *wd = elm_widget_data_get(data);
453 if (!wd) return ECORE_CALLBACK_CANCEL;
455 wd->delay_write = NULL;
456 return ECORE_CALLBACK_CANCEL;
459 static Elm_Entry_Text_Filter *
460 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
462 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
463 if (!tf) return NULL;
466 if (func == elm_entry_filter_limit_size)
468 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
475 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
481 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
484 else if (func == elm_entry_filter_accept_set)
486 Elm_Entry_Filter_Accept_Set *as = data, *as2;
493 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
500 as2->accepted = eina_stringshare_add(as->accepted);
502 as2->accepted = NULL;
504 as2->rejected = eina_stringshare_add(as->rejected);
506 as2->rejected = NULL;
515 _filter_free(Elm_Entry_Text_Filter *tf)
517 if (tf->func == elm_entry_filter_limit_size)
519 Elm_Entry_Filter_Limit_Size *lim = tf->data;
522 else if (tf->func == elm_entry_filter_accept_set)
524 Elm_Entry_Filter_Accept_Set *as = tf->data;
527 if (as->accepted) eina_stringshare_del(as->accepted);
528 if (as->rejected) eina_stringshare_del(as->rejected);
536 _del_pre_hook(Evas_Object *obj)
538 Widget_Data *wd = elm_widget_data_get(obj);
542 ecore_timer_del(wd->delay_write);
543 wd->delay_write = NULL;
544 if (wd->autosave) _save(obj);
549 _del_hook(Evas_Object *obj)
551 Widget_Data *wd = elm_widget_data_get(obj);
552 Elm_Entry_Context_Menu_Item *it;
553 Elm_Entry_Item_Provider *ip;
554 Elm_Entry_Text_Filter *tf;
556 if (wd->file) eina_stringshare_del(wd->file);
558 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
559 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
561 entries = eina_list_remove(entries, obj);
562 #ifdef HAVE_ELEMENTARY_X
563 ecore_event_handler_del(wd->sel_notify_handler);
564 ecore_event_handler_del(wd->sel_clear_handler);
566 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
567 if (wd->text) eina_stringshare_del(wd->text);
568 if (wd->bg) evas_object_del(wd->bg);
569 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
570 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
571 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
572 if (wd->mgf_proxy) evas_object_del(wd->mgf_proxy);
573 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
574 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
576 EINA_LIST_FREE(wd->items, it)
578 eina_stringshare_del(it->label);
579 eina_stringshare_del(it->icon_file);
580 eina_stringshare_del(it->icon_group);
583 EINA_LIST_FREE(wd->item_providers, ip)
587 EINA_LIST_FREE(wd->text_filters, tf)
595 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
597 Widget_Data *wd = elm_widget_data_get(obj);
598 edje_object_mirrored_set(wd->ent, rtl);
602 _theme_hook(Evas_Object *obj)
604 Widget_Data *wd = elm_widget_data_get(obj);
606 Ecore_IMF_Context *ic;
607 _elm_widget_mirrored_reload(obj);
608 _mirrored_set(obj, elm_widget_mirrored_get(obj));
610 t = eina_stringshare_add(elm_entry_entry_get(obj));
611 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
612 if (_elm_config->desktop_entry)
613 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
614 elm_entry_entry_set(obj, t);
615 eina_stringshare_del(t);
616 if (elm_widget_disabled_get(obj))
617 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
618 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
619 if (elm_widget_focus_get(obj))
620 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
621 edje_object_message_signal_process(wd->ent);
622 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
623 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
627 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", EINA_FALSE);
628 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", EINA_FALSE);
632 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
633 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
636 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
639 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
646 _disable_hook(Evas_Object *obj)
648 Widget_Data *wd = elm_widget_data_get(obj);
650 if (elm_widget_disabled_get(obj))
652 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
653 wd->disabled = EINA_TRUE;
657 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
658 wd->disabled = EINA_FALSE;
663 _elm_win_recalc_job(void *data)
665 Widget_Data *wd = elm_widget_data_get(data);
666 Evas_Coord minh = -1, resw = -1;
668 wd->deferred_recalc_job = NULL;
669 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
670 edje_object_size_min_restricted_calc(wd->ent, NULL, &minh, resw, 0);
671 elm_coords_finger_size_adjust(1, NULL, 1, &minh);
672 evas_object_size_hint_min_set(data, -1, minh);
674 evas_object_size_hint_max_set(data, -1, minh);
676 if (wd->deferred_cur)
677 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
681 _sizing_eval(Evas_Object *obj)
683 Widget_Data *wd = elm_widget_data_get(obj);
684 Evas_Coord minw = -1, minh = -1;
685 Evas_Coord resw, resh;
687 if ((wd->linewrap) || (wd->char_linewrap))
689 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
690 if ((resw == wd->lastw) && (!wd->changed)) return;
691 wd->changed = EINA_FALSE;
693 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
694 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
698 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
699 edje_object_size_min_calc(wd->ent, &minw, &minh);
700 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
701 evas_object_size_hint_min_set(obj, minw, minh);
703 evas_object_size_hint_max_set(obj, -1, minh);
708 _check_enable_returnkey(Evas_Object *obj)
710 Widget_Data *wd = elm_widget_data_get(obj);
713 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
716 if (!wd->autoreturnkey) return;
718 if (_entry_length_get(obj) == 0)
720 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
724 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
729 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
731 Widget_Data *wd = elm_widget_data_get(obj);
732 Evas_Object *top = elm_widget_top_get(obj);
734 if (!wd->editable) return;
735 if (elm_widget_focus_get(obj))
737 printf("[Elm_entry::Focused] obj : %p\n", obj);
738 evas_object_focus_set(wd->ent, EINA_TRUE);
739 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
740 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
741 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
742 _check_enable_returnkey(obj);
743 wd->mgf_type = _ENTRY_MAGNIFIER_FILLWIDTH;
744 _magnifier_create(obj);
748 printf("[Elm_entry::Unfocused] obj : %p\n", obj);
749 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
750 evas_object_focus_set(wd->ent, EINA_FALSE);
751 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
752 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
754 if ((wd->api) && (wd->api->obj_hidemenu))
756 wd->api->obj_hidemenu(obj);
762 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
764 Widget_Data *wd = elm_widget_data_get(obj);
766 edje_object_signal_emit(wd->ent, emission, source);
770 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
772 Widget_Data *wd = elm_widget_data_get(obj);
774 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
778 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
780 Widget_Data *wd = elm_widget_data_get(obj);
781 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
786 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
788 Widget_Data *wd = elm_widget_data_get(obj);
789 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
793 _hoversel_position(Evas_Object *obj)
795 Widget_Data *wd = elm_widget_data_get(obj);
796 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
801 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
810 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
812 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
823 evas_object_move(wd->hoversel, x + cx, y + cy);
824 evas_object_resize(wd->hoversel, cw, ch);
828 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
830 Widget_Data *wd = elm_widget_data_get(data);
832 if (wd->hoversel) _hoversel_position(data);
836 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
838 Widget_Data *wd = elm_widget_data_get(data);
840 if ((wd->linewrap) || (wd->char_linewrap))
844 if (wd->hoversel) _hoversel_position(data);
845 // Evas_Coord ww, hh;
846 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
850 _hover_del(void *data)
852 Widget_Data *wd = elm_widget_data_get(data);
857 evas_object_del(wd->hoversel);
860 wd->hovdeljob = NULL;
864 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
866 Widget_Data *wd = elm_widget_data_get(data);
869 if (wd->hoversel) evas_object_hide(wd->hoversel);
872 if (!_elm_config->desktop_entry)
875 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
878 elm_widget_scroll_freeze_pop(data);
879 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
880 wd->hovdeljob = ecore_job_add(_hover_del, data);
884 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
886 Widget_Data *wd = elm_widget_data_get(data);
888 wd->selmode = EINA_TRUE;
889 edje_object_part_text_select_none(wd->ent, "elm.text");
890 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
891 edje_object_part_text_select_all(wd->ent, "elm.text");
892 elm_object_scroll_freeze_pop(data);
896 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
898 Widget_Data *wd = elm_widget_data_get(data);
900 wd->selmode = EINA_TRUE;
901 edje_object_part_text_select_none(wd->ent, "elm.text");
902 if (!_elm_config->desktop_entry)
905 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
907 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
908 if (!_elm_config->desktop_entry)
909 elm_object_scroll_freeze_pop(data);
910 //elm_widget_scroll_hold_push(data);
914 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
916 Widget_Data *wd = elm_widget_data_get(data);
918 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
919 if (wd->sel_notify_handler)
921 #ifdef HAVE_ELEMENTARY_X
922 Elm_Sel_Format formats;
923 wd->selection_asked = EINA_TRUE;
924 formats = ELM_SEL_FORMAT_MARKUP;
926 formats |= ELM_SEL_FORMAT_IMAGE;
927 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
933 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
935 Widget_Data *wd = elm_widget_data_get(obj);
939 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
940 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
941 if (seltype == ELM_SEL_CLIPBOARD)
942 eina_stringshare_replace(&wd->cut_sel, sel);
946 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
948 Widget_Data *wd = elm_widget_data_get(data);
951 wd->selmode = EINA_FALSE;
952 if (!_elm_config->desktop_entry)
953 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
954 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
955 if (!_elm_config->desktop_entry)
956 elm_widget_scroll_hold_pop(data);
957 _store_selection(ELM_SEL_CLIPBOARD, data);
958 edje_object_part_text_insert(wd->ent, "elm.text", "");
959 edje_object_part_text_select_none(wd->ent, "elm.text");
963 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
965 Widget_Data *wd = elm_widget_data_get(data);
967 //wd->selmode = EINA_FALSE;
968 if (!_elm_config->desktop_entry)
970 //edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
971 //edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
972 elm_widget_scroll_hold_pop(data);
974 _store_selection(ELM_SEL_CLIPBOARD, data);
975 // edje_object_part_text_select_none(wd->ent, "elm.text");
979 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
981 Widget_Data *wd = elm_widget_data_get(data);
983 wd->selmode = EINA_FALSE;
984 if (!_elm_config->desktop_entry)
985 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
986 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
987 if (!_elm_config->desktop_entry)
988 elm_widget_scroll_hold_pop(data);
989 edje_object_part_text_select_none(wd->ent, "elm.text");
993 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
995 Widget_Data *wd = elm_widget_data_get(data);
999 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
1000 cnpwidgetdata = data;
1001 elm_cbhm_helper_init(obj);
1002 if (elm_entry_cnp_textonly_get(obj))
1003 elm_cbhm_send_raw_data("show0");
1005 elm_cbhm_send_raw_data("show1");
1011 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1013 Widget_Data *wd = elm_widget_data_get(data);
1015 cnpwidgetdata = data;
1021 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1023 Elm_Entry_Context_Menu_Item *it = data;
1024 Evas_Object *obj2 = it->obj;
1025 if (it->func) it->func(it->data, obj2, NULL);
1029 _menu_press(Evas_Object *obj)
1031 Widget_Data *wd = elm_widget_data_get(obj);
1034 const Elm_Entry_Context_Menu_Item *it;
1036 if ((wd->api) && (wd->api->obj_longpress))
1038 wd->api->obj_longpress(obj);
1040 else if (wd->context_menu)
1042 const char *context_menu_orientation;
1044 if (wd->hoversel) evas_object_del(wd->hoversel);
1045 else elm_widget_scroll_freeze_push(obj);
1046 wd->hoversel = elm_hoversel_add(obj);
1047 context_menu_orientation = edje_object_data_get
1048 (wd->ent, "context_menu_orientation");
1049 if ((context_menu_orientation) &&
1050 (!strcmp(context_menu_orientation, "horizontal")))
1051 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1052 elm_object_style_set(wd->hoversel, "entry");
1053 elm_widget_sub_object_add(obj, wd->hoversel);
1054 elm_hoversel_label_set(wd->hoversel, "Text");
1055 top = elm_widget_top_get(obj);
1056 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1057 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1061 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1063 if (1) // need way to detect if someone has a selection
1066 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1070 if ((!wd->password) && (wd->editable))
1071 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1072 _clipboard_menu, obj);
1079 if (wd->have_selection)
1081 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1084 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1087 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1091 elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1092 _clipboard_menu, obj);
1096 EINA_LIST_FOREACH(wd->items, l, it)
1098 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1099 it->icon_type, _item_clicked, it);
1103 _hoversel_position(obj);
1104 evas_object_show(wd->hoversel);
1105 elm_hoversel_hover_begin(wd->hoversel);
1107 if (!_elm_config->desktop_entry)
1109 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1110 edje_object_part_text_select_abort(wd->ent, "elm.text");
1114 evas_object_smart_callback_call(obj, SIG_LONGPRESSED, NULL);
1118 _magnifier_hide(void *data)
1120 Widget_Data *wd = elm_widget_data_get(data);
1123 evas_object_hide(wd->mgf_bg);
1124 evas_object_hide(wd->mgf_clip);
1128 _magnifier_show(void *data)
1130 Widget_Data *wd = elm_widget_data_get(data);
1133 evas_object_show(wd->mgf_bg);
1134 evas_object_show(wd->mgf_clip);
1138 _magnifier_move(void *data)
1140 Widget_Data *wd = elm_widget_data_get(data);
1143 Evas_Coord x, y, w, h, fs;
1144 Evas_Coord cx, cy, cw, ch, ox, oy;
1146 evas_object_geometry_get(data, &x, &y, &w, &h);
1147 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1150 fs = elm_finger_size_get();
1152 if ((cy + y) - wd->mgf_height - fs < 0)
1153 oy = -1 * ((cy + y) - wd->mgf_height - fs);
1155 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1156 evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1157 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1158 evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1162 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);
1166 _magnifier_create(void *data)
1168 Widget_Data *wd = elm_widget_data_get(data);
1169 Evas_Coord x, y, w, h;
1170 const char* key_data = NULL;
1176 evas_object_image_source_unset(wd->mgf_proxy);
1177 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1178 evas_object_hide(wd->mgf_proxy);
1179 evas_object_clip_unset(wd->mgf_proxy);
1180 evas_object_del(wd->mgf_proxy);
1182 if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1183 if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1185 evas_object_geometry_get(data, &x, &y, &w, &h);
1186 wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1188 if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1189 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1190 else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1191 _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1195 wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1196 evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1197 edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1199 key_data = edje_object_data_get(wd->mgf_bg, "height");
1200 if (key_data) wd->mgf_height = atoi(key_data);
1201 key_data = edje_object_data_get(wd->mgf_bg, "scale");
1202 if (key_data) wd->mgf_scale = atof(key_data);
1204 if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1205 evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1207 wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1208 evas_object_image_source_set(wd->mgf_proxy, data);
1209 evas_object_resize(wd->mgf_proxy, w * wd->mgf_scale, h * wd->mgf_scale);
1210 evas_object_image_fill_set(wd->mgf_proxy, 0, 0, w * wd->mgf_scale, h * wd->mgf_scale);
1211 evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1212 evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1213 evas_object_show(wd->mgf_proxy);
1214 evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1216 evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1217 evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1221 _long_press(void *data)
1223 Widget_Data *wd = elm_widget_data_get(data);
1224 if (!wd) return ECORE_CALLBACK_CANCEL;
1226 wd->long_pressed = EINA_TRUE;
1228 if (wd->longpress_timer)
1230 ecore_timer_del(wd->longpress_timer);
1231 wd->longpress_timer = NULL;
1234 _cancel(data, NULL, NULL);
1236 _magnifier_create(data);
1237 _magnifier_move(data);
1238 _magnifier_show(data);
1239 elm_object_scroll_freeze_push(data);
1241 wd->longpress_timer = NULL;
1242 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1243 return ECORE_CALLBACK_CANCEL;
1247 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1249 Widget_Data *wd = elm_widget_data_get(data);
1250 Evas_Event_Mouse_Down *ev = event_info;
1252 if (wd->disabled) return;
1253 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1254 if (ev->button != 1) return;
1255 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1256 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1257 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1258 wd->downx = ev->canvas.x;
1259 wd->downy = ev->canvas.y;
1261 wd->long_pressed = EINA_FALSE;
1265 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1267 Widget_Data *wd = elm_widget_data_get(data);
1268 Evas_Event_Mouse_Up *ev = event_info;
1270 if (wd->disabled) return;
1271 if (ev->button != 1) return;
1273 if (!wd->double_clicked)
1275 if ((wd->api) && (wd->api->obj_mouseup))
1277 wd->api->obj_mouseup(data);
1280 if (wd->longpress_timer)
1282 ecore_timer_del(wd->longpress_timer);
1283 wd->longpress_timer = NULL;
1286 _magnifier_hide(data);
1287 elm_object_scroll_freeze_pop(data);
1289 if (wd->long_pressed)
1296 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1298 Widget_Data *wd = elm_widget_data_get(data);
1299 Evas_Event_Mouse_Move *ev = event_info;
1301 if (wd->disabled) return;
1304 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1306 if (wd->longpress_timer)
1308 ecore_timer_del(wd->longpress_timer);
1309 wd->longpress_timer = NULL;
1312 else if (wd->longpress_timer)
1316 dx = wd->downx - ev->cur.canvas.x;
1318 dy = wd->downy - ev->cur.canvas.y;
1321 ((_elm_config->finger_size / 2) *
1322 (_elm_config->finger_size / 2)))
1324 ecore_timer_del(wd->longpress_timer);
1325 wd->longpress_timer = NULL;
1329 else if (wd->longpress_timer)
1333 dx = wd->downx - ev->cur.canvas.x;
1335 dy = wd->downy - ev->cur.canvas.y;
1338 ((_elm_config->finger_size / 2) *
1339 (_elm_config->finger_size / 2)))
1341 ecore_timer_del(wd->longpress_timer);
1342 wd->longpress_timer = NULL;
1346 if (ev->buttons != 1) return;
1348 if (wd->long_pressed)
1350 _magnifier_show(data);
1351 _magnifier_move(data);
1356 _getbase(Evas_Object *obj)
1358 Widget_Data *wd = elm_widget_data_get(obj);
1359 if (!wd) return "base";
1364 if (wd->show_last_character) return "custom-password";
1365 else return "base-password";
1369 if (wd->single_line) return "base-single";
1372 if (wd->linewrap) return "base";
1373 else if (wd->char_linewrap) return "base-charwrap";
1374 else return "base-nowrap";
1382 if (wd->show_last_character) return "custom-password";
1383 else return "base-password";
1387 if (wd->single_line) return "base-single-noedit";
1390 if (wd->linewrap) return "base-noedit";
1391 else if (wd->char_linewrap) return "base-noedit-charwrap";
1392 else return "base-nowrap-noedit";
1400 _entry_length_get(Evas_Object *obj)
1403 const char *str = elm_entry_entry_get(obj);
1406 char *plain_str = _elm_util_mkup_to_text(str);
1407 if (!plain_str) return 0;
1409 len = strlen(plain_str);
1416 _matchlist_show(void *data)
1418 Widget_Data *wd = elm_widget_data_get(data);
1419 const char *text = NULL;
1421 char *str_list = NULL, *str_result = NULL;
1422 char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1425 Eina_Bool textfound = EINA_FALSE;
1428 if (elm_widget_disabled_get(data)) return;
1430 wd->matchlist_job = NULL;
1432 if (wd->matchlist_list_clicked)
1434 evas_object_hide(wd->hover);
1435 wd->matchlist_list_clicked = EINA_FALSE;
1438 text = elm_entry_entry_get(data);
1441 textlen = strlen(text);
1443 if (textlen < wd->matchlist_threshold)
1445 evas_object_hide(wd->hover);
1449 evas_object_hide(wd->hover);
1453 elm_list_clear(wd->list);
1454 EINA_LIST_FOREACH(wd->match_list, l, str_list)
1456 if (wd->matchlist_case_sensitive)
1457 str_result = strstr(str_list, text);
1459 str_result = strcasestr(str_list, text);
1463 str_mkup = malloc(strlen(str_list) + 16);
1465 textlen = strlen(str_list) - strlen(str_result);
1466 str_front = malloc(textlen + 1);
1467 memset(str_front, 0, textlen + 1);
1468 strncpy(str_front, str_list, textlen);
1470 textlen = strlen(text);
1471 str_mid = malloc(textlen + 1);
1472 memset(str_mid, 0, textlen + 1);
1473 strncpy(str_mid, str_list + strlen(str_front), textlen);
1475 sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1477 elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1479 if (str_mkup) free(str_mkup);
1480 if (str_front) free(str_front);
1481 if (str_mid) free(str_mid);
1483 textfound=EINA_TRUE;
1492 elm_list_go(wd->list);
1493 evas_object_show(wd->hover);
1494 evas_object_raise(wd->hover);
1498 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1500 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1501 Widget_Data *wd = elm_widget_data_get(data);
1502 if ((it == NULL) || (wd == NULL))
1505 const char *text = elm_list_item_label_get(it);
1506 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1511 elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1512 elm_entry_cursor_end_set(data);
1513 wd->matchlist_list_clicked = EINA_TRUE;
1515 evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1518 elm_widget_focus_set(data, EINA_TRUE);
1522 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
1524 Widget_Data *wd = elm_widget_data_get(obj);
1529 Evas_Coord max_w = 9999, max_h = 9999;
1530 const char* key_data = NULL;
1532 wd->matchlist_threshold = 1;
1533 wd->hover = elm_hover_add(elm_widget_parent_get(obj));
1534 elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
1535 elm_hover_target_set(wd->hover, obj);
1536 elm_object_style_set(wd->hover, "matchlist");
1538 wd->layout = elm_layout_add(wd->hover);
1539 elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
1540 wd->list = elm_list_add(wd->layout);
1541 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
1542 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1543 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1544 elm_object_style_set(wd->list, "matchlist");
1546 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
1547 if (key_data) max_w = atoi(key_data);
1548 key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
1549 if (key_data) max_h = atoi(key_data);
1551 elm_list_go(wd->list);
1552 evas_object_size_hint_max_set(wd->list, max_w, max_h);
1553 evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
1554 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
1555 elm_hover_content_set(wd->hover, "bottom", wd->layout);
1557 wd->match_list = match_list;
1562 evas_object_del(wd->hover);
1564 wd->match_list = NULL;
1567 wd->matchlist_case_sensitive = case_sensitive;
1572 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1574 Widget_Data *wd = elm_widget_data_get(data);
1576 wd->changed = EINA_TRUE;
1578 if (wd->text) eina_stringshare_del(wd->text);
1580 _check_enable_returnkey(data);
1581 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1582 if (wd->delay_write)
1584 ecore_timer_del(wd->delay_write);
1585 wd->delay_write = NULL;
1588 if ((wd->single_line) && (wd->match_list))
1590 if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1591 wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1593 if ((!wd->autosave) || (!wd->file)) return;
1594 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1598 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1600 Widget_Data *wd = elm_widget_data_get(data);
1601 elm_object_scroll_freeze_push(data);
1603 if ((wd->api) && (wd->api->obj_hidemenu))
1605 wd->api->obj_hidemenu(data);
1608 _magnifier_create(data);
1609 _magnifier_move(data);
1610 _magnifier_show(data);
1614 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1616 Widget_Data *wd = elm_widget_data_get(data);
1617 elm_object_scroll_freeze_pop(data);
1619 if (wd->have_selection)
1621 _magnifier_hide(data);
1627 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1629 _magnifier_move(data);
1630 _magnifier_show(data);
1634 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1636 _magnifier_hide(data);
1641 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1643 Widget_Data *wd = elm_widget_data_get(data);
1647 EINA_LIST_FOREACH(entries, l, entry)
1649 if (entry != data) elm_entry_select_none(entry);
1651 wd->have_selection = EINA_TRUE;
1652 wd->selmode = EINA_TRUE;
1653 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1654 #ifdef HAVE_ELEMENTARY_X
1655 if (wd->sel_notify_handler)
1657 const char *txt = elm_entry_selection_get(data);
1660 top = elm_widget_top_get(data);
1661 if ((top) && (elm_win_xwindow_get(top)))
1662 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1668 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1670 Evas_Coord cx, cy, cw, ch;
1671 Widget_Data *wd = elm_widget_data_get(data);
1674 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1675 if (!wd->deferred_recalc_job)
1676 elm_widget_show_region_set(data, cx, cy, cw, ch);
1679 wd->deferred_cur = EINA_TRUE;
1683 wd->ch = ch + elm_finger_size_get();
1688 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1690 Evas_Coord cx, cy, cw, ch;
1691 Widget_Data *wd = elm_widget_data_get(data);
1693 wd->have_selection = EINA_TRUE;
1694 wd->selmode = EINA_TRUE;
1695 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1696 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1697 elm_entry_selection_get(data));
1699 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1700 if (!wd->deferred_recalc_job)
1701 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get());
1704 wd->deferred_cur = EINA_TRUE;
1708 wd->ch = ch + elm_finger_size_get();
1713 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1715 Widget_Data *wd = elm_widget_data_get(data);
1717 if (!wd->have_selection) return;
1718 wd->have_selection = EINA_FALSE;
1719 wd->selmode = EINA_FALSE;
1720 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1721 if (wd->sel_notify_handler)
1725 #ifdef HAVE_ELEMENTARY_X
1728 top = elm_widget_top_get(data);
1729 if ((top) && (elm_win_xwindow_get(top)))
1730 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1733 eina_stringshare_del(wd->cut_sel);
1738 #ifdef HAVE_ELEMENTARY_X
1741 top = elm_widget_top_get(data);
1742 if ((top) && (elm_win_xwindow_get(top)))
1743 elm_selection_clear(ELM_SEL_PRIMARY, data);
1748 if ((wd->api) && (wd->api->obj_hidemenu))
1750 wd->api->obj_hidemenu(data);
1755 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1757 Widget_Data *wd = elm_widget_data_get(data);
1759 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1760 if (wd->sel_notify_handler)
1762 #ifdef HAVE_ELEMENTARY_X
1765 top = elm_widget_top_get(data);
1766 if ((top) && (elm_win_xwindow_get(top)))
1768 wd->selection_asked = EINA_TRUE;
1769 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1777 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1779 Widget_Data *wd = elm_widget_data_get(data);
1781 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1782 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1783 elm_entry_selection_get(data));
1787 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1789 Widget_Data *wd = elm_widget_data_get(data);
1791 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1792 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1793 elm_entry_selection_get(data));
1794 edje_object_part_text_insert(wd->ent, "elm.text", "");
1795 wd->changed = EINA_TRUE;
1800 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1802 Widget_Data *wd = elm_widget_data_get(data);
1803 Evas_Coord cx, cy, cw, ch;
1805 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1806 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1807 &cx, &cy, &cw, &ch);
1808 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1809 if (!wd->deferred_recalc_job)
1810 elm_widget_show_region_set(data, cx, cy, cw, ch);
1813 wd->deferred_cur = EINA_TRUE;
1822 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1824 Widget_Data *wd = elm_widget_data_get(data);
1829 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1831 Widget_Data *wd = elm_widget_data_get(data);
1836 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1838 Widget_Data *wd = elm_widget_data_get(data);
1839 Elm_Entry_Anchor_Info ei;
1840 char *buf2, *p, *p2, *n;
1842 p = strrchr(emission, ',');
1845 const Eina_List *geoms;
1849 while (p2 >= emission)
1851 if (*p2 == ',') break;
1855 buf2 = alloca(5 + p - p2);
1856 strncpy(buf2, p2, p - p2);
1859 ei.button = atoi(buf2);
1860 ei.x = ei.y = ei.w = ei.h = 0;
1862 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1865 Evas_Textblock_Rectangle *r;
1867 Evas_Coord px, py, x, y;
1869 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1870 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1871 EINA_LIST_FOREACH(geoms, l, r)
1873 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1874 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1885 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1890 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1892 Widget_Data *wd = elm_widget_data_get(data);
1897 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1899 Widget_Data *wd = elm_widget_data_get(data);
1904 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1906 Widget_Data *wd = elm_widget_data_get(data);
1911 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1913 Widget_Data *wd = elm_widget_data_get(data);
1915 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1919 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1921 Widget_Data *wd = elm_widget_data_get(data);
1923 wd->double_clicked = EINA_FALSE;
1924 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1926 if ((wd->api) && (wd->api->obj_hidemenu))
1928 wd->api->obj_hidemenu(data);
1933 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1935 Widget_Data *wd = elm_widget_data_get(data);
1937 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1941 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1943 Widget_Data *wd = elm_widget_data_get(data);
1945 wd->double_clicked = EINA_TRUE;
1946 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1949 #ifdef HAVE_ELEMENTARY_X
1951 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1953 Widget_Data *wd = elm_widget_data_get(data);
1954 Ecore_X_Event_Selection_Notify *ev = event;
1955 if (!wd) return ECORE_CALLBACK_PASS_ON;
1956 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1957 return ECORE_CALLBACK_PASS_ON;
1959 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1960 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1962 Ecore_X_Selection_Data_Text *text_data;
1964 text_data = ev->data;
1965 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1967 if (text_data->text)
1969 char *txt = _elm_util_text_to_mkup(text_data->text);
1973 elm_entry_entry_insert(data, txt);
1978 wd->selection_asked = EINA_FALSE;
1980 else if (ev->selection == ECORE_X_SELECTION_XDND)
1982 Ecore_X_Selection_Data_Text *text_data;
1984 text_data = ev->data;
1985 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1987 if (text_data->text)
1989 char *txt = _elm_util_text_to_mkup(text_data->text);
1993 /* Massive FIXME: this should be at the drag point */
1994 elm_entry_entry_insert(data, txt);
1999 wd->drag_selection_asked = EINA_FALSE;
2001 ecore_x_dnd_send_finished();
2003 return ECORE_CALLBACK_PASS_ON;
2007 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2010 Widget_Data *wd = elm_widget_data_get(data);
2011 Ecore_X_Event_Selection_Clear *ev = event;
2012 if (!wd) return ECORE_CALLBACK_PASS_ON;
2013 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2014 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2015 (ev->selection == ECORE_X_SELECTION_PRIMARY))
2017 elm_entry_select_none(data);
2022 Evas_Object *top = elm_widget_top_get(data);
2023 Ecore_X_Event_Selection_Clear *ev = event;
2026 return ECORE_CALLBACK_PASS_ON;
2028 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2030 return ECORE_CALLBACK_PASS_ON;
2033 if (cnpwidgetdata == data)
2035 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
2039 return ECORE_CALLBACK_PASS_ON;
2044 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2049 wd = elm_widget_data_get(obj);
2051 if (!wd) return EINA_FALSE;
2052 printf("Inserting at (%d,%d) %s\n", drop->x, drop->y, (char*)drop->data);
2054 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2055 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2056 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2057 EDJE_CURSOR_MAIN,drop->x,drop->y);
2058 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2059 elm_entry_entry_insert(obj, drop->data);
2060 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2061 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2067 static Evas_Object *
2068 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2070 Widget_Data *wd = elm_widget_data_get(data);
2073 Elm_Entry_Item_Provider *ip;
2075 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2077 o = ip->func(ip->data, data, item);
2080 if (!strncmp(item, "file://", 7))
2082 const char *fname = item + 7;
2084 o = evas_object_image_filled_add(evas_object_evas_get(data));
2085 evas_object_image_file_set(o, fname, NULL);
2086 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2088 evas_object_show(o);
2093 o = edje_object_add(evas_object_evas_get(data));
2094 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2098 o = edje_object_add(evas_object_evas_get(data));
2099 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2100 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2105 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2107 const char *srcstring = NULL;
2108 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2109 char *curlocater, *replocater;
2110 char *starttag, *endtag;
2111 int tagtxtlen = 0, insertflag = 0;
2113 srcstring = eina_strbuf_string_get(srcbuf);
2114 curlocater = strstr(srcstring, key);
2116 if (!curlocater || !srcstring)
2124 starttag = strchr(srcstring, '<');
2125 endtag = strchr(srcstring, '>');
2126 tagtxtlen = endtag - starttag;
2127 if (tagtxtlen <= 0) tagtxtlen = 0;
2128 if (starttag < curlocater && curlocater < endtag) break;
2129 if (endtag != NULL && endtag+1 != NULL)
2130 srcstring = endtag+1;
2133 } while (strlen(srcstring) > 1);
2135 if (starttag && endtag && tagtxtlen > strlen(key))
2137 repbuf = eina_strbuf_new();
2138 diffbuf = eina_strbuf_new();
2139 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2140 srcstring = eina_strbuf_string_get(repbuf);
2141 curlocater = strstr(srcstring, key);
2143 if (curlocater != NULL)
2145 replocater = curlocater + strlen(key) + 1;
2147 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2150 if (replocater-curlocater > strlen(key)+1)
2152 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2161 eina_strbuf_reset(repbuf);
2169 if (repbuf == NULL) repbuf = eina_strbuf_new();
2170 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2174 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2175 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2181 eina_strbuf_prepend(diffbuf, "<");
2182 eina_strbuf_append(diffbuf, ">");
2183 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2187 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2188 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2192 if (repbuf) eina_strbuf_free(repbuf);
2193 if (diffbuf) eina_strbuf_free(diffbuf);
2199 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2201 Eina_Strbuf *sharebuf = NULL;
2203 sharebuf = eina_strbuf_new();
2204 eina_strbuf_append(sharebuf, *srcstring);
2205 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2206 eina_stringshare_del(*srcstring);
2207 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2208 eina_strbuf_free(sharebuf);
2214 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2216 Widget_Data *wd = elm_widget_data_get(data);
2218 Elm_Entry_Text_Filter *tf;
2220 if (type == EDJE_TEXT_FILTER_FORMAT)
2223 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2225 tf->func(tf->data, data, text);
2232 * This adds an entry to @p parent object.
2234 * @param parent The parent object
2235 * @return The new object or NULL if it cannot be created
2240 elm_entry_add(Evas_Object *parent)
2242 Evas_Object *obj, *top;
2246 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2248 ELM_SET_WIDTYPE(widtype, "entry");
2249 elm_widget_type_set(obj, "entry");
2250 elm_widget_sub_object_add(parent, obj);
2251 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2252 elm_widget_data_set(obj, wd);
2253 elm_widget_del_hook_set(obj, _del_hook);
2254 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2255 elm_widget_theme_hook_set(obj, _theme_hook);
2256 elm_widget_disable_hook_set(obj, _disable_hook);
2257 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2258 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2259 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2260 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2261 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2262 elm_widget_can_focus_set(obj, EINA_TRUE);
2263 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2265 wd->linewrap = EINA_TRUE;
2266 wd->char_linewrap= EINA_FALSE;
2267 wd->editable = EINA_TRUE;
2268 wd->disabled = EINA_FALSE;
2269 wd->context_menu = EINA_TRUE;
2270 wd->autosave = EINA_TRUE;
2271 wd->textonly = EINA_FALSE;
2272 wd->autoperiod = EINA_TRUE;
2274 wd->ent = edje_object_add(e);
2275 edje_object_item_provider_set(wd->ent, _get_item, obj);
2276 edje_object_text_insert_filter_callback_add(wd->ent, "elm.text", _text_filter, obj);
2277 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2278 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2279 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2281 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2283 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2286 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2287 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2288 _signal_entry_changed, obj);
2289 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2290 _signal_handler_move_start, obj);
2291 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2292 _signal_handler_move_end, obj);
2293 edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2294 _signal_handler_moving, obj);
2295 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2296 _signal_selection_start, obj);
2297 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2298 _signal_selection_end, obj);
2299 edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2300 _signal_magnifier_changed, obj);
2301 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2302 _signal_selection_changed, obj);
2303 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2304 _signal_selection_cleared, obj);
2305 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2306 _signal_entry_paste_request, obj);
2307 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2308 _signal_entry_copy_notify, obj);
2309 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2310 _signal_entry_cut_notify, obj);
2311 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2312 _signal_cursor_changed, obj);
2313 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2314 _signal_anchor_down, obj);
2315 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2316 _signal_anchor_up, obj);
2317 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2318 _signal_anchor_clicked, obj);
2319 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2320 _signal_anchor_move, obj);
2321 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2322 _signal_anchor_in, obj);
2323 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2324 _signal_anchor_out, obj);
2325 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2326 _signal_key_enter, obj);
2327 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2328 _signal_mouse_down, obj);
2329 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2330 _signal_mouse_clicked, obj);
2331 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2332 _signal_mouse_double, obj);
2333 edje_object_part_text_set(wd->ent, "elm.text", "");
2334 if (_elm_config->desktop_entry)
2335 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2336 elm_widget_resize_object_set(obj, wd->ent);
2339 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2341 #ifdef HAVE_ELEMENTARY_X
2342 top = elm_widget_top_get(obj);
2343 if ((top) && (elm_win_xwindow_get(top)))
2345 wd->sel_notify_handler =
2346 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2347 _event_selection_notify, obj);
2348 wd->sel_clear_handler =
2349 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2350 _event_selection_clear, obj);
2353 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2354 _drag_drop_cb, NULL);
2357 entries = eina_list_prepend(entries, obj);
2359 // module - find module for entry
2360 wd->api = _module(obj);
2361 // if found - hook in
2362 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2364 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2365 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2366 // TODO: and save some bytes, making descriptions per-class and not instance!
2367 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2371 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2373 ELM_CHECK_WIDTYPE(obj, widtype);
2374 Widget_Data *wd = elm_widget_data_get(obj);
2376 ext_mod->cancel = _cancel;
2377 ext_mod->copy = _copy;
2378 ext_mod->cut = _cut;
2379 ext_mod->paste = _paste;
2380 ext_mod->select = _select;
2381 ext_mod->selectall = _selectall;
2382 ext_mod->ent = wd->ent;
2383 ext_mod->items = wd->items;
2384 ext_mod->longpress_timer = wd->longpress_timer;
2385 ext_mod->editable = wd->editable;
2386 ext_mod->have_selection = wd->have_selection;
2387 ext_mod->password = wd->password;
2388 ext_mod->selmode = wd->selmode;
2389 ext_mod->cnpinit = _cnpinit;
2390 ext_mod->context_menu = wd->context_menu;
2391 ext_mod->textonly = wd->textonly;
2395 * This sets the entry object not to line wrap. All input will
2396 * be on a single line, and the entry box will extend with user input.
2398 * @param obj The entry object
2399 * @param single_line If true, the text in the entry
2400 * will be on a single line.
2405 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2407 ELM_CHECK_WIDTYPE(obj, widtype);
2408 Widget_Data *wd = elm_widget_data_get(obj);
2410 if (wd->single_line == single_line) return;
2411 wd->single_line = single_line;
2412 wd->linewrap = EINA_FALSE;
2413 wd->char_linewrap = EINA_FALSE;
2414 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2419 * This returns true if the entry has been set to single line mode.
2420 * See also elm_entry_single_line_set().
2422 * @param obj The entry object
2423 * @return single_line If true, the text in the entry is set to display
2429 elm_entry_single_line_get(const Evas_Object *obj)
2431 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2432 Widget_Data *wd = elm_widget_data_get(obj);
2433 if (!wd) return EINA_FALSE;
2434 return wd->single_line;
2438 * This sets the entry object to password mode. All text entered
2439 * and/or displayed within the widget will be replaced with asterisks (*).
2441 * @param obj The entry object
2442 * @param password If true, password mode is enabled.
2447 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2449 ELM_CHECK_WIDTYPE(obj, widtype);
2450 Widget_Data *wd = elm_widget_data_get(obj);
2452 if (wd->password == password) return;
2453 wd->password = password;
2454 wd->single_line = EINA_TRUE;
2455 wd->linewrap = EINA_FALSE;
2456 wd->char_linewrap = EINA_FALSE;
2461 * This returns whether password mode is enabled.
2462 * See also elm_entry_password_set().
2464 * @param obj The entry object
2465 * @return If true, the entry is set to display all characters
2471 elm_entry_password_get(const Evas_Object *obj)
2473 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2474 Widget_Data *wd = elm_widget_data_get(obj);
2475 if (!wd) return EINA_FALSE;
2476 return wd->password;
2480 * This sets the text displayed within the entry to @p entry.
2482 * @param obj The entry object
2483 * @param entry The text to be displayed
2488 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2490 ELM_CHECK_WIDTYPE(obj, widtype);
2491 Widget_Data *wd = elm_widget_data_get(obj);
2493 if (!entry) entry = "";
2494 if(wd->max_no_of_bytes)
2496 int len = strlen(entry);
2497 if(len > wd->max_no_of_bytes)
2499 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2503 edje_object_part_text_set(wd->ent, "elm.text", entry);
2504 if (wd->text) eina_stringshare_del(wd->text);
2506 wd->changed = EINA_TRUE;
2511 * This returns the text currently shown in object @p entry.
2512 * See also elm_entry_entry_set().
2514 * @param obj The entry object
2515 * @return The currently displayed text or NULL on failure
2520 elm_entry_entry_get(const Evas_Object *obj)
2522 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2523 Widget_Data *wd = elm_widget_data_get(obj);
2525 if (!wd) return NULL;
2527 if ((wd->text)&&(wd->password))
2528 return elm_entry_markup_to_utf8(wd->text);
2530 if (wd->text) return wd->text;
2531 text = edje_object_part_text_get(wd->ent, "elm.text");
2534 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2537 eina_stringshare_replace(&wd->text, text);
2538 if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2543 * This returns EINA_TRUE if the entry is empty/there was an error
2544 * and EINA_FALSE if it is not empty.
2546 * @param obj The entry object
2547 * @return If the entry is empty or not.
2552 elm_entry_is_empty(const Evas_Object *obj)
2554 /* FIXME: until there's support for that in textblock, we just check
2555 * to see if the there is text or not. */
2556 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2557 Widget_Data *wd = elm_widget_data_get(obj);
2558 const Evas_Object *tb;
2559 //Evas_Textblock_Cursor *cur;
2561 if (!wd) return EINA_TRUE;
2564 /* It's a hack until we get the support suggested above.
2565 * We just create a cursor, point it to the begining, and then
2566 * try to advance it, if it can advance, the tb is not empty,
2567 * otherwise it is. */
2568 tb = edje_object_part_object_get(wd->ent, "elm.text");
2569 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2570 actually, ok for the time being, thsese hackish stuff will be removed
2571 once evas 1.0 is out*/
2572 evas_textblock_cursor_pos_set(cur, 0);
2573 ret = evas_textblock_cursor_char_next(cur);
2574 evas_textblock_cursor_free(cur);
2579 char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
2580 if (!str) return EINA_TRUE;
2582 ret = (strlen(str) == 0);
2588 * This returns all selected text within the entry.
2590 * @param obj The entry object
2591 * @return The selected text within the entry or NULL on failure
2596 elm_entry_selection_get(const Evas_Object *obj)
2598 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2599 Widget_Data *wd = elm_widget_data_get(obj);
2600 if (!wd) return NULL;
2601 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2605 * This inserts text in @p entry where the current cursor position.
2607 * This inserts text at the cursor position is as if it was typed
2608 * by the user (note this also allows markup which a user
2609 * can't just "type" as it would be converted to escaped text, so this
2610 * call can be used to insert things like emoticon items or bold push/pop
2611 * tags, other font and color change tags etc.)
2613 * @param obj The entry object
2614 * @param entry The text to insert
2619 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2621 ELM_CHECK_WIDTYPE(obj, widtype);
2622 Widget_Data *wd = elm_widget_data_get(obj);
2624 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2626 if (cnpwidgetdata == obj)
2627 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2629 wd->changed = EINA_TRUE;
2634 * This enables word line wrapping in the entry object. It is the opposite
2635 * of elm_entry_single_line_set(). Additionally, setting this disables
2636 * character line wrapping.
2637 * See also elm_entry_line_char_wrap_set().
2639 * @param obj The entry object
2640 * @param wrap If true, the entry will be wrapped once it reaches the end
2641 * of the object. Wrapping will occur at the end of the word before the end of the
2647 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2649 ELM_CHECK_WIDTYPE(obj, widtype);
2650 Widget_Data *wd = elm_widget_data_get(obj);
2652 if (wd->linewrap == wrap) return;
2653 wd->linewrap = wrap;
2655 wd->char_linewrap = EINA_FALSE;
2660 * Set wrap width of the entry
2662 * @param obj The entry object
2663 * @param w The wrap width in pixels at a minimum where words need to wrap
2667 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2669 Widget_Data *wd = elm_widget_data_get(obj);
2670 if (wd->wrap_w == w) return;
2676 * get wrap width of the entry
2678 * @param obj The entry object
2679 * @return The wrap width in pixels at a minimum where words need to wrap
2683 elm_entry_wrap_width_get(const Evas_Object *obj)
2685 Widget_Data *wd = elm_widget_data_get(obj);
2690 * This enables character line wrapping in the entry object. It is the opposite
2691 * of elm_entry_single_line_set(). Additionally, setting this disables
2692 * word line wrapping.
2693 * See also elm_entry_line_wrap_set().
2695 * @param obj The entry object
2696 * @param wrap If true, the entry will be wrapped once it reaches the end
2697 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2702 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2704 ELM_CHECK_WIDTYPE(obj, widtype);
2705 Widget_Data *wd = elm_widget_data_get(obj);
2707 if (wd->char_linewrap == wrap) return;
2708 wd->char_linewrap = wrap;
2709 if(wd->char_linewrap)
2710 wd->linewrap = EINA_FALSE;
2715 * This sets the editable attribute of the entry.
2717 * @param obj The entry object
2718 * @param editable If true, the entry will be editable by the user.
2719 * If false, it will be set to the disabled state.
2724 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2726 ELM_CHECK_WIDTYPE(obj, widtype);
2727 Widget_Data *wd = elm_widget_data_get(obj);
2729 if (wd->editable == editable) return;
2730 wd->editable = editable;
2733 #ifdef HAVE_ELEMENTARY_X
2735 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2737 elm_drop_target_del(obj);
2742 * This gets the editable attribute of the entry.
2743 * See also elm_entry_editable_set().
2745 * @param obj The entry object
2746 * @return If true, the entry is editable by the user.
2747 * If false, it is not editable by the user
2752 elm_entry_editable_get(const Evas_Object *obj)
2754 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2755 Widget_Data *wd = elm_widget_data_get(obj);
2756 if (!wd) return EINA_FALSE;
2757 return wd->editable;
2761 * This drops any existing text selection within the entry.
2763 * @param obj The entry object
2768 elm_entry_select_none(Evas_Object *obj)
2770 ELM_CHECK_WIDTYPE(obj, widtype);
2771 Widget_Data *wd = elm_widget_data_get(obj);
2775 wd->selmode = EINA_FALSE;
2776 if (!_elm_config->desktop_entry)
2777 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2778 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2780 wd->have_selection = EINA_FALSE;
2781 edje_object_part_text_select_none(wd->ent, "elm.text");
2785 * This selects all text within the entry.
2787 * @param obj The entry object
2792 elm_entry_select_all(Evas_Object *obj)
2794 ELM_CHECK_WIDTYPE(obj, widtype);
2795 Widget_Data *wd = elm_widget_data_get(obj);
2799 wd->selmode = EINA_FALSE;
2800 if (!_elm_config->desktop_entry)
2801 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2802 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2804 wd->have_selection = EINA_TRUE;
2805 edje_object_part_text_select_all(wd->ent, "elm.text");
2809 * This function returns the geometry of the cursor.
2811 * It's useful if you want to draw something on the cursor (or where it is),
2812 * or for example in the case of scrolled entry where you want to show the
2815 * @param obj The entry object
2816 * @param x returned geometry
2817 * @param y returned geometry
2818 * @param w returned geometry
2819 * @param h returned geometry
2820 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2825 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2827 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2828 Widget_Data *wd = elm_widget_data_get(obj);
2829 if (!wd) return EINA_FALSE;
2830 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2835 * This moves the cursor one place to the right within the entry.
2837 * @param obj The entry object
2838 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2843 elm_entry_cursor_next(Evas_Object *obj)
2845 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2846 Widget_Data *wd = elm_widget_data_get(obj);
2847 if (!wd) return EINA_FALSE;
2848 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2852 * This moves the cursor one place to the left within the entry.
2854 * @param obj The entry object
2855 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2860 elm_entry_cursor_prev(Evas_Object *obj)
2862 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2863 Widget_Data *wd = elm_widget_data_get(obj);
2864 if (!wd) return EINA_FALSE;
2865 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2869 * This moves the cursor one line up within the entry.
2871 * @param obj The entry object
2872 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2877 elm_entry_cursor_up(Evas_Object *obj)
2879 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2880 Widget_Data *wd = elm_widget_data_get(obj);
2881 if (!wd) return EINA_FALSE;
2882 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2886 * This moves the cursor one line down within the entry.
2888 * @param obj The entry object
2889 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2894 elm_entry_cursor_down(Evas_Object *obj)
2896 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2897 Widget_Data *wd = elm_widget_data_get(obj);
2898 if (!wd) return EINA_FALSE;
2899 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2903 * This moves the cursor to the beginning of the entry.
2905 * @param obj The entry object
2910 elm_entry_cursor_begin_set(Evas_Object *obj)
2912 ELM_CHECK_WIDTYPE(obj, widtype);
2913 Widget_Data *wd = elm_widget_data_get(obj);
2915 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2919 * This moves the cursor to the end of the entry.
2921 * @param obj The entry object
2926 elm_entry_cursor_end_set(Evas_Object *obj)
2928 ELM_CHECK_WIDTYPE(obj, widtype);
2929 Widget_Data *wd = elm_widget_data_get(obj);
2931 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2935 * This moves the cursor to the beginning of the current line.
2937 * @param obj The entry object
2942 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2944 ELM_CHECK_WIDTYPE(obj, widtype);
2945 Widget_Data *wd = elm_widget_data_get(obj);
2947 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2951 * This moves the cursor to the end of the current line.
2953 * @param obj The entry object
2958 elm_entry_cursor_line_end_set(Evas_Object *obj)
2960 ELM_CHECK_WIDTYPE(obj, widtype);
2961 Widget_Data *wd = elm_widget_data_get(obj);
2963 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2967 * This begins a selection within the entry as though
2968 * the user were holding down the mouse button to make a selection.
2970 * @param obj The entry object
2975 elm_entry_cursor_selection_begin(Evas_Object *obj)
2977 ELM_CHECK_WIDTYPE(obj, widtype);
2978 Widget_Data *wd = elm_widget_data_get(obj);
2980 edje_object_part_text_select_begin(wd->ent, "elm.text");
2984 * This ends a selection within the entry as though
2985 * the user had just released the mouse button while making a selection.
2987 * @param obj The entry object
2992 elm_entry_cursor_selection_end(Evas_Object *obj)
2994 ELM_CHECK_WIDTYPE(obj, widtype);
2995 Widget_Data *wd = elm_widget_data_get(obj);
2997 edje_object_part_text_select_extend(wd->ent, "elm.text");
3001 * TODO: fill this in
3003 * @param obj The entry object
3004 * @return TODO: fill this in
3009 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3011 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3012 Widget_Data *wd = elm_widget_data_get(obj);
3013 if (!wd) return EINA_FALSE;
3014 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3018 * This returns whether the cursor is visible.
3020 * @param obj The entry object
3021 * @return If true, the cursor is visible.
3026 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3028 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3029 Widget_Data *wd = elm_widget_data_get(obj);
3030 if (!wd) return EINA_FALSE;
3031 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3035 * TODO: fill this in
3037 * @param obj The entry object
3038 * @return TODO: fill this in
3043 elm_entry_cursor_content_get(const Evas_Object *obj)
3045 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3046 Widget_Data *wd = elm_widget_data_get(obj);
3047 if (!wd) return NULL;
3048 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3052 * Sets the cursor position in the entry to the given value
3054 * @param obj The entry object
3055 * @param pos The position of the cursor
3060 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3062 ELM_CHECK_WIDTYPE(obj, widtype);
3063 Widget_Data *wd = elm_widget_data_get(obj);
3065 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3066 edje_object_message_signal_process(wd->ent);
3070 * Retrieves the current position of the cursor in the entry
3072 * @param obj The entry object
3073 * @return The cursor position
3078 elm_entry_cursor_pos_get(const Evas_Object *obj)
3080 ELM_CHECK_WIDTYPE(obj, widtype) 0;
3081 Widget_Data *wd = elm_widget_data_get(obj);
3083 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3087 * This executes a "cut" action on the selected text in the entry.
3089 * @param obj The entry object
3094 elm_entry_selection_cut(Evas_Object *obj)
3096 ELM_CHECK_WIDTYPE(obj, widtype);
3097 Widget_Data *wd = elm_widget_data_get(obj);
3099 _cut(obj, NULL, NULL);
3103 * This executes a "copy" action on the selected text in the entry.
3105 * @param obj The entry object
3110 elm_entry_selection_copy(Evas_Object *obj)
3112 ELM_CHECK_WIDTYPE(obj, widtype);
3113 Widget_Data *wd = elm_widget_data_get(obj);
3115 _copy(obj, NULL, NULL);
3119 * This executes a "paste" action in the entry.
3121 * @param obj The entry object
3126 elm_entry_selection_paste(Evas_Object *obj)
3128 ELM_CHECK_WIDTYPE(obj, widtype);
3129 Widget_Data *wd = elm_widget_data_get(obj);
3131 _paste(obj, NULL, NULL);
3135 * This clears and frees the items in a entry's contextual (right click) menu.
3137 * @param obj The entry object
3142 elm_entry_context_menu_clear(Evas_Object *obj)
3144 ELM_CHECK_WIDTYPE(obj, widtype);
3145 Widget_Data *wd = elm_widget_data_get(obj);
3146 Elm_Entry_Context_Menu_Item *it;
3148 EINA_LIST_FREE(wd->items, it)
3150 eina_stringshare_del(it->label);
3151 eina_stringshare_del(it->icon_file);
3152 eina_stringshare_del(it->icon_group);
3158 * This adds an item to the entry's contextual menu.
3160 * @param obj The entry object
3161 * @param label The item's text label
3162 * @param icon_file The item's icon file
3163 * @param icon_type The item's icon type
3164 * @param func The callback to execute when the item is clicked
3165 * @param data The data to associate with the item for related functions
3170 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)
3172 ELM_CHECK_WIDTYPE(obj, widtype);
3173 Widget_Data *wd = elm_widget_data_get(obj);
3174 Elm_Entry_Context_Menu_Item *it;
3176 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3178 wd->items = eina_list_append(wd->items, it);
3180 it->label = eina_stringshare_add(label);
3181 it->icon_file = eina_stringshare_add(icon_file);
3182 it->icon_type = icon_type;
3184 it->data = (void *)data;
3188 * This disables the entry's contextual (right click) menu.
3190 * @param obj The entry object
3191 * @param disabled If true, the menu is disabled
3196 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3198 ELM_CHECK_WIDTYPE(obj, widtype);
3199 Widget_Data *wd = elm_widget_data_get(obj);
3201 if (wd->context_menu == !disabled) return;
3202 wd->context_menu = !disabled;
3206 * This returns whether the entry's contextual (right click) menu is disabled.
3208 * @param obj The entry object
3209 * @return If true, the menu is disabled
3214 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3216 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3217 Widget_Data *wd = elm_widget_data_get(obj);
3218 if (!wd) return EINA_FALSE;
3219 return !wd->context_menu;
3223 * This appends a custom item provider to the list for that entry
3225 * This appends the given callback. The list is walked from beginning to end
3226 * with each function called given the item href string in the text. If the
3227 * function returns an object handle other than NULL (it should create an
3228 * and object to do this), then this object is used to replace that item. If
3229 * not the next provider is called until one provides an item object, or the
3230 * default provider in entry does.
3232 * @param obj The entry object
3233 * @param func The function called to provide the item object
3234 * @param data The data passed to @p func
3239 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3241 ELM_CHECK_WIDTYPE(obj, widtype);
3242 Widget_Data *wd = elm_widget_data_get(obj);
3244 EINA_SAFETY_ON_NULL_RETURN(func);
3245 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3249 wd->item_providers = eina_list_append(wd->item_providers, ip);
3253 * This prepends a custom item provider to the list for that entry
3255 * This prepends the given callback. See elm_entry_item_provider_append() for
3258 * @param obj The entry object
3259 * @param func The function called to provide the item object
3260 * @param data The data passed to @p func
3265 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3267 ELM_CHECK_WIDTYPE(obj, widtype);
3268 Widget_Data *wd = elm_widget_data_get(obj);
3270 EINA_SAFETY_ON_NULL_RETURN(func);
3271 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3275 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3279 * This removes a custom item provider to the list for that entry
3281 * This removes the given callback. See elm_entry_item_provider_append() for
3284 * @param obj The entry object
3285 * @param func The function called to provide the item object
3286 * @param data The data passed to @p func
3291 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3293 ELM_CHECK_WIDTYPE(obj, widtype);
3294 Widget_Data *wd = elm_widget_data_get(obj);
3296 Elm_Entry_Item_Provider *ip;
3298 EINA_SAFETY_ON_NULL_RETURN(func);
3299 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3301 if ((ip->func == func) && ((!data) || (ip->data == data)))
3303 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3311 * Append a filter function for text inserted in the entry
3313 * Append the given callback to the list. This functions will be called
3314 * whenever any text is inserted into the entry, with the text to be inserted
3315 * as a parameter. The callback function is free to alter the text in any way
3316 * it wants, but it must remember to free the given pointer and update it.
3317 * If the new text is to be discarded, the function can free it and set it text
3318 * parameter to NULL. This will also prevent any following filters from being
3321 * @param obj The entry object
3322 * @param func The function to use as text filter
3323 * @param data User data to pass to @p func
3328 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3331 Elm_Entry_Text_Filter *tf;
3332 ELM_CHECK_WIDTYPE(obj, widtype);
3334 wd = elm_widget_data_get(obj);
3336 EINA_SAFETY_ON_NULL_RETURN(func);
3338 tf = _filter_new(func, data);
3341 wd->text_filters = eina_list_append(wd->text_filters, tf);
3345 * Prepend a filter function for text insdrted in the entry
3347 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3348 * for more information
3350 * @param obj The entry object
3351 * @param func The function to use as text filter
3352 * @param data User data to pass to @p func
3357 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3360 Elm_Entry_Text_Filter *tf;
3361 ELM_CHECK_WIDTYPE(obj, widtype);
3363 wd = elm_widget_data_get(obj);
3365 EINA_SAFETY_ON_NULL_RETURN(func);
3367 tf = _filter_new(func, data);
3370 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3374 * Remove a filter from the list
3376 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3377 * for more information.
3379 * @param obj The entry object
3380 * @param func The filter function to remove
3381 * @param data The user data passed when adding the function
3386 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3390 Elm_Entry_Text_Filter *tf;
3391 ELM_CHECK_WIDTYPE(obj, widtype);
3393 wd = elm_widget_data_get(obj);
3395 EINA_SAFETY_ON_NULL_RETURN(func);
3397 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3399 if ((tf->func == func) && ((!data) || (tf->data == data)))
3401 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3409 * This converts a markup (HTML-like) string into UTF-8.
3410 * Returning string is obtained with malloc.
3411 * After use the returned string, it should be freed.
3413 * @param s The string (in markup) to be converted
3414 * @return The converted string (in UTF-8). It should be freed.
3419 elm_entry_markup_to_utf8(const char *s)
3421 char *ss = _elm_util_mkup_to_text(s);
3422 if (!ss) ss = strdup("");
3427 * This converts a UTF-8 string into markup (HTML-like).
3428 * Returning string is obtained with malloc.
3429 * After use the returned string, it should be freed.
3431 * @param s The string (in UTF-8) to be converted
3432 * @return The converted string (in markup). It should be freed.
3437 elm_entry_utf8_to_markup(const char *s)
3439 char *ss = _elm_util_text_to_mkup(s);
3440 if (!ss) ss = strdup("");
3445 * Get the input method context in the entry widget
3447 * @param obj The entry object
3448 * @return The input method context
3452 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3454 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3455 Widget_Data *wd = elm_widget_data_get(obj);
3456 if (!wd || !wd->ent) return NULL;
3458 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3462 * Set whether entry should enable the return key on soft keyboard automatically
3464 * @param obj The entry object
3465 * @param on If true, entry enables the return key on soft keyboard automatically.
3470 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3472 ELM_CHECK_WIDTYPE(obj, widtype);
3473 Widget_Data *wd = elm_widget_data_get(obj);
3476 wd->autoreturnkey = on;
3477 _check_enable_returnkey(obj);
3481 * Set whether entry should support auto capitalization
3483 * @param obj The entry object
3484 * @param on If true, entry suports auto capitalization.
3489 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3491 ELM_CHECK_WIDTYPE(obj, widtype);
3492 Widget_Data *wd = elm_widget_data_get(obj);
3496 wd->autocapital = EINA_FALSE;
3498 wd->autocapital = autocap;
3500 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3501 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3502 wd->autocapital = EINA_FALSE;
3504 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3508 * Set whether entry should support auto period
3510 * @param obj The entry object
3511 * @param on If true, entry suports auto period.
3516 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3518 ELM_CHECK_WIDTYPE(obj, widtype);
3519 Widget_Data *wd = elm_widget_data_get(obj);
3523 wd->autoperiod = EINA_FALSE;
3525 wd->autoperiod = autoperiod;
3527 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3528 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3529 wd->autoperiod = EINA_FALSE;
3531 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3535 * Set the font size on the entry object
3537 * @param obj The entry object
3538 * @param size font size
3543 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3545 ELM_CHECK_WIDTYPE(obj, widtype);
3546 Widget_Data *wd = elm_widget_data_get(obj);
3547 Eina_Strbuf *fontbuf = NULL;
3552 t = eina_stringshare_add(elm_entry_entry_get(obj));
3553 fontbuf = eina_strbuf_new();
3554 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3556 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3558 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3560 elm_entry_entry_set(obj, t);
3564 eina_strbuf_free(fontbuf);
3565 eina_stringshare_del(t);
3569 * Set the text align on the entry object
3571 * @param obj The entry object
3572 * @param align align mode
3577 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3579 ELM_CHECK_WIDTYPE(obj, widtype);
3580 Widget_Data *wd = elm_widget_data_get(obj);
3585 t = eina_stringshare_add(elm_entry_entry_get(obj));
3587 if (len <= 0) return;
3589 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3590 elm_entry_entry_set(obj, t);
3594 eina_stringshare_del(t);
3598 * Set the text color on the entry object
3600 * @param obj The entry object
3601 * @param r Red property background color of The entry object
3602 * @param g Green property background color of The entry object
3603 * @param b Blue property background color of The entry object
3604 * @param a Alpha property background alpha of The entry object
3609 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3611 ELM_CHECK_WIDTYPE(obj, widtype);
3612 Widget_Data *wd = elm_widget_data_get(obj);
3613 Eina_Strbuf *colorbuf = NULL;
3618 t = eina_stringshare_add(elm_entry_entry_get(obj));
3620 if (len <= 0) return;
3621 colorbuf = eina_strbuf_new();
3622 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3624 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3626 elm_entry_entry_set(obj, t);
3630 eina_strbuf_free(colorbuf);
3631 eina_stringshare_del(t);
3635 * Set background color of the entry
3637 * @param obj The entry object
3638 * @param r Red property background color of The entry object
3639 * @param g Green property background color of The entry object
3640 * @param b Blue property background color of The entry object
3641 * @param a Alpha property background alpha of The entry object
3645 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3647 ELM_CHECK_WIDTYPE(obj, widtype);
3648 Widget_Data *wd = elm_widget_data_get(obj);
3649 evas_object_color_set(wd->bg, r, g, b, a);
3651 if (wd->bgcolor == EINA_FALSE)
3654 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3659 * Filter inserted text based on user defined character and byte limits
3661 * Add this filter to an entry to limit the characters that it will accept
3662 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3663 * The funtion works on the UTF-8 representation of the string, converting
3664 * it from the set markup, thus not accounting for any format in it.
3666 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3667 * it as data when setting the filter. In it it's possible to set limits
3668 * by character count or bytes (any of them is disabled if 0), and both can
3669 * be set at the same time. In that case, it first checks for characters,
3672 * The function will cut the inserted text in order to allow only the first
3673 * number of characters that are still allowed. The cut is made in
3674 * characters, even when limiting by bytes, in order to always contain
3675 * valid ones and avoid half unicode characters making it in.
3680 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3682 Elm_Entry_Filter_Limit_Size *lim = data;
3685 const char *(*text_get)(const Evas_Object *);
3686 const char *widget_type;
3688 EINA_SAFETY_ON_NULL_RETURN(data);
3689 EINA_SAFETY_ON_NULL_RETURN(entry);
3690 EINA_SAFETY_ON_NULL_RETURN(text);
3692 /* hack. I don't want to copy the entire function to work with
3694 widget_type = elm_widget_type_get(entry);
3695 if (!strcmp(widget_type, "entry"))
3696 text_get = elm_entry_entry_get;
3697 else if (!strcmp(widget_type, "scrolled_entry"))
3698 text_get = elm_scrolled_entry_entry_get;
3702 current = elm_entry_markup_to_utf8(text_get(entry));
3704 if (lim->max_char_count > 0)
3707 len = evas_string_char_len_get(current);
3708 if (len >= lim->max_char_count)
3710 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3716 newlen = evas_string_char_len_get(*text);
3717 cut = strlen(*text);
3718 while ((len + newlen) > lim->max_char_count)
3720 cut = evas_string_char_prev_get(*text, cut, NULL);
3726 if (lim->max_byte_count > 0)
3728 len = strlen(current);
3729 if (len >= lim->max_byte_count)
3731 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3737 newlen = strlen(*text);
3738 while ((len + newlen) > lim->max_byte_count)
3740 int p = evas_string_char_prev_get(*text, newlen, NULL);
3741 newlen -= (newlen - p);
3744 (*text)[newlen] = 0;
3755 * Filter inserted text based on accepted or rejected sets of characters
3757 * Add this filter to an entry to restrict the set of accepted characters
3758 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3759 * This structure contains both accepted and rejected sets, but they are
3760 * mutually exclusive. If accepted is set, it will be used, otherwise it
3761 * goes on to the rejected set.
3764 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3766 Elm_Entry_Filter_Accept_Set *as = data;
3770 int read_idx, last_read_idx = 0, read_char;
3772 EINA_SAFETY_ON_NULL_RETURN(data);
3773 EINA_SAFETY_ON_NULL_RETURN(text);
3775 if ((!as->accepted) && (!as->rejected))
3781 goes_in = EINA_TRUE;
3786 goes_in = EINA_FALSE;
3790 read_idx = evas_string_char_next_get(*text, 0, &read_char);
3793 int cmp_idx, cmp_char;
3794 Eina_Bool in_set = EINA_FALSE;
3796 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3799 if (read_char == cmp_char)
3804 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3806 if (in_set == goes_in)
3808 int size = read_idx - last_read_idx;
3809 const char *src = (*text) + last_read_idx;
3811 memcpy(insert, *text + last_read_idx, size);
3814 last_read_idx = read_idx;
3815 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3821 * This sets the file (and implicitly loads it) for the text to display and
3822 * then edit. All changes are written back to the file after a short delay if
3823 * the entry object is set to autosave.
3825 * @param obj The entry object
3826 * @param file The path to the file to load and save
3827 * @param format The file format
3832 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3834 ELM_CHECK_WIDTYPE(obj, widtype);
3835 Widget_Data *wd = elm_widget_data_get(obj);
3837 if (wd->delay_write)
3839 ecore_timer_del(wd->delay_write);
3840 wd->delay_write = NULL;
3842 if (wd->autosave) _save(obj);
3843 eina_stringshare_replace(&wd->file, file);
3844 wd->format = format;
3849 * Gets the file to load and save and the file format
3851 * @param obj The entry object
3852 * @param file The path to the file to load and save
3853 * @param format The file format
3858 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3860 ELM_CHECK_WIDTYPE(obj, widtype);
3861 Widget_Data *wd = elm_widget_data_get(obj);
3863 if (file) *file = wd->file;
3864 if (format) *format = wd->format;
3868 * This function writes any changes made to the file set with
3869 * elm_entry_file_set()
3871 * @param obj The entry object
3876 elm_entry_file_save(Evas_Object *obj)
3878 ELM_CHECK_WIDTYPE(obj, widtype);
3879 Widget_Data *wd = elm_widget_data_get(obj);
3881 if (wd->delay_write)
3883 ecore_timer_del(wd->delay_write);
3884 wd->delay_write = NULL;
3887 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3891 * This sets the entry object to 'autosave' the loaded text file or not.
3893 * @param obj The entry object
3894 * @param autosave Autosave the loaded file or not
3899 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3901 ELM_CHECK_WIDTYPE(obj, widtype);
3902 Widget_Data *wd = elm_widget_data_get(obj);
3904 wd->autosave = !!autosave;
3908 * This gets the entry object's 'autosave' status.
3910 * @param obj The entry object
3911 * @return Autosave the loaded file or not
3916 elm_entry_autosave_get(const Evas_Object *obj)
3918 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3919 Widget_Data *wd = elm_widget_data_get(obj);
3920 if (!wd) return EINA_FALSE;
3921 return wd->autosave;
3925 * Control pasting of text and images for the widget.
3927 * Normally the entry allows both text and images to be pasted. By setting
3928 * textonly to be true, this prevents images from being pasted.
3930 * Note this only changes the behaviour of text.
3932 * @param obj The entry object
3933 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3938 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3940 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3941 ELM_CHECK_WIDTYPE(obj, widtype);
3942 Widget_Data *wd = elm_widget_data_get(obj);
3944 textonly = !!textonly;
3945 if (wd->textonly == textonly) return;
3946 wd->textonly = !!textonly;
3947 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3948 #ifdef HAVE_ELEMENTARY_X
3949 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3954 * Getting elm_entry text paste/drop mode.
3956 * In textonly mode, only text may be pasted or dropped into the widget.
3958 * @param obj The entry object
3959 * @return If the widget only accepts text from pastes.
3964 elm_entry_cnp_textonly_get(Evas_Object *obj)
3966 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3967 Widget_Data *wd = elm_widget_data_get(obj);
3968 if (!wd) return EINA_FALSE;
3969 return wd->textonly;
3973 * This sets the attribute to show the input panel automatically.
3975 * @param obj The entry object
3976 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3981 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3983 ELM_CHECK_WIDTYPE(obj, widtype);
3984 Widget_Data *wd = elm_widget_data_get(obj);
3987 wd->input_panel_enable = enabled;
3988 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3992 * Set the input panel layout of the entry
3994 * @param obj The entry object
3995 * @param layout the layout to set
4000 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4002 ELM_CHECK_WIDTYPE(obj, widtype);
4003 Widget_Data *wd = elm_widget_data_get(obj);
4006 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4009 wd->input_panel_layout = layout;
4011 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4015 * Set the magnifier style of the entry
4017 * @param obj The entry object
4018 * @param type the magnifier style to set
4023 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4025 ELM_CHECK_WIDTYPE(obj, widtype);
4026 Widget_Data *wd = elm_widget_data_get(obj);
4029 wd->mgf_type = type;
4030 _magnifier_create(obj);