1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
6 /* Maximum chunk size to be inserted to the entry at once
7 * FIXME: This size is arbitrary, should probably choose a better size.
8 * Possibly also find a way to set it to a low value for weak computers,
9 * and to a big value for better computers. */
10 #define _CHUNK_SIZE 10000
12 typedef struct _Mod_Api Mod_Api;
14 typedef struct _Widget_Data Widget_Data;
15 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
16 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
17 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
21 Evas_Object *ent, *scroller, *end, *icon;
22 Evas_Object *hoversel;
23 Ecore_Job *deferred_recalc_job;
24 Ecore_Event_Handler *sel_notify_handler;
25 Ecore_Event_Handler *sel_clear_handler;
26 Ecore_Timer *longpress_timer;
27 Ecore_Timer *delay_write;
28 /* for deferred appending */
29 Ecore_Idler *append_text_idler;
30 char *append_text_left;
31 int append_text_position;
33 /* Only for clipboard */
37 Elm_Text_Format format;
38 Evas_Coord lastw, entmw, entmh;
39 Evas_Coord downx, downy;
41 Eina_List *item_providers;
42 Eina_List *text_filters;
44 Mod_Api *api; // module api if supplied
46 Elm_Scroller_Policy policy_h, policy_v;
47 Elm_Wrap_Type linewrap;
48 Eina_Bool changed : 1;
49 Eina_Bool single_line : 1;
50 Eina_Bool password : 1;
51 Eina_Bool editable : 1;
52 Eina_Bool selection_asked : 1;
53 Eina_Bool have_selection : 1;
54 Eina_Bool selmode : 1;
55 Eina_Bool deferred_cur : 1;
56 Eina_Bool cur_changed : 1;
57 Eina_Bool disabled : 1;
58 Eina_Bool context_menu : 1;
59 Eina_Bool drag_selection_asked : 1;
60 Eina_Bool can_write : 1;
61 Eina_Bool autosave : 1;
62 Eina_Bool textonly : 1;
63 Eina_Bool usedown : 1;
67 struct _Elm_Entry_Context_Menu_Item
71 const char *icon_file;
72 const char *icon_group;
73 Elm_Icon_Type icon_type;
78 struct _Elm_Entry_Item_Provider
80 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
84 struct _Elm_Entry_Text_Filter
86 Elm_Entry_Filter_Cb func;
90 typedef enum _Length_Unit
97 static const char *widtype = NULL;
99 #ifdef HAVE_ELEMENTARY_X
100 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
102 static void _del_hook(Evas_Object *obj);
103 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
104 static void _theme_hook(Evas_Object *obj);
105 static void _disable_hook(Evas_Object *obj);
106 static void _sizing_eval(Evas_Object *obj);
107 static void _on_focus_hook(void *data, Evas_Object *obj);
108 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
109 static const char *_getbase(Evas_Object *obj);
110 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
111 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
112 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
113 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
114 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
115 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
116 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
117 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
118 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
120 static const char SIG_CHANGED[] = "changed";
121 static const char SIG_CHANGED_USER[] = "changed,user";
122 static const char SIG_ACTIVATED[] = "activated";
123 static const char SIG_PRESS[] = "press";
124 static const char SIG_LONGPRESSED[] = "longpressed";
125 static const char SIG_CLICKED[] = "clicked";
126 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
127 static const char SIG_CLICKED_TRIPLE[] = "clicked,triple";
128 static const char SIG_FOCUSED[] = "focused";
129 static const char SIG_UNFOCUSED[] = "unfocused";
130 static const char SIG_SELECTION_PASTE[] = "selection,paste";
131 static const char SIG_SELECTION_COPY[] = "selection,copy";
132 static const char SIG_SELECTION_CUT[] = "selection,cut";
133 static const char SIG_SELECTION_START[] = "selection,start";
134 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
135 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
136 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
137 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
138 static const char SIG_ANCHOR_DOWN[] = "anchor,down";
139 static const char SIG_ANCHOR_UP[] = "anchor,up";
140 static const char SIG_ANCHOR_IN[] = "anchor,in";
141 static const char SIG_ANCHOR_OUT[] = "anchor,out";
142 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
143 static const Evas_Smart_Cb_Description _signals[] = {
147 {SIG_LONGPRESSED, ""},
149 {SIG_CLICKED_DOUBLE, ""},
150 {SIG_CLICKED_TRIPLE, ""},
153 {SIG_SELECTION_PASTE, ""},
154 {SIG_SELECTION_COPY, ""},
155 {SIG_SELECTION_CUT, ""},
156 {SIG_SELECTION_START, ""},
157 {SIG_SELECTION_CHANGED, ""},
158 {SIG_SELECTION_CLEARED, ""},
159 {SIG_CURSOR_CHANGED, ""},
160 {SIG_ANCHOR_CLICKED, ""},
161 {SIG_ANCHOR_DOWN, ""},
164 {SIG_ANCHOR_OUT, ""},
165 {SIG_PREEDIT_CHANGED, ""},
166 {SIG_CHANGED_USER, ""},
170 static Eina_List *entries = NULL;
174 void (*obj_hook) (Evas_Object *obj);
175 void (*obj_unhook) (Evas_Object *obj);
176 void (*obj_longpress) (Evas_Object *obj);
180 _module(Evas_Object *obj __UNUSED__)
182 static Elm_Module *m = NULL;
183 if (m) goto ok; // already found - just use
184 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
186 m->api = malloc(sizeof(Mod_Api));
187 if (!m->api) return NULL;
188 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
189 _elm_module_symbol_get(m, "obj_hook");
190 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
191 _elm_module_symbol_get(m, "obj_unhook");
192 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
193 _elm_module_symbol_get(m, "obj_longpress");
194 ok: // ok - return api
199 _buf_append(char *buf, const char *str, int *len, int *alloc)
201 int len2 = strlen(str);
202 if ((*len + len2) >= *alloc)
204 char *buf2 = realloc(buf, *alloc + len2 + 512);
205 if (!buf2) return NULL;
207 *alloc += (512 + len2);
209 strcpy(buf + *len, str);
215 _load_file(const char *file)
219 int alloc = 0, len = 0;
220 char *text = NULL, buf[16384 + 1];
222 f = fopen(file, "rb");
224 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
228 tmp_text = _buf_append(text, buf, &len, &alloc);
229 if (!tmp_text) break;
237 _load_plain(const char *file)
241 text = _load_file(file);
246 text2 = elm_entry_utf8_to_markup(text);
254 _load(Evas_Object *obj)
256 Widget_Data *wd = elm_widget_data_get(obj);
261 elm_entry_entry_set(obj, "");
266 case ELM_TEXT_FORMAT_PLAIN_UTF8:
267 text = _load_plain(wd->file);
269 case ELM_TEXT_FORMAT_MARKUP_UTF8:
270 text = _load_file(wd->file);
278 elm_entry_entry_set(obj, text);
282 elm_entry_entry_set(obj, "");
286 _save_markup_utf8(const char *file, const char *text)
290 if ((!text) || (!text[0]))
292 ecore_file_unlink(file);
295 f = fopen(file, "wb");
298 // FIXME: report a write error
301 fputs(text, f); // FIXME: catch error
306 _save_plain_utf8(const char *file, const char *text)
310 text2 = elm_entry_markup_to_utf8(text);
313 _save_markup_utf8(file, text2);
318 _save(Evas_Object *obj)
320 Widget_Data *wd = elm_widget_data_get(obj);
322 if (!wd->file) return;
325 case ELM_TEXT_FORMAT_PLAIN_UTF8:
326 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
328 case ELM_TEXT_FORMAT_MARKUP_UTF8:
329 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
337 _delay_write(void *data)
339 Widget_Data *wd = elm_widget_data_get(data);
340 if (!wd) return ECORE_CALLBACK_CANCEL;
342 wd->delay_write = NULL;
343 return ECORE_CALLBACK_CANCEL;
346 static Elm_Entry_Text_Filter *
347 _filter_new(Elm_Entry_Filter_Cb func, void *data)
349 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
350 if (!tf) return NULL;
353 if (func == elm_entry_filter_limit_size)
355 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
362 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
368 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
371 else if (func == elm_entry_filter_accept_set)
373 Elm_Entry_Filter_Accept_Set *as = data, *as2;
380 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
387 as2->accepted = eina_stringshare_add(as->accepted);
389 as2->accepted = NULL;
391 as2->rejected = eina_stringshare_add(as->rejected);
393 as2->rejected = NULL;
402 _filter_free(Elm_Entry_Text_Filter *tf)
404 if (tf->func == elm_entry_filter_limit_size)
406 Elm_Entry_Filter_Limit_Size *lim = tf->data;
409 else if (tf->func == elm_entry_filter_accept_set)
411 Elm_Entry_Filter_Accept_Set *as = tf->data;
414 if (as->accepted) eina_stringshare_del(as->accepted);
415 if (as->rejected) eina_stringshare_del(as->rejected);
423 _del_pre_hook(Evas_Object *obj)
425 Widget_Data *wd = elm_widget_data_get(obj);
429 ecore_timer_del(wd->delay_write);
430 wd->delay_write = NULL;
431 if (wd->autosave) _save(obj);
436 _del_hook(Evas_Object *obj)
438 Widget_Data *wd = elm_widget_data_get(obj);
439 Elm_Entry_Context_Menu_Item *it;
440 Elm_Entry_Item_Provider *ip;
441 Elm_Entry_Text_Filter *tf;
443 if (wd->file) eina_stringshare_del(wd->file);
445 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
446 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
448 entries = eina_list_remove(entries, obj);
449 #ifdef HAVE_ELEMENTARY_X
450 if (wd->sel_notify_handler)
451 ecore_event_handler_del(wd->sel_notify_handler);
452 if (wd->sel_clear_handler)
453 ecore_event_handler_del(wd->sel_clear_handler);
455 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
456 if (wd->text) eina_stringshare_del(wd->text);
457 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
458 if (wd->append_text_idler)
460 ecore_idler_del(wd->append_text_idler);
461 free(wd->append_text_left);
462 wd->append_text_left = NULL;
463 wd->append_text_idler = NULL;
465 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
466 EINA_LIST_FREE(wd->items, it)
468 eina_stringshare_del(it->label);
469 eina_stringshare_del(it->icon_file);
470 eina_stringshare_del(it->icon_group);
473 EINA_LIST_FREE(wd->item_providers, ip)
477 EINA_LIST_FREE(wd->text_filters, tf)
485 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
487 Widget_Data *wd = elm_widget_data_get(obj);
488 edje_object_mirrored_set(wd->ent, rtl);
492 _theme_hook(Evas_Object *obj)
494 Widget_Data *wd = elm_widget_data_get(obj);
496 _elm_widget_mirrored_reload(obj);
497 _mirrored_set(obj, elm_widget_mirrored_get(obj));
499 t = eina_stringshare_add(elm_entry_entry_get(obj));
500 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
501 if (_elm_config->desktop_entry)
502 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
503 elm_entry_entry_set(obj, t);
504 eina_stringshare_del(t);
505 if (elm_widget_disabled_get(obj))
506 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
507 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
508 if (elm_widget_focus_get(obj))
509 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
510 edje_object_message_signal_process(wd->ent);
511 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
512 elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
513 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
514 elm_widget_style_get(obj));
520 edj = elm_smart_scroller_edje_object_get(wd->scroller);
521 str = edje_object_data_get(edj, "focus_highlight");
522 if ((str) && (!strcmp(str, "on")))
523 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
525 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
531 _disable_hook(Evas_Object *obj)
533 Widget_Data *wd = elm_widget_data_get(obj);
535 if (elm_widget_disabled_get(obj))
537 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
538 wd->disabled = EINA_TRUE;
542 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
543 wd->disabled = EINA_FALSE;
548 _recalc_cursor_geometry(Evas_Object *obj)
550 Widget_Data *wd = elm_widget_data_get(obj);
552 evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
553 if (!wd->deferred_recalc_job)
555 Evas_Coord cx, cy, cw, ch;
556 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
560 elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
561 wd->cur_changed = EINA_FALSE;
565 wd->deferred_cur = EINA_TRUE;
569 _elm_win_recalc_job(void *data)
571 Widget_Data *wd = elm_widget_data_get(data);
572 Evas_Coord minh = -1, resw = -1, minw = -1, fw = 0, fh = 0;
574 wd->deferred_recalc_job = NULL;
576 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
577 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
578 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
581 /* This is a hack to workaround the way min size hints are treated.
582 * If the minimum width is smaller than the restricted width, it means
583 * the mininmum doesn't matter. */
586 Evas_Coord ominw = -1;
587 evas_object_size_hint_min_get(data, &ominw, NULL);
591 elm_coords_finger_size_adjust(1, &fw, 1, &fh);
594 Evas_Coord vmw = 0, vmh = 0;
596 edje_object_size_min_calc
597 (elm_smart_scroller_edje_object_get(wd->scroller),
601 evas_object_size_hint_min_set(data, vmw, minh + vmh);
602 evas_object_size_hint_max_set(data, -1, minh + vmh);
606 evas_object_size_hint_min_set(data, vmw, vmh);
607 evas_object_size_hint_max_set(data, -1, -1);
614 evas_object_size_hint_min_set(data, minw, minh);
615 evas_object_size_hint_max_set(data, -1, minh);
619 evas_object_size_hint_min_set(data, fw, minh);
620 evas_object_size_hint_max_set(data, -1, -1);
624 if ((wd->deferred_cur) && (elm_object_focus_get(data)))
626 Evas_Coord cx, cy, cw, ch;
627 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
631 elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
632 wd->cur_changed = EINA_FALSE;
638 _sizing_eval(Evas_Object *obj)
640 Widget_Data *wd = elm_widget_data_get(obj);
641 Evas_Coord minw = -1, minh = -1;
642 Evas_Coord resw, resh;
645 evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
648 if ((resw == wd->lastw) && (!wd->changed)) return;
649 wd->changed = EINA_FALSE;
653 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
655 evas_object_resize(wd->scroller, resw, resh);
656 edje_object_size_min_calc
657 (elm_smart_scroller_edje_object_get(wd->scroller),
659 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
660 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
663 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
665 if ((minw > 0) && (vw < minw)) vw = minw;
666 if (minh > vh) vh = minh;
668 if (wd->single_line) h = vmh + minh;
670 evas_object_resize(wd->ent, vw, vh);
671 evas_object_size_hint_min_set(obj, w, h);
673 evas_object_size_hint_max_set(obj, -1, h);
675 evas_object_size_hint_max_set(obj, -1, -1);
679 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
680 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
685 if (!wd->changed) return;
686 wd->changed = EINA_FALSE;
690 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
692 edje_object_size_min_calc(wd->ent, &minw, &minh);
695 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
697 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
699 if ((minw > 0) && (vw < minw)) vw = minw;
700 if (minh > 0) vh = minh;
702 evas_object_resize(wd->ent, vw, vh);
703 edje_object_size_min_calc
704 (elm_smart_scroller_edje_object_get(wd->scroller),
706 if (wd->single_line) h = vmh + minh;
708 evas_object_size_hint_min_set(obj, w, h);
710 evas_object_size_hint_max_set(obj, -1, h);
712 evas_object_size_hint_max_set(obj, -1, -1);
716 edje_object_size_min_calc(wd->ent, &minw, &minh);
719 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
720 evas_object_size_hint_min_set(obj, minw, minh);
722 evas_object_size_hint_max_set(obj, -1, minh);
724 evas_object_size_hint_max_set(obj, -1, -1);
728 _recalc_cursor_geometry(obj);
732 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
734 Widget_Data *wd = elm_widget_data_get(obj);
735 Evas_Object *top = elm_widget_top_get(obj);
737 if (!wd->editable) return;
738 if (elm_widget_focus_get(obj))
740 evas_object_focus_set(wd->ent, EINA_TRUE);
741 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
742 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
743 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
747 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
748 evas_object_focus_set(wd->ent, EINA_FALSE);
749 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
750 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
755 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
757 Widget_Data *wd = elm_widget_data_get(obj);
759 edje_object_signal_emit(wd->ent, emission, source);
761 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
766 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
768 Widget_Data *wd = elm_widget_data_get(obj);
770 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
772 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
773 emission, source, func_cb, data);
777 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
779 Widget_Data *wd = elm_widget_data_get(obj);
780 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
783 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
784 emission, source, func_cb, data);
788 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
790 Widget_Data *wd = elm_widget_data_get(obj);
791 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
795 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
797 Widget_Data *wd = elm_widget_data_get(obj);
799 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
803 _show_region_hook(void *data, Evas_Object *obj)
805 Widget_Data *wd = elm_widget_data_get(data);
806 Evas_Coord x, y, w, h;
808 elm_widget_show_region_get(obj, &x, &y, &w, &h);
810 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
814 _hoversel_position(Evas_Object *obj)
816 Widget_Data *wd = elm_widget_data_get(obj);
817 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
822 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
831 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
833 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
844 evas_object_move(wd->hoversel, x + cx, y + cy);
845 evas_object_resize(wd->hoversel, cw, ch);
849 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
851 Widget_Data *wd = elm_widget_data_get(data);
853 if (wd->hoversel) _hoversel_position(data);
857 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
859 Widget_Data *wd = elm_widget_data_get(data);
868 Evas_Coord vw = 0, vh = 0;
870 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
871 if (vw < wd->entmw) vw = wd->entmw;
872 if (vh < wd->entmh) vh = wd->entmh;
873 evas_object_resize(wd->ent, vw, vh);
875 if (wd->hoversel) _hoversel_position(data);
879 _hover_del(void *data)
881 Widget_Data *wd = elm_widget_data_get(data);
886 evas_object_del(wd->hoversel);
889 wd->hovdeljob = NULL;
893 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
895 Widget_Data *wd = elm_widget_data_get(data);
898 if (wd->hoversel) evas_object_hide(wd->hoversel);
901 if (!_elm_config->desktop_entry)
904 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
907 elm_widget_scroll_freeze_pop(data);
908 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
909 wd->hovdeljob = ecore_job_add(_hover_del, data);
913 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
915 Widget_Data *wd = elm_widget_data_get(data);
917 wd->selmode = EINA_TRUE;
918 edje_object_part_text_select_none(wd->ent, "elm.text");
919 if (!_elm_config->desktop_entry)
922 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
924 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
925 if (!_elm_config->desktop_entry)
926 elm_widget_scroll_hold_push(data);
930 _elm_entry_entry_paste(Evas_Object *obj, const char *entry)
932 elm_entry_entry_insert(obj, entry);
933 evas_object_smart_callback_call(obj, SIG_CHANGED_USER, NULL);
937 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
939 Widget_Data *wd = elm_widget_data_get(data);
941 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
942 if (wd->sel_notify_handler)
944 #ifdef HAVE_ELEMENTARY_X
945 Elm_Sel_Format formats;
946 wd->selection_asked = EINA_TRUE;
947 formats = ELM_SEL_FORMAT_MARKUP;
949 formats |= ELM_SEL_FORMAT_IMAGE;
950 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
956 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
958 Widget_Data *wd = elm_widget_data_get(obj);
962 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
963 if ((!sel) || (!sel[0])) return; /* avoid deleting our own selection */
964 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
965 if (seltype == ELM_SEL_CLIPBOARD)
966 eina_stringshare_replace(&wd->cut_sel, sel);
970 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
972 Widget_Data *wd = elm_widget_data_get(data);
975 wd->selmode = EINA_FALSE;
976 if (!_elm_config->desktop_entry)
977 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
978 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
979 if (!_elm_config->desktop_entry)
980 elm_widget_scroll_hold_pop(data);
981 _store_selection(ELM_SEL_CLIPBOARD, data);
982 edje_object_part_text_insert(wd->ent, "elm.text", "");
983 edje_object_part_text_select_none(wd->ent, "elm.text");
988 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
990 Widget_Data *wd = elm_widget_data_get(data);
992 wd->selmode = EINA_FALSE;
993 if (!_elm_config->desktop_entry)
995 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
996 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
997 elm_widget_scroll_hold_pop(data);
999 _store_selection(ELM_SEL_CLIPBOARD, data);
1000 // edje_object_part_text_select_none(wd->ent, "elm.text");
1004 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1006 Widget_Data *wd = elm_widget_data_get(data);
1008 wd->selmode = EINA_FALSE;
1009 if (!_elm_config->desktop_entry)
1010 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1011 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1012 if (!_elm_config->desktop_entry)
1013 elm_widget_scroll_hold_pop(data);
1014 edje_object_part_text_select_none(wd->ent, "elm.text");
1018 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1020 Elm_Entry_Context_Menu_Item *it = data;
1021 Evas_Object *obj2 = it->obj;
1022 if (it->func) it->func(it->data, obj2, NULL);
1026 _menu_press(Evas_Object *obj)
1028 Widget_Data *wd = elm_widget_data_get(obj);
1031 const Elm_Entry_Context_Menu_Item *it;
1033 if ((wd->api) && (wd->api->obj_longpress))
1035 wd->api->obj_longpress(obj);
1037 else if (wd->context_menu)
1039 const char *context_menu_orientation;
1041 if (wd->hoversel) evas_object_del(wd->hoversel);
1042 else elm_widget_scroll_freeze_push(obj);
1043 wd->hoversel = elm_hoversel_add(obj);
1044 context_menu_orientation = edje_object_data_get
1045 (wd->ent, "context_menu_orientation");
1046 if ((context_menu_orientation) &&
1047 (!strcmp(context_menu_orientation, "horizontal")))
1048 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1049 elm_object_style_set(wd->hoversel, "entry");
1050 elm_widget_sub_object_add(obj, wd->hoversel);
1051 elm_object_text_set(wd->hoversel, "Text");
1052 top = elm_widget_top_get(obj);
1053 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1054 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1055 if (wd->have_selection)
1059 if (wd->have_selection)
1061 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1064 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1067 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1075 if (!_elm_config->desktop_entry)
1078 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1081 if (elm_selection_selection_has_owner())
1084 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1089 EINA_LIST_FOREACH(wd->items, l, it)
1091 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1092 it->icon_type, _item_clicked, it);
1096 _hoversel_position(obj);
1097 evas_object_show(wd->hoversel);
1098 elm_hoversel_hover_begin(wd->hoversel);
1100 if (!_elm_config->desktop_entry)
1102 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1103 edje_object_part_text_select_abort(wd->ent, "elm.text");
1109 _long_press(void *data)
1111 Widget_Data *wd = elm_widget_data_get(data);
1112 if (!wd) return ECORE_CALLBACK_CANCEL;
1114 wd->longpress_timer = NULL;
1115 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1116 return ECORE_CALLBACK_CANCEL;
1120 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1122 Widget_Data *wd = elm_widget_data_get(data);
1123 Evas_Event_Mouse_Down *ev = event_info;
1125 if (wd->disabled) return;
1126 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1127 wd->downx = ev->canvas.x;
1128 wd->downy = ev->canvas.y;
1129 if (ev->button == 1)
1131 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1132 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1137 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1139 Widget_Data *wd = elm_widget_data_get(data);
1140 Evas_Event_Mouse_Up *ev = event_info;
1142 if (wd->disabled) return;
1143 if (ev->button == 1)
1145 if (wd->longpress_timer)
1147 ecore_timer_del(wd->longpress_timer);
1148 wd->longpress_timer = NULL;
1151 else if (ev->button == 3)
1159 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1161 Widget_Data *wd = elm_widget_data_get(data);
1162 Evas_Event_Mouse_Move *ev = event_info;
1164 if (wd->disabled) return;
1167 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1169 if (wd->longpress_timer)
1171 ecore_timer_del(wd->longpress_timer);
1172 wd->longpress_timer = NULL;
1175 else if (wd->longpress_timer)
1179 dx = wd->downx - ev->cur.canvas.x;
1181 dy = wd->downy - ev->cur.canvas.y;
1184 ((_elm_config->finger_size / 2) *
1185 (_elm_config->finger_size / 2)))
1187 ecore_timer_del(wd->longpress_timer);
1188 wd->longpress_timer = NULL;
1192 else if (wd->longpress_timer)
1196 dx = wd->downx - ev->cur.canvas.x;
1198 dy = wd->downy - ev->cur.canvas.y;
1201 ((_elm_config->finger_size / 2) *
1202 (_elm_config->finger_size / 2)))
1204 ecore_timer_del(wd->longpress_timer);
1205 wd->longpress_timer = NULL;
1211 _getbase(Evas_Object *obj)
1213 Widget_Data *wd = elm_widget_data_get(obj);
1214 if (!wd) return "base";
1217 if (wd->password) return "base-password";
1220 if (wd->single_line) return "base-single";
1223 switch (wd->linewrap)
1226 return "base-charwrap";
1229 case ELM_WRAP_MIXED:
1230 return "base-mixedwrap";
1233 return "base-nowrap";
1240 if (wd->password) return "base-password";
1243 if (wd->single_line) return "base-single-noedit";
1246 switch (wd->linewrap)
1249 return "base-noedit-charwrap";
1251 return "base-noedit";
1252 case ELM_WRAP_MIXED:
1253 return "base-noedit-mixedwrap";
1256 return "base-nowrap-noedit";
1265 _entry_changed_common_handling(void *data, const char *event)
1267 Widget_Data *wd = elm_widget_data_get(data);
1270 wd->changed = EINA_TRUE;
1271 /* Reset the size hints which are no more relevant.
1272 * Keep the height, this is a hack, but doesn't really matter
1273 * cause we'll re-eval in a moment. */
1274 evas_object_size_hint_min_get(data, NULL, &minh);
1275 evas_object_size_hint_min_set(data, -1, minh);
1277 if (wd->text) eina_stringshare_del(wd->text);
1279 evas_object_smart_callback_call(data, event, NULL);
1280 if (wd->delay_write)
1282 ecore_timer_del(wd->delay_write);
1283 wd->delay_write = NULL;
1285 if ((!wd->autosave) || (!wd->file)) return;
1286 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1290 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1292 _entry_changed_common_handling(data, SIG_CHANGED);
1296 _signal_entry_changed_user(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1298 evas_object_smart_callback_call(data, SIG_CHANGED_USER, NULL);
1302 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1304 _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1308 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1310 Widget_Data *wd = elm_widget_data_get(data);
1314 EINA_LIST_FOREACH(entries, l, entry)
1316 if (entry != data) elm_entry_select_none(entry);
1318 wd->have_selection = EINA_TRUE;
1319 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1320 #ifdef HAVE_ELEMENTARY_X
1321 if (wd->sel_notify_handler)
1323 const char *txt = elm_entry_selection_get(data);
1326 top = elm_widget_top_get(data);
1327 if ((top) && (elm_win_xwindow_get(top)))
1328 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1334 _signal_selection_all(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1336 Widget_Data *wd = elm_widget_data_get(data);
1338 elm_entry_select_all(data);
1342 _signal_selection_none(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1344 Widget_Data *wd = elm_widget_data_get(data);
1346 elm_entry_select_none(data);
1350 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1352 Widget_Data *wd = elm_widget_data_get(data);
1354 wd->have_selection = EINA_TRUE;
1355 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1356 _store_selection(ELM_SEL_PRIMARY, data);
1360 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1362 Widget_Data *wd = elm_widget_data_get(data);
1364 if (!wd->have_selection) return;
1365 wd->have_selection = EINA_FALSE;
1366 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1367 if (wd->sel_notify_handler)
1371 #ifdef HAVE_ELEMENTARY_X
1374 top = elm_widget_top_get(data);
1375 if ((top) && (elm_win_xwindow_get(top)))
1376 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1379 eina_stringshare_del(wd->cut_sel);
1384 #ifdef HAVE_ELEMENTARY_X
1387 top = elm_widget_top_get(data);
1388 if ((top) && (elm_win_xwindow_get(top)))
1389 elm_selection_clear(ELM_SEL_PRIMARY, data);
1396 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1398 Widget_Data *wd = elm_widget_data_get(data);
1399 Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ? ELM_SEL_PRIMARY : ELM_SEL_CLIPBOARD;
1401 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1402 if (wd->sel_notify_handler)
1404 #ifdef HAVE_ELEMENTARY_X
1407 top = elm_widget_top_get(data);
1408 if ((top) && (elm_win_xwindow_get(top)))
1410 wd->selection_asked = EINA_TRUE;
1411 elm_selection_get(type, ELM_SEL_FORMAT_MARKUP, data,
1419 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1421 _copy(data, NULL, NULL);
1425 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1427 _cut(data, NULL, NULL);
1431 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1433 Widget_Data *wd = elm_widget_data_get(data);
1435 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1436 wd->cur_changed = EINA_TRUE;
1437 _recalc_cursor_geometry(data);
1441 _signal_anchor_geoms_do_things_with(Widget_Data *wd, Elm_Entry_Anchor_Info *ei)
1443 const Eina_List *geoms, *l;
1444 Evas_Textblock_Rectangle *r;
1445 Evas_Coord px, py, x, y;
1447 geoms = edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei->name);
1451 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1452 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1453 EINA_LIST_FOREACH(geoms, l, r)
1455 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1456 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1468 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1470 Widget_Data *wd = elm_widget_data_get(data);
1471 Elm_Entry_Anchor_Info ei;
1475 p = emission + sizeof("nchor,mouse,down,");
1476 ei.button = strtol(p, &p2, 10);
1478 ei.x = ei.y = ei.w = ei.h = 0;
1480 _signal_anchor_geoms_do_things_with(wd, &ei);
1483 evas_object_smart_callback_call(data, SIG_ANCHOR_DOWN, &ei);
1487 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1489 Widget_Data *wd = elm_widget_data_get(data);
1490 Elm_Entry_Anchor_Info ei;
1494 p = emission + sizeof("nchor,mouse,up,");
1495 ei.button = strtol(p, &p2, 10);
1497 ei.x = ei.y = ei.w = ei.h = 0;
1499 _signal_anchor_geoms_do_things_with(wd, &ei);
1502 evas_object_smart_callback_call(data, SIG_ANCHOR_UP, &ei);
1506 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1508 Widget_Data *wd = elm_widget_data_get(data);
1509 Elm_Entry_Anchor_Info ei;
1513 p = emission + sizeof("nchor,mouse,clicked,");
1514 ei.button = strtol(p, &p2, 10);
1516 ei.x = ei.y = ei.w = ei.h = 0;
1518 _signal_anchor_geoms_do_things_with(wd, &ei);
1521 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1525 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1527 Widget_Data *wd = elm_widget_data_get(data);
1532 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1534 Widget_Data *wd = elm_widget_data_get(data);
1535 Elm_Entry_Anchor_Info ei;
1537 ei.name = emission + sizeof("nchor,mouse,in,");
1539 ei.x = ei.y = ei.w = ei.h = 0;
1541 _signal_anchor_geoms_do_things_with(wd, &ei);
1544 evas_object_smart_callback_call(data, SIG_ANCHOR_IN, &ei);
1548 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1550 Widget_Data *wd = elm_widget_data_get(data);
1551 Elm_Entry_Anchor_Info ei;
1553 ei.name = emission + sizeof("nchor,mouse,out,");
1555 ei.x = ei.y = ei.w = ei.h = 0;
1557 _signal_anchor_geoms_do_things_with(wd, &ei);
1560 evas_object_smart_callback_call(data, SIG_ANCHOR_OUT, &ei);
1564 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1566 Widget_Data *wd = elm_widget_data_get(data);
1568 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1572 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1574 Widget_Data *wd = elm_widget_data_get(data);
1576 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1580 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1582 Widget_Data *wd = elm_widget_data_get(data);
1584 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1588 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1590 Widget_Data *wd = elm_widget_data_get(data);
1592 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1596 _signal_mouse_triple(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1598 Widget_Data *wd = elm_widget_data_get(data);
1600 evas_object_smart_callback_call(data, SIG_CLICKED_TRIPLE, NULL);
1603 #ifdef HAVE_ELEMENTARY_X
1605 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1607 Widget_Data *wd = elm_widget_data_get(data);
1608 Ecore_X_Event_Selection_Notify *ev = event;
1609 if (!wd) return ECORE_CALLBACK_PASS_ON;
1610 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1611 return ECORE_CALLBACK_PASS_ON;
1613 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1614 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1616 Ecore_X_Selection_Data_Text *text_data;
1618 text_data = ev->data;
1619 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1621 if (text_data->text)
1623 char *txt = _elm_util_text_to_mkup(text_data->text);
1627 elm_entry_entry_insert(data, txt);
1632 wd->selection_asked = EINA_FALSE;
1634 else if (ev->selection == ECORE_X_SELECTION_XDND)
1636 Ecore_X_Selection_Data_Text *text_data;
1638 text_data = ev->data;
1639 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1641 if (text_data->text)
1643 char *txt = _elm_util_text_to_mkup(text_data->text);
1647 /* Massive FIXME: this should be at the drag point */
1648 elm_entry_entry_insert(data, txt);
1653 wd->drag_selection_asked = EINA_FALSE;
1655 ecore_x_dnd_send_finished();
1658 return ECORE_CALLBACK_PASS_ON;
1662 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1664 Widget_Data *wd = elm_widget_data_get(data);
1665 Ecore_X_Event_Selection_Clear *ev = event;
1666 if (!wd) return ECORE_CALLBACK_PASS_ON;
1667 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1668 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1669 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1671 elm_entry_select_none(data);
1673 return ECORE_CALLBACK_PASS_ON;
1677 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1682 wd = elm_widget_data_get(obj);
1683 if (!wd) return EINA_FALSE;
1684 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1686 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1687 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1688 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1689 EDJE_CURSOR_MAIN,drop->x,drop->y);
1690 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1691 elm_entry_entry_insert(obj, drop->data);
1692 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1693 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1699 static Evas_Object *
1700 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1702 Widget_Data *wd = elm_widget_data_get(data);
1705 Elm_Entry_Item_Provider *ip;
1707 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1709 o = ip->func(ip->data, data, item);
1712 if (!strncmp(item, "file://", 7))
1714 const char *fname = item + 7;
1716 o = evas_object_image_filled_add(evas_object_evas_get(data));
1717 evas_object_image_file_set(o, fname, NULL);
1718 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1720 evas_object_show(o);
1725 o = edje_object_add(evas_object_evas_get(data));
1726 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1730 o = edje_object_add(evas_object_evas_get(data));
1731 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1732 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1737 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1739 Widget_Data *wd = elm_widget_data_get(data);
1741 Elm_Entry_Text_Filter *tf;
1743 if (type == EDJE_TEXT_FILTER_FORMAT)
1746 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1748 tf->func(tf->data, data, text);
1754 /* This function is used to insert text by chunks in jobs */
1756 _text_append_idler(void *data)
1760 Evas_Object *obj = (Evas_Object *) data;
1761 Widget_Data *wd = elm_widget_data_get(obj);
1762 if (wd->text) eina_stringshare_del(wd->text);
1764 wd->changed = EINA_TRUE;
1766 start = wd->append_text_position;
1767 if(start + _CHUNK_SIZE < wd->append_text_len)
1769 wd->append_text_position = (start + _CHUNK_SIZE);
1770 /* Go to the start of the nearest codepoint, because we don't want
1771 * to cut it in the middle */
1772 eina_unicode_utf8_get_prev(wd->append_text_left,
1773 &wd->append_text_position);
1777 wd->append_text_position = wd->append_text_len;
1780 backup = wd->append_text_left[wd->append_text_position];
1781 wd->append_text_left[wd->append_text_position] = '\0';
1783 edje_object_part_text_append(wd->ent, "elm.text",
1784 wd->append_text_left + start);
1786 wd->append_text_left[wd->append_text_position] = backup;
1788 /* If there's still more to go, renew the idler, else, cleanup */
1789 if (wd->append_text_position < wd->append_text_len)
1791 return ECORE_CALLBACK_RENEW;
1795 free(wd->append_text_left);
1796 wd->append_text_left = NULL;
1797 wd->append_text_idler = NULL;
1798 return ECORE_CALLBACK_CANCEL;
1803 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
1805 int i = 0, unit_size;
1806 int current_len = strlen(*text);
1807 char *new_text = *text;
1808 if (unit >= LENGTH_UNIT_LAST) return;
1811 if (*new_text == '<')
1813 while (*new_text != '>')
1816 if (!*new_text) break;
1823 if (*new_text == '&')
1825 while (*(new_text + idx) != ';')
1828 if (!*(new_text + idx)) break;
1832 idx = evas_string_char_next_get(new_text, idx, NULL);
1833 markup = malloc(idx + 1);
1834 strncpy(markup, new_text, idx);
1836 if (unit == LENGTH_UNIT_BYTE)
1837 unit_size = strlen(elm_entry_markup_to_utf8(markup));
1838 else if (unit == LENGTH_UNIT_CHAR)
1839 unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
1845 if (can_add < unit_size)
1849 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1855 strncpy(new_text, new_text + idx, current_len - ((new_text + idx) - *text));
1857 (*text)[current_len] = 0;
1862 can_add -= unit_size;
1867 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1871 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
1874 ELM_CHECK_WIDTYPE(obj, widtype);
1875 if (item && strcmp(item, "default")) return;
1876 Widget_Data *wd = elm_widget_data_get(obj);
1878 if (!entry) entry = "";
1879 if (wd->text) eina_stringshare_del(wd->text);
1881 wd->changed = EINA_TRUE;
1883 /* Clear currently pending job if there is one */
1884 if (wd->append_text_idler)
1886 ecore_idler_del(wd->append_text_idler);
1887 free(wd->append_text_left);
1888 wd->append_text_left = NULL;
1889 wd->append_text_idler = NULL;
1892 len = strlen(entry);
1893 /* Split to ~_CHUNK_SIZE chunks */
1894 if (len > _CHUNK_SIZE)
1896 wd->append_text_left = (char *) malloc(len + 1);
1899 /* If we decided to use the idler */
1900 if (wd->append_text_left)
1902 /* Need to clear the entry first */
1903 edje_object_part_text_set(wd->ent, "elm.text", "");
1904 memcpy(wd->append_text_left, entry, len + 1);
1905 wd->append_text_position = 0;
1906 wd->append_text_len = len;
1907 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
1911 edje_object_part_text_set(wd->ent, "elm.text", entry);
1916 _elm_entry_text_get(const Evas_Object *obj, const char *item)
1918 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1919 Widget_Data *wd = elm_widget_data_get(obj);
1920 if (item && strcmp(item, "default")) return NULL;
1922 if (!wd) return NULL;
1923 if (wd->text) return wd->text;
1924 text = edje_object_part_text_get(wd->ent, "elm.text");
1927 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1931 if (wd->append_text_len > 0)
1935 tlen = strlen(text);
1936 tmpbuf = malloc(tlen + wd->append_text_len + 1);
1939 ERR("Failed to allocate memory for entry's text %p", obj);
1942 memcpy(tmpbuf, text, tlen);
1943 memcpy(tmpbuf + tlen, wd->append_text_left, wd->append_text_len);
1944 tmpbuf[tlen + wd->append_text_len] = '\0';
1945 eina_stringshare_replace(&wd->text, tmpbuf);
1950 eina_stringshare_replace(&wd->text, text);
1956 elm_entry_add(Evas_Object *parent)
1958 Evas_Object *obj, *top;
1962 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1964 ELM_SET_WIDTYPE(widtype, "entry");
1965 elm_widget_type_set(obj, "entry");
1966 elm_widget_sub_object_add(parent, obj);
1967 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1968 elm_widget_data_set(obj, wd);
1969 elm_widget_del_hook_set(obj, _del_hook);
1970 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1971 elm_widget_theme_hook_set(obj, _theme_hook);
1972 elm_widget_disable_hook_set(obj, _disable_hook);
1973 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1974 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
1975 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1976 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1977 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1978 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1979 elm_widget_can_focus_set(obj, EINA_TRUE);
1980 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1981 elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
1982 elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
1984 wd->scroller = elm_smart_scroller_add(e);
1985 elm_widget_sub_object_add(obj, wd->scroller);
1986 elm_smart_scroller_widget_set(wd->scroller, obj);
1987 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
1988 elm_widget_style_get(obj));
1989 evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1990 evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
1991 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
1992 evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
1993 evas_object_propagate_events_set(elm_smart_scroller_edje_object_get(
1994 wd->scroller), EINA_TRUE);
1996 wd->linewrap = ELM_WRAP_WORD;
1997 wd->editable = EINA_TRUE;
1998 wd->disabled = EINA_FALSE;
1999 wd->context_menu = EINA_TRUE;
2000 wd->autosave = EINA_TRUE;
2001 wd->textonly = EINA_FALSE;
2003 wd->ent = edje_object_add(e);
2004 elm_widget_sub_object_add(obj, wd->ent);
2005 edje_object_item_provider_set(wd->ent, _get_item, obj);
2006 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2007 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2008 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2010 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2012 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2014 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2016 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2017 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2018 _signal_entry_changed, obj);
2019 edje_object_signal_callback_add(wd->ent, "entry,changed,user", "elm.text",
2020 _signal_entry_changed_user, obj);
2021 edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2022 _signal_preedit_changed, obj);
2023 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2024 _signal_selection_start, obj);
2025 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2026 _signal_selection_changed, obj);
2027 edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
2028 _signal_selection_all, obj);
2029 edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
2030 _signal_selection_none, obj);
2031 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2032 _signal_selection_cleared, obj);
2033 edje_object_signal_callback_add(wd->ent, "entry,paste,request,*", "elm.text",
2034 _signal_entry_paste_request, obj);
2035 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2036 _signal_entry_copy_notify, obj);
2037 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2038 _signal_entry_cut_notify, obj);
2039 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2040 _signal_cursor_changed, obj);
2041 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2042 _signal_anchor_down, obj);
2043 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2044 _signal_anchor_up, obj);
2045 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2046 _signal_anchor_clicked, obj);
2047 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2048 _signal_anchor_move, obj);
2049 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2050 _signal_anchor_in, obj);
2051 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2052 _signal_anchor_out, obj);
2053 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2054 _signal_key_enter, obj);
2055 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2056 _signal_mouse_down, obj);
2057 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2058 _signal_mouse_clicked, obj);
2059 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2060 _signal_mouse_double, obj);
2061 edje_object_signal_callback_add(wd->ent, "mouse,down,1,triple", "elm.text",
2062 _signal_mouse_triple, obj);
2063 edje_object_part_text_set(wd->ent, "elm.text", "");
2064 if (_elm_config->desktop_entry)
2065 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2066 elm_widget_resize_object_set(obj, wd->ent);
2069 #ifdef HAVE_ELEMENTARY_X
2070 top = elm_widget_top_get(obj);
2071 if ((top) && (elm_win_xwindow_get(top)))
2073 wd->sel_notify_handler =
2074 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2075 _event_selection_notify, obj);
2076 wd->sel_clear_handler =
2077 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2078 _event_selection_clear, obj);
2081 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2082 _drag_drop_cb, NULL);
2085 entries = eina_list_prepend(entries, obj);
2087 // module - find module for entry
2088 wd->api = _module(obj);
2089 // if found - hook in
2090 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2092 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2093 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2094 // TODO: and save some bytes, making descriptions per-class and not instance!
2095 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2100 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2102 ELM_CHECK_WIDTYPE(obj, widtype);
2103 Widget_Data *wd = elm_widget_data_get(obj);
2105 if (wd->single_line == single_line) return;
2106 wd->single_line = single_line;
2107 wd->linewrap = ELM_WRAP_NONE;
2108 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2112 if (wd->single_line)
2113 elm_smart_scroller_policy_set(wd->scroller,
2114 ELM_SMART_SCROLLER_POLICY_OFF,
2115 ELM_SMART_SCROLLER_POLICY_OFF);
2118 const Elm_Scroller_Policy map[3] =
2120 ELM_SMART_SCROLLER_POLICY_AUTO,
2121 ELM_SMART_SCROLLER_POLICY_ON,
2122 ELM_SMART_SCROLLER_POLICY_OFF
2124 elm_smart_scroller_policy_set(wd->scroller,
2133 elm_entry_single_line_get(const Evas_Object *obj)
2135 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2136 Widget_Data *wd = elm_widget_data_get(obj);
2137 if (!wd) return EINA_FALSE;
2138 return wd->single_line;
2142 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2144 ELM_CHECK_WIDTYPE(obj, widtype);
2145 Widget_Data *wd = elm_widget_data_get(obj);
2147 if (wd->password == password) return;
2148 wd->password = password;
2149 wd->single_line = EINA_TRUE;
2150 wd->linewrap = ELM_WRAP_NONE;
2155 elm_entry_password_get(const Evas_Object *obj)
2157 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2158 Widget_Data *wd = elm_widget_data_get(obj);
2159 if (!wd) return EINA_FALSE;
2160 return wd->password;
2164 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2166 _elm_entry_text_set(obj, NULL, entry);
2170 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2173 ELM_CHECK_WIDTYPE(obj, widtype);
2174 Widget_Data *wd = elm_widget_data_get(obj);
2176 if (!entry) entry = "";
2177 wd->changed = EINA_TRUE;
2179 len = strlen(entry);
2180 if (wd->append_text_left)
2183 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
2189 wd->append_text_left = tmpbuf;
2190 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
2191 wd->append_text_len += len;
2195 /* FIXME: Add chunked appending here (like in entry_set) */
2196 edje_object_part_text_append(wd->ent, "elm.text", entry);
2201 elm_entry_entry_get(const Evas_Object *obj)
2203 return _elm_entry_text_get(obj, NULL);
2207 elm_entry_is_empty(const Evas_Object *obj)
2209 /* FIXME: until there's support for that in textblock, we just check
2210 * to see if the there is text or not. */
2211 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2212 Widget_Data *wd = elm_widget_data_get(obj);
2213 const Evas_Object *tb;
2214 Evas_Textblock_Cursor *cur;
2216 if (!wd) return EINA_TRUE;
2217 /* It's a hack until we get the support suggested above.
2218 * We just create a cursor, point it to the begining, and then
2219 * try to advance it, if it can advance, the tb is not empty,
2220 * otherwise it is. */
2221 tb = edje_object_part_object_get(wd->ent, "elm.text");
2222 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2223 actually, ok for the time being, thsese hackish stuff will be removed
2224 once evas 1.0 is out*/
2225 evas_textblock_cursor_pos_set(cur, 0);
2226 ret = evas_textblock_cursor_char_next(cur);
2227 evas_textblock_cursor_free(cur);
2233 elm_entry_selection_get(const Evas_Object *obj)
2235 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2236 Widget_Data *wd = elm_widget_data_get(obj);
2237 if (!wd) return NULL;
2238 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2242 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2244 ELM_CHECK_WIDTYPE(obj, widtype);
2245 Widget_Data *wd = elm_widget_data_get(obj);
2247 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2248 wd->changed = EINA_TRUE;
2253 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2255 ELM_CHECK_WIDTYPE(obj, widtype);
2256 Widget_Data *wd = elm_widget_data_get(obj);
2258 if (wd->linewrap == wrap) return;
2260 wd->linewrap = wrap;
2265 elm_entry_line_wrap_get(const Evas_Object *obj)
2267 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2268 Widget_Data *wd = elm_widget_data_get(obj);
2269 if (!wd) return EINA_FALSE;
2270 return wd->linewrap;
2274 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2276 ELM_CHECK_WIDTYPE(obj, widtype);
2277 Widget_Data *wd = elm_widget_data_get(obj);
2279 if (wd->editable == editable) return;
2280 wd->editable = editable;
2283 #ifdef HAVE_ELEMENTARY_X
2285 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2287 elm_drop_target_del(obj);
2292 elm_entry_editable_get(const Evas_Object *obj)
2294 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2295 Widget_Data *wd = elm_widget_data_get(obj);
2296 if (!wd) return EINA_FALSE;
2297 return wd->editable;
2301 elm_entry_select_none(Evas_Object *obj)
2303 ELM_CHECK_WIDTYPE(obj, widtype);
2304 Widget_Data *wd = elm_widget_data_get(obj);
2308 wd->selmode = EINA_FALSE;
2309 if (!_elm_config->desktop_entry)
2310 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2311 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2313 wd->have_selection = EINA_FALSE;
2314 edje_object_part_text_select_none(wd->ent, "elm.text");
2318 elm_entry_select_all(Evas_Object *obj)
2320 ELM_CHECK_WIDTYPE(obj, widtype);
2321 Widget_Data *wd = elm_widget_data_get(obj);
2325 wd->selmode = EINA_FALSE;
2326 if (!_elm_config->desktop_entry)
2327 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2328 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2330 wd->have_selection = EINA_TRUE;
2331 edje_object_part_text_select_all(wd->ent, "elm.text");
2335 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2337 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2338 Widget_Data *wd = elm_widget_data_get(obj);
2339 if (!wd) return EINA_FALSE;
2340 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2345 elm_entry_cursor_next(Evas_Object *obj)
2347 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2348 Widget_Data *wd = elm_widget_data_get(obj);
2349 if (!wd) return EINA_FALSE;
2350 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2354 elm_entry_cursor_prev(Evas_Object *obj)
2356 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2357 Widget_Data *wd = elm_widget_data_get(obj);
2358 if (!wd) return EINA_FALSE;
2359 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2363 elm_entry_cursor_up(Evas_Object *obj)
2365 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2366 Widget_Data *wd = elm_widget_data_get(obj);
2367 if (!wd) return EINA_FALSE;
2368 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2372 elm_entry_cursor_down(Evas_Object *obj)
2374 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2375 Widget_Data *wd = elm_widget_data_get(obj);
2376 if (!wd) return EINA_FALSE;
2377 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2381 elm_entry_cursor_begin_set(Evas_Object *obj)
2383 ELM_CHECK_WIDTYPE(obj, widtype);
2384 Widget_Data *wd = elm_widget_data_get(obj);
2386 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2390 elm_entry_cursor_end_set(Evas_Object *obj)
2392 ELM_CHECK_WIDTYPE(obj, widtype);
2393 Widget_Data *wd = elm_widget_data_get(obj);
2397 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2400 elm_widget_show_region_get(obj, &x, &y, &w, &h);
2401 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
2406 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2408 ELM_CHECK_WIDTYPE(obj, widtype);
2409 Widget_Data *wd = elm_widget_data_get(obj);
2411 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2415 elm_entry_cursor_line_end_set(Evas_Object *obj)
2417 ELM_CHECK_WIDTYPE(obj, widtype);
2418 Widget_Data *wd = elm_widget_data_get(obj);
2420 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2424 elm_entry_cursor_selection_begin(Evas_Object *obj)
2426 ELM_CHECK_WIDTYPE(obj, widtype);
2427 Widget_Data *wd = elm_widget_data_get(obj);
2429 edje_object_part_text_select_begin(wd->ent, "elm.text");
2433 elm_entry_cursor_selection_end(Evas_Object *obj)
2435 ELM_CHECK_WIDTYPE(obj, widtype);
2436 Widget_Data *wd = elm_widget_data_get(obj);
2438 edje_object_part_text_select_extend(wd->ent, "elm.text");
2442 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2444 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2445 Widget_Data *wd = elm_widget_data_get(obj);
2446 if (!wd) return EINA_FALSE;
2447 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2451 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2453 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2454 Widget_Data *wd = elm_widget_data_get(obj);
2455 if (!wd) return EINA_FALSE;
2456 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2460 elm_entry_cursor_content_get(const Evas_Object *obj)
2462 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2463 Widget_Data *wd = elm_widget_data_get(obj);
2464 if (!wd) return NULL;
2465 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2469 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2471 ELM_CHECK_WIDTYPE(obj, widtype);
2472 Widget_Data *wd = elm_widget_data_get(obj);
2474 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2475 edje_object_message_signal_process(wd->ent);
2479 elm_entry_cursor_pos_get(const Evas_Object *obj)
2481 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2482 Widget_Data *wd = elm_widget_data_get(obj);
2484 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2488 elm_entry_selection_cut(Evas_Object *obj)
2490 ELM_CHECK_WIDTYPE(obj, widtype);
2491 Widget_Data *wd = elm_widget_data_get(obj);
2493 _cut(obj, NULL, NULL);
2497 elm_entry_selection_copy(Evas_Object *obj)
2499 ELM_CHECK_WIDTYPE(obj, widtype);
2500 Widget_Data *wd = elm_widget_data_get(obj);
2502 _copy(obj, NULL, NULL);
2506 elm_entry_selection_paste(Evas_Object *obj)
2508 ELM_CHECK_WIDTYPE(obj, widtype);
2509 Widget_Data *wd = elm_widget_data_get(obj);
2511 _paste(obj, NULL, NULL);
2515 elm_entry_context_menu_clear(Evas_Object *obj)
2517 ELM_CHECK_WIDTYPE(obj, widtype);
2518 Widget_Data *wd = elm_widget_data_get(obj);
2519 Elm_Entry_Context_Menu_Item *it;
2521 EINA_LIST_FREE(wd->items, it)
2523 eina_stringshare_del(it->label);
2524 eina_stringshare_del(it->icon_file);
2525 eina_stringshare_del(it->icon_group);
2531 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)
2533 ELM_CHECK_WIDTYPE(obj, widtype);
2534 Widget_Data *wd = elm_widget_data_get(obj);
2535 Elm_Entry_Context_Menu_Item *it;
2537 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2539 wd->items = eina_list_append(wd->items, it);
2541 it->label = eina_stringshare_add(label);
2542 it->icon_file = eina_stringshare_add(icon_file);
2543 it->icon_type = icon_type;
2545 it->data = (void *)data;
2549 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2551 ELM_CHECK_WIDTYPE(obj, widtype);
2552 Widget_Data *wd = elm_widget_data_get(obj);
2554 if (wd->context_menu == !disabled) return;
2555 wd->context_menu = !disabled;
2559 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2561 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2562 Widget_Data *wd = elm_widget_data_get(obj);
2563 if (!wd) return EINA_FALSE;
2564 return !wd->context_menu;
2568 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2570 ELM_CHECK_WIDTYPE(obj, widtype);
2571 Widget_Data *wd = elm_widget_data_get(obj);
2573 EINA_SAFETY_ON_NULL_RETURN(func);
2574 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2578 wd->item_providers = eina_list_append(wd->item_providers, ip);
2582 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2584 ELM_CHECK_WIDTYPE(obj, widtype);
2585 Widget_Data *wd = elm_widget_data_get(obj);
2587 EINA_SAFETY_ON_NULL_RETURN(func);
2588 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2592 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2596 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2598 ELM_CHECK_WIDTYPE(obj, widtype);
2599 Widget_Data *wd = elm_widget_data_get(obj);
2601 Elm_Entry_Item_Provider *ip;
2603 EINA_SAFETY_ON_NULL_RETURN(func);
2604 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2606 if ((ip->func == func) && ((!data) || (ip->data == data)))
2608 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2616 elm_entry_text_filter_append(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2619 Elm_Entry_Text_Filter *tf;
2620 ELM_CHECK_WIDTYPE(obj, widtype);
2622 wd = elm_widget_data_get(obj);
2624 EINA_SAFETY_ON_NULL_RETURN(func);
2626 tf = _filter_new(func, data);
2629 wd->text_filters = eina_list_append(wd->text_filters, tf);
2633 elm_entry_text_filter_prepend(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2636 Elm_Entry_Text_Filter *tf;
2637 ELM_CHECK_WIDTYPE(obj, widtype);
2639 wd = elm_widget_data_get(obj);
2641 EINA_SAFETY_ON_NULL_RETURN(func);
2643 tf = _filter_new(func, data);
2646 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2650 elm_entry_text_filter_remove(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2654 Elm_Entry_Text_Filter *tf;
2655 ELM_CHECK_WIDTYPE(obj, widtype);
2657 wd = elm_widget_data_get(obj);
2659 EINA_SAFETY_ON_NULL_RETURN(func);
2661 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2663 if ((tf->func == func) && ((!data) || (tf->data == data)))
2665 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2673 elm_entry_markup_to_utf8(const char *s)
2675 char *ss = _elm_util_mkup_to_text(s);
2676 if (!ss) ss = strdup("");
2681 elm_entry_utf8_to_markup(const char *s)
2683 char *ss = _elm_util_text_to_mkup(s);
2684 if (!ss) ss = strdup("");
2689 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2691 Elm_Entry_Filter_Limit_Size *lim = data;
2694 const char *(*text_get)(const Evas_Object *);
2695 const char *widget_type;
2697 EINA_SAFETY_ON_NULL_RETURN(data);
2698 EINA_SAFETY_ON_NULL_RETURN(entry);
2699 EINA_SAFETY_ON_NULL_RETURN(text);
2701 /* hack. I don't want to copy the entire function to work with
2703 widget_type = elm_widget_type_get(entry);
2704 if (!strcmp(widget_type, "entry"))
2705 text_get = elm_entry_entry_get;
2709 current = elm_entry_markup_to_utf8(text_get(entry));
2711 if (lim->max_char_count > 0)
2713 len = evas_string_char_len_get(current);
2714 if (len >= lim->max_char_count)
2716 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2722 newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
2723 if ((len + newlen) > lim->max_char_count)
2724 _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
2726 else if (lim->max_byte_count > 0)
2728 len = strlen(current);
2729 if (len >= lim->max_byte_count)
2731 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2737 newlen = strlen(elm_entry_markup_to_utf8(*text));
2738 if ((len + newlen) > lim->max_byte_count)
2739 _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
2745 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2747 Elm_Entry_Filter_Accept_Set *as = data;
2751 int read_idx, last_read_idx = 0, read_char;
2753 EINA_SAFETY_ON_NULL_RETURN(data);
2754 EINA_SAFETY_ON_NULL_RETURN(text);
2756 if ((!as->accepted) && (!as->rejected))
2762 goes_in = EINA_TRUE;
2767 goes_in = EINA_FALSE;
2771 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2774 int cmp_idx, cmp_char;
2775 Eina_Bool in_set = EINA_FALSE;
2777 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2780 if (read_char == cmp_char)
2785 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2787 if (in_set == goes_in)
2789 int size = read_idx - last_read_idx;
2790 const char *src = (*text) + last_read_idx;
2792 memcpy(insert, *text + last_read_idx, size);
2795 last_read_idx = read_idx;
2796 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2802 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2804 ELM_CHECK_WIDTYPE(obj, widtype);
2805 Widget_Data *wd = elm_widget_data_get(obj);
2807 if (wd->delay_write)
2809 ecore_timer_del(wd->delay_write);
2810 wd->delay_write = NULL;
2812 if (wd->autosave) _save(obj);
2813 eina_stringshare_replace(&wd->file, file);
2814 wd->format = format;
2819 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2821 ELM_CHECK_WIDTYPE(obj, widtype);
2822 Widget_Data *wd = elm_widget_data_get(obj);
2824 if (file) *file = wd->file;
2825 if (format) *format = wd->format;
2829 elm_entry_file_save(Evas_Object *obj)
2831 ELM_CHECK_WIDTYPE(obj, widtype);
2832 Widget_Data *wd = elm_widget_data_get(obj);
2834 if (wd->delay_write)
2836 ecore_timer_del(wd->delay_write);
2837 wd->delay_write = NULL;
2840 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2844 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2846 ELM_CHECK_WIDTYPE(obj, widtype);
2847 Widget_Data *wd = elm_widget_data_get(obj);
2849 wd->autosave = !!autosave;
2853 elm_entry_autosave_get(const Evas_Object *obj)
2855 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2856 Widget_Data *wd = elm_widget_data_get(obj);
2857 if (!wd) return EINA_FALSE;
2858 return wd->autosave;
2862 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2864 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2865 ELM_CHECK_WIDTYPE(obj, widtype);
2866 Widget_Data *wd = elm_widget_data_get(obj);
2868 textonly = !!textonly;
2869 if (wd->textonly == textonly) return;
2870 wd->textonly = !!textonly;
2871 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2872 #ifdef HAVE_ELEMENTARY_X
2873 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2878 elm_entry_cnp_textonly_get(const Evas_Object *obj)
2880 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2881 Widget_Data *wd = elm_widget_data_get(obj);
2882 if (!wd) return EINA_FALSE;
2883 return wd->textonly;
2887 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
2889 ELM_CHECK_WIDTYPE(obj, widtype);
2890 Widget_Data *wd = elm_widget_data_get(obj);
2893 if (wd->scroll == scroll) return;
2894 wd->scroll = scroll;
2897 elm_widget_sub_object_del(obj, wd->scroller);
2898 elm_widget_resize_object_set(obj, wd->scroller);
2899 elm_widget_sub_object_add(obj, wd->ent);
2900 elm_smart_scroller_child_set(wd->scroller, wd->ent);
2901 evas_object_show(wd->scroller);
2902 elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
2906 elm_smart_scroller_child_set(wd->scroller, NULL);
2907 elm_widget_sub_object_del(obj, wd->ent);
2908 elm_widget_resize_object_set(obj, wd->ent);
2909 evas_object_smart_member_add(wd->scroller, obj);
2910 elm_widget_sub_object_add(obj, wd->scroller);
2911 evas_object_hide(wd->scroller);
2912 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
2919 elm_entry_scrollable_get(const Evas_Object *obj)
2921 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2922 Widget_Data *wd = elm_widget_data_get(obj);
2923 if (!wd) return EINA_FALSE;
2928 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
2930 ELM_CHECK_WIDTYPE(obj, widtype);
2931 Widget_Data *wd = elm_widget_data_get(obj);
2934 EINA_SAFETY_ON_NULL_RETURN(icon);
2935 if (wd->icon == icon) return;
2936 if (wd->icon) evas_object_del(wd->icon);
2938 edje = elm_smart_scroller_edje_object_get(wd->scroller);
2940 edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
2941 edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
2946 elm_entry_icon_get(const Evas_Object *obj)
2948 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2949 Widget_Data *wd = elm_widget_data_get(obj);
2950 if (!wd) return NULL;
2955 elm_entry_icon_unset(Evas_Object *obj)
2957 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2958 Widget_Data *wd = elm_widget_data_get(obj);
2959 Evas_Object *ret = NULL;
2960 if (!wd) return NULL;
2963 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
2964 if (!edje) return NULL;
2966 edje_object_part_unswallow(edje, wd->icon);
2967 edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
2975 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
2977 ELM_CHECK_WIDTYPE(obj, widtype);
2978 Widget_Data *wd = elm_widget_data_get(obj);
2979 if ((!wd) || (!wd->icon)) return;
2981 evas_object_hide(wd->icon);
2983 evas_object_show(wd->icon);
2988 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
2990 ELM_CHECK_WIDTYPE(obj, widtype);
2991 Widget_Data *wd = elm_widget_data_get(obj);
2994 EINA_SAFETY_ON_NULL_RETURN(end);
2995 if (wd->end == end) return;
2996 if (wd->end) evas_object_del(wd->end);
2998 edje = elm_smart_scroller_edje_object_get(wd->scroller);
3000 edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
3001 edje_object_signal_emit(edje, "elm,action,show,end", "elm");
3006 elm_entry_end_get(const Evas_Object *obj)
3008 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3009 Widget_Data *wd = elm_widget_data_get(obj);
3010 if (!wd) return NULL;
3015 elm_entry_end_unset(Evas_Object *obj)
3017 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3018 Widget_Data *wd = elm_widget_data_get(obj);
3019 Evas_Object *ret = NULL;
3020 if (!wd) return NULL;
3023 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
3024 if (!edje) return NULL;
3026 edje_object_part_unswallow(edje, wd->end);
3027 edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
3035 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
3037 ELM_CHECK_WIDTYPE(obj, widtype);
3038 Widget_Data *wd = elm_widget_data_get(obj);
3039 if ((!wd) || (!wd->end)) return;
3041 evas_object_hide(wd->end);
3043 evas_object_show(wd->end);
3048 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
3050 ELM_CHECK_WIDTYPE(obj, widtype);
3051 Widget_Data *wd = elm_widget_data_get(obj);
3052 const Elm_Scroller_Policy map[3] =
3054 ELM_SMART_SCROLLER_POLICY_AUTO,
3055 ELM_SMART_SCROLLER_POLICY_ON,
3056 ELM_SMART_SCROLLER_POLICY_OFF
3061 elm_smart_scroller_policy_set(wd->scroller,
3067 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3069 ELM_CHECK_WIDTYPE(obj, widtype);
3070 Widget_Data *wd = elm_widget_data_get(obj);
3072 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
3076 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3078 ELM_CHECK_WIDTYPE(obj, widtype);
3079 Widget_Data *wd = elm_widget_data_get(obj);
3081 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);