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_ACTIVATED[] = "activated";
122 static const char SIG_PRESS[] = "press";
123 static const char SIG_LONGPRESSED[] = "longpressed";
124 static const char SIG_CLICKED[] = "clicked";
125 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
126 static const char SIG_FOCUSED[] = "focused";
127 static const char SIG_UNFOCUSED[] = "unfocused";
128 static const char SIG_SELECTION_PASTE[] = "selection,paste";
129 static const char SIG_SELECTION_COPY[] = "selection,copy";
130 static const char SIG_SELECTION_CUT[] = "selection,cut";
131 static const char SIG_SELECTION_START[] = "selection,start";
132 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
133 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
134 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
135 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
136 static const char SIG_ANCHOR_DOWN[] = "anchor,down";
137 static const char SIG_ANCHOR_UP[] = "anchor,up";
138 static const char SIG_ANCHOR_IN[] = "anchor,in";
139 static const char SIG_ANCHOR_OUT[] = "anchor,out";
140 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
141 static const Evas_Smart_Cb_Description _signals[] = {
145 {SIG_LONGPRESSED, ""},
147 {SIG_CLICKED_DOUBLE, ""},
150 {SIG_SELECTION_PASTE, ""},
151 {SIG_SELECTION_COPY, ""},
152 {SIG_SELECTION_CUT, ""},
153 {SIG_SELECTION_START, ""},
154 {SIG_SELECTION_CHANGED, ""},
155 {SIG_SELECTION_CLEARED, ""},
156 {SIG_CURSOR_CHANGED, ""},
157 {SIG_ANCHOR_CLICKED, ""},
158 {SIG_ANCHOR_DOWN, ""},
161 {SIG_ANCHOR_OUT, ""},
162 {SIG_PREEDIT_CHANGED, ""},
166 static Eina_List *entries = NULL;
170 void (*obj_hook) (Evas_Object *obj);
171 void (*obj_unhook) (Evas_Object *obj);
172 void (*obj_longpress) (Evas_Object *obj);
176 _module(Evas_Object *obj __UNUSED__)
178 static Elm_Module *m = NULL;
179 if (m) goto ok; // already found - just use
180 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
182 m->api = malloc(sizeof(Mod_Api));
183 if (!m->api) return NULL;
184 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
185 _elm_module_symbol_get(m, "obj_hook");
186 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
187 _elm_module_symbol_get(m, "obj_unhook");
188 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
189 _elm_module_symbol_get(m, "obj_longpress");
190 ok: // ok - return api
195 _buf_append(char *buf, const char *str, int *len, int *alloc)
197 int len2 = strlen(str);
198 if ((*len + len2) >= *alloc)
200 char *buf2 = realloc(buf, *alloc + len2 + 512);
201 if (!buf2) return NULL;
203 *alloc += (512 + len2);
205 strcpy(buf + *len, str);
211 _load_file(const char *file)
215 int alloc = 0, len = 0;
216 char *text = NULL, buf[16384 + 1];
218 f = fopen(file, "rb");
220 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
224 tmp_text = _buf_append(text, buf, &len, &alloc);
225 if (!tmp_text) break;
233 _load_plain(const char *file)
237 text = _load_file(file);
242 text2 = elm_entry_utf8_to_markup(text);
250 _load(Evas_Object *obj)
252 Widget_Data *wd = elm_widget_data_get(obj);
257 elm_entry_entry_set(obj, "");
262 case ELM_TEXT_FORMAT_PLAIN_UTF8:
263 text = _load_plain(wd->file);
265 case ELM_TEXT_FORMAT_MARKUP_UTF8:
266 text = _load_file(wd->file);
274 elm_entry_entry_set(obj, text);
278 elm_entry_entry_set(obj, "");
282 _save_markup_utf8(const char *file, const char *text)
286 if ((!text) || (!text[0]))
288 ecore_file_unlink(file);
291 f = fopen(file, "wb");
294 // FIXME: report a write error
297 fputs(text, f); // FIXME: catch error
302 _save_plain_utf8(const char *file, const char *text)
306 text2 = elm_entry_markup_to_utf8(text);
309 _save_markup_utf8(file, text2);
314 _save(Evas_Object *obj)
316 Widget_Data *wd = elm_widget_data_get(obj);
318 if (!wd->file) return;
321 case ELM_TEXT_FORMAT_PLAIN_UTF8:
322 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
324 case ELM_TEXT_FORMAT_MARKUP_UTF8:
325 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
333 _delay_write(void *data)
335 Widget_Data *wd = elm_widget_data_get(data);
336 if (!wd) return ECORE_CALLBACK_CANCEL;
338 wd->delay_write = NULL;
339 return ECORE_CALLBACK_CANCEL;
342 static Elm_Entry_Text_Filter *
343 _filter_new(Elm_Entry_Filter_Cb func, void *data)
345 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
346 if (!tf) return NULL;
349 if (func == elm_entry_filter_limit_size)
351 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
358 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
364 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
367 else if (func == elm_entry_filter_accept_set)
369 Elm_Entry_Filter_Accept_Set *as = data, *as2;
376 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
383 as2->accepted = eina_stringshare_add(as->accepted);
385 as2->accepted = NULL;
387 as2->rejected = eina_stringshare_add(as->rejected);
389 as2->rejected = NULL;
398 _filter_free(Elm_Entry_Text_Filter *tf)
400 if (tf->func == elm_entry_filter_limit_size)
402 Elm_Entry_Filter_Limit_Size *lim = tf->data;
405 else if (tf->func == elm_entry_filter_accept_set)
407 Elm_Entry_Filter_Accept_Set *as = tf->data;
410 if (as->accepted) eina_stringshare_del(as->accepted);
411 if (as->rejected) eina_stringshare_del(as->rejected);
419 _del_pre_hook(Evas_Object *obj)
421 Widget_Data *wd = elm_widget_data_get(obj);
425 ecore_timer_del(wd->delay_write);
426 wd->delay_write = NULL;
427 if (wd->autosave) _save(obj);
432 _del_hook(Evas_Object *obj)
434 Widget_Data *wd = elm_widget_data_get(obj);
435 Elm_Entry_Context_Menu_Item *it;
436 Elm_Entry_Item_Provider *ip;
437 Elm_Entry_Text_Filter *tf;
439 if (wd->file) eina_stringshare_del(wd->file);
441 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
442 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
444 entries = eina_list_remove(entries, obj);
445 #ifdef HAVE_ELEMENTARY_X
446 if (wd->sel_notify_handler)
447 ecore_event_handler_del(wd->sel_notify_handler);
448 if (wd->sel_clear_handler)
449 ecore_event_handler_del(wd->sel_clear_handler);
451 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
452 if (wd->text) eina_stringshare_del(wd->text);
453 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
454 if (wd->append_text_idler)
456 ecore_idler_del(wd->append_text_idler);
457 free(wd->append_text_left);
458 wd->append_text_left = NULL;
459 wd->append_text_idler = NULL;
461 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
462 EINA_LIST_FREE(wd->items, it)
464 eina_stringshare_del(it->label);
465 eina_stringshare_del(it->icon_file);
466 eina_stringshare_del(it->icon_group);
469 EINA_LIST_FREE(wd->item_providers, ip)
473 EINA_LIST_FREE(wd->text_filters, tf)
481 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
483 Widget_Data *wd = elm_widget_data_get(obj);
484 edje_object_mirrored_set(wd->ent, rtl);
488 _theme_hook(Evas_Object *obj)
490 Widget_Data *wd = elm_widget_data_get(obj);
492 _elm_widget_mirrored_reload(obj);
493 _mirrored_set(obj, elm_widget_mirrored_get(obj));
495 t = eina_stringshare_add(elm_entry_entry_get(obj));
496 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
497 if (_elm_config->desktop_entry)
498 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
499 elm_entry_entry_set(obj, t);
500 eina_stringshare_del(t);
501 if (elm_widget_disabled_get(obj))
502 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
503 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
504 if (elm_widget_focus_get(obj))
505 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
506 edje_object_message_signal_process(wd->ent);
507 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
508 elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
509 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
510 elm_widget_style_get(obj));
516 edj = elm_smart_scroller_edje_object_get(wd->scroller);
517 str = edje_object_data_get(edj, "focus_highlight");
518 if ((str) && (!strcmp(str, "on")))
519 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
521 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
527 _disable_hook(Evas_Object *obj)
529 Widget_Data *wd = elm_widget_data_get(obj);
531 if (elm_widget_disabled_get(obj))
533 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
534 wd->disabled = EINA_TRUE;
538 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
539 wd->disabled = EINA_FALSE;
544 _recalc_cursor_geometry(Evas_Object *obj)
546 Widget_Data *wd = elm_widget_data_get(obj);
548 evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
549 if (!wd->deferred_recalc_job)
551 Evas_Coord cx, cy, cw, ch;
552 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
556 elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
557 wd->cur_changed = EINA_FALSE;
561 wd->deferred_cur = EINA_TRUE;
565 _elm_win_recalc_job(void *data)
567 Widget_Data *wd = elm_widget_data_get(data);
568 Evas_Coord minh = -1, resw = -1, minw = -1, fw = 0, fh = 0;
570 wd->deferred_recalc_job = NULL;
572 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
573 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
574 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
577 /* This is a hack to workaround the way min size hints are treated.
578 * If the minimum width is smaller than the restricted width, it means
579 * the mininmum doesn't matter. */
582 Evas_Coord ominw = -1;
583 evas_object_size_hint_min_get(data, &ominw, NULL);
587 elm_coords_finger_size_adjust(1, &fw, 1, &fh);
590 Evas_Coord vmw = 0, vmh = 0;
592 edje_object_size_min_calc
593 (elm_smart_scroller_edje_object_get(wd->scroller),
597 evas_object_size_hint_min_set(data, vmw, minh + vmh);
598 evas_object_size_hint_max_set(data, -1, minh + vmh);
602 evas_object_size_hint_min_set(data, vmw, vmh);
603 evas_object_size_hint_max_set(data, -1, -1);
610 evas_object_size_hint_min_set(data, minw, minh);
611 evas_object_size_hint_max_set(data, -1, minh);
615 evas_object_size_hint_min_set(data, fw, minh);
616 evas_object_size_hint_max_set(data, -1, -1);
620 if (wd->deferred_cur)
622 Evas_Coord cx, cy, cw, ch;
623 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
627 elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
628 wd->cur_changed = EINA_FALSE;
634 _sizing_eval(Evas_Object *obj)
636 Widget_Data *wd = elm_widget_data_get(obj);
637 Evas_Coord minw = -1, minh = -1;
638 Evas_Coord resw, resh;
641 evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
644 if ((resw == wd->lastw) && (!wd->changed)) return;
645 wd->changed = EINA_FALSE;
649 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
651 evas_object_resize(wd->scroller, resw, resh);
652 edje_object_size_min_calc
653 (elm_smart_scroller_edje_object_get(wd->scroller),
655 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
656 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
659 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
661 if ((minw > 0) && (vw < minw)) vw = minw;
662 if (minh > vh) vh = minh;
664 if (wd->single_line) h = vmh + minh;
666 evas_object_resize(wd->ent, vw, vh);
667 evas_object_size_hint_min_set(obj, w, h);
669 evas_object_size_hint_max_set(obj, -1, h);
671 evas_object_size_hint_max_set(obj, -1, -1);
675 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
676 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
681 if (!wd->changed) return;
682 wd->changed = EINA_FALSE;
686 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
688 edje_object_size_min_calc(wd->ent, &minw, &minh);
691 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
693 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
695 if ((minw > 0) && (vw < minw)) vw = minw;
696 if (minh > 0) vh = minh;
698 evas_object_resize(wd->ent, vw, vh);
699 edje_object_size_min_calc
700 (elm_smart_scroller_edje_object_get(wd->scroller),
702 if (wd->single_line) h = vmh + minh;
704 evas_object_size_hint_min_set(obj, w, h);
706 evas_object_size_hint_max_set(obj, -1, h);
708 evas_object_size_hint_max_set(obj, -1, -1);
712 edje_object_size_min_calc(wd->ent, &minw, &minh);
715 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
716 evas_object_size_hint_min_set(obj, minw, minh);
718 evas_object_size_hint_max_set(obj, -1, minh);
720 evas_object_size_hint_max_set(obj, -1, -1);
724 _recalc_cursor_geometry(obj);
728 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
730 Widget_Data *wd = elm_widget_data_get(obj);
731 Evas_Object *top = elm_widget_top_get(obj);
733 if (!wd->editable) return;
734 if (elm_widget_focus_get(obj))
736 evas_object_focus_set(wd->ent, EINA_TRUE);
737 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
738 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
739 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
743 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
744 evas_object_focus_set(wd->ent, EINA_FALSE);
745 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
746 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
751 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
753 Widget_Data *wd = elm_widget_data_get(obj);
755 edje_object_signal_emit(wd->ent, emission, source);
757 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
762 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
764 Widget_Data *wd = elm_widget_data_get(obj);
766 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
768 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
769 emission, source, func_cb, data);
773 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
775 Widget_Data *wd = elm_widget_data_get(obj);
776 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
779 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
780 emission, source, func_cb, data);
784 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
786 Widget_Data *wd = elm_widget_data_get(obj);
787 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
791 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
793 Widget_Data *wd = elm_widget_data_get(obj);
795 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
799 _show_region_hook(void *data, Evas_Object *obj)
801 Widget_Data *wd = elm_widget_data_get(data);
802 Evas_Coord x, y, w, h;
804 elm_widget_show_region_get(obj, &x, &y, &w, &h);
806 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
810 _hoversel_position(Evas_Object *obj)
812 Widget_Data *wd = elm_widget_data_get(obj);
813 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
818 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
827 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
829 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
840 evas_object_move(wd->hoversel, x + cx, y + cy);
841 evas_object_resize(wd->hoversel, cw, ch);
845 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
847 Widget_Data *wd = elm_widget_data_get(data);
849 if (wd->hoversel) _hoversel_position(data);
853 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
855 Widget_Data *wd = elm_widget_data_get(data);
864 Evas_Coord vw = 0, vh = 0;
866 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
867 if (vw < wd->entmw) vw = wd->entmw;
868 if (vh < wd->entmh) vh = wd->entmh;
869 evas_object_resize(wd->ent, vw, vh);
871 if (wd->hoversel) _hoversel_position(data);
875 _hover_del(void *data)
877 Widget_Data *wd = elm_widget_data_get(data);
882 evas_object_del(wd->hoversel);
885 wd->hovdeljob = NULL;
889 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
891 Widget_Data *wd = elm_widget_data_get(data);
894 if (wd->hoversel) evas_object_hide(wd->hoversel);
897 if (!_elm_config->desktop_entry)
900 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
903 elm_widget_scroll_freeze_pop(data);
904 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
905 wd->hovdeljob = ecore_job_add(_hover_del, data);
909 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
911 Widget_Data *wd = elm_widget_data_get(data);
913 wd->selmode = EINA_TRUE;
914 edje_object_part_text_select_none(wd->ent, "elm.text");
915 if (!_elm_config->desktop_entry)
918 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
920 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
921 if (!_elm_config->desktop_entry)
922 elm_widget_scroll_hold_push(data);
926 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
928 Widget_Data *wd = elm_widget_data_get(data);
930 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
931 if (wd->sel_notify_handler)
933 #ifdef HAVE_ELEMENTARY_X
934 Elm_Sel_Format formats;
935 wd->selection_asked = EINA_TRUE;
936 formats = ELM_SEL_FORMAT_MARKUP;
938 formats |= ELM_SEL_FORMAT_IMAGE;
939 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
945 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
947 Widget_Data *wd = elm_widget_data_get(obj);
951 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
952 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
953 if (seltype == ELM_SEL_CLIPBOARD)
954 eina_stringshare_replace(&wd->cut_sel, sel);
958 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
960 Widget_Data *wd = elm_widget_data_get(data);
963 wd->selmode = EINA_FALSE;
964 if (!_elm_config->desktop_entry)
965 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
966 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
967 if (!_elm_config->desktop_entry)
968 elm_widget_scroll_hold_pop(data);
969 _store_selection(ELM_SEL_CLIPBOARD, data);
970 edje_object_part_text_insert(wd->ent, "elm.text", "");
971 edje_object_part_text_select_none(wd->ent, "elm.text");
975 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
977 Widget_Data *wd = elm_widget_data_get(data);
979 wd->selmode = EINA_FALSE;
980 if (!_elm_config->desktop_entry)
982 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
983 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
984 elm_widget_scroll_hold_pop(data);
986 _store_selection(ELM_SEL_CLIPBOARD, data);
987 // edje_object_part_text_select_none(wd->ent, "elm.text");
991 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
993 Widget_Data *wd = elm_widget_data_get(data);
995 wd->selmode = EINA_FALSE;
996 if (!_elm_config->desktop_entry)
997 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
998 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
999 if (!_elm_config->desktop_entry)
1000 elm_widget_scroll_hold_pop(data);
1001 edje_object_part_text_select_none(wd->ent, "elm.text");
1005 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1007 Elm_Entry_Context_Menu_Item *it = data;
1008 Evas_Object *obj2 = it->obj;
1009 if (it->func) it->func(it->data, obj2, NULL);
1013 _menu_press(Evas_Object *obj)
1015 Widget_Data *wd = elm_widget_data_get(obj);
1018 const Elm_Entry_Context_Menu_Item *it;
1020 if ((wd->api) && (wd->api->obj_longpress))
1022 wd->api->obj_longpress(obj);
1024 else if (wd->context_menu)
1026 const char *context_menu_orientation;
1028 if (wd->hoversel) evas_object_del(wd->hoversel);
1029 else elm_widget_scroll_freeze_push(obj);
1030 wd->hoversel = elm_hoversel_add(obj);
1031 context_menu_orientation = edje_object_data_get
1032 (wd->ent, "context_menu_orientation");
1033 if ((context_menu_orientation) &&
1034 (!strcmp(context_menu_orientation, "horizontal")))
1035 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1036 elm_object_style_set(wd->hoversel, "entry");
1037 elm_widget_sub_object_add(obj, wd->hoversel);
1038 elm_object_text_set(wd->hoversel, "Text");
1039 top = elm_widget_top_get(obj);
1040 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1041 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1042 if (wd->have_selection)
1046 if (wd->have_selection)
1048 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1051 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1054 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1062 if (!_elm_config->desktop_entry)
1065 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1068 if (1) // need way to detect if someone has a selection
1071 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1076 EINA_LIST_FOREACH(wd->items, l, it)
1078 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1079 it->icon_type, _item_clicked, it);
1083 _hoversel_position(obj);
1084 evas_object_show(wd->hoversel);
1085 elm_hoversel_hover_begin(wd->hoversel);
1087 if (!_elm_config->desktop_entry)
1089 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1090 edje_object_part_text_select_abort(wd->ent, "elm.text");
1096 _long_press(void *data)
1098 Widget_Data *wd = elm_widget_data_get(data);
1099 if (!wd) return ECORE_CALLBACK_CANCEL;
1101 wd->longpress_timer = NULL;
1102 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1103 return ECORE_CALLBACK_CANCEL;
1107 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1109 Widget_Data *wd = elm_widget_data_get(data);
1110 Evas_Event_Mouse_Down *ev = event_info;
1112 if (wd->disabled) return;
1113 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1114 wd->downx = ev->canvas.x;
1115 wd->downy = ev->canvas.y;
1116 if (ev->button == 1)
1118 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1119 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1124 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1126 Widget_Data *wd = elm_widget_data_get(data);
1127 Evas_Event_Mouse_Up *ev = event_info;
1129 if (wd->disabled) return;
1130 if (ev->button == 1)
1132 if (wd->longpress_timer)
1134 ecore_timer_del(wd->longpress_timer);
1135 wd->longpress_timer = NULL;
1138 else if (ev->button == 3)
1146 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1148 Widget_Data *wd = elm_widget_data_get(data);
1149 Evas_Event_Mouse_Move *ev = event_info;
1151 if (wd->disabled) return;
1154 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1156 if (wd->longpress_timer)
1158 ecore_timer_del(wd->longpress_timer);
1159 wd->longpress_timer = NULL;
1162 else if (wd->longpress_timer)
1166 dx = wd->downx - ev->cur.canvas.x;
1168 dy = wd->downy - ev->cur.canvas.y;
1171 ((_elm_config->finger_size / 2) *
1172 (_elm_config->finger_size / 2)))
1174 ecore_timer_del(wd->longpress_timer);
1175 wd->longpress_timer = NULL;
1179 else if (wd->longpress_timer)
1183 dx = wd->downx - ev->cur.canvas.x;
1185 dy = wd->downy - ev->cur.canvas.y;
1188 ((_elm_config->finger_size / 2) *
1189 (_elm_config->finger_size / 2)))
1191 ecore_timer_del(wd->longpress_timer);
1192 wd->longpress_timer = NULL;
1198 _getbase(Evas_Object *obj)
1200 Widget_Data *wd = elm_widget_data_get(obj);
1201 if (!wd) return "base";
1204 if (wd->password) return "base-password";
1207 if (wd->single_line) return "base-single";
1210 switch (wd->linewrap)
1213 return "base-charwrap";
1216 case ELM_WRAP_MIXED:
1217 return "base-mixedwrap";
1220 return "base-nowrap";
1227 if (wd->password) return "base-password";
1230 if (wd->single_line) return "base-single-noedit";
1233 switch (wd->linewrap)
1236 return "base-noedit-charwrap";
1238 return "base-noedit";
1239 case ELM_WRAP_MIXED:
1240 return "base-noedit-mixedwrap";
1243 return "base-nowrap-noedit";
1252 _entry_changed_common_handling(void *data, const char *event)
1254 Widget_Data *wd = elm_widget_data_get(data);
1257 wd->changed = EINA_TRUE;
1258 /* Reset the size hints which are no more relevant.
1259 * Keep the height, this is a hack, but doesn't really matter
1260 * cause we'll re-eval in a moment. */
1261 evas_object_size_hint_min_get(data, NULL, &minh);
1262 evas_object_size_hint_min_set(data, -1, minh);
1264 if (wd->text) eina_stringshare_del(wd->text);
1266 evas_object_smart_callback_call(data, event, NULL);
1267 if (wd->delay_write)
1269 ecore_timer_del(wd->delay_write);
1270 wd->delay_write = NULL;
1272 if ((!wd->autosave) || (!wd->file)) return;
1273 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1277 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1279 _entry_changed_common_handling(data, SIG_CHANGED);
1283 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1285 _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1289 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1291 Widget_Data *wd = elm_widget_data_get(data);
1295 EINA_LIST_FOREACH(entries, l, entry)
1297 if (entry != data) elm_entry_select_none(entry);
1299 wd->have_selection = EINA_TRUE;
1300 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1301 #ifdef HAVE_ELEMENTARY_X
1302 if (wd->sel_notify_handler)
1304 const char *txt = elm_entry_selection_get(data);
1307 top = elm_widget_top_get(data);
1308 if ((top) && (elm_win_xwindow_get(top)))
1309 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1315 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1317 Widget_Data *wd = elm_widget_data_get(data);
1319 wd->have_selection = EINA_TRUE;
1320 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1321 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1322 elm_entry_selection_get(data));
1326 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1328 Widget_Data *wd = elm_widget_data_get(data);
1330 if (!wd->have_selection) return;
1331 wd->have_selection = EINA_FALSE;
1332 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1333 if (wd->sel_notify_handler)
1337 #ifdef HAVE_ELEMENTARY_X
1340 top = elm_widget_top_get(data);
1341 if ((top) && (elm_win_xwindow_get(top)))
1342 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1345 eina_stringshare_del(wd->cut_sel);
1350 #ifdef HAVE_ELEMENTARY_X
1353 top = elm_widget_top_get(data);
1354 if ((top) && (elm_win_xwindow_get(top)))
1355 elm_selection_clear(ELM_SEL_PRIMARY, data);
1362 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1364 Widget_Data *wd = elm_widget_data_get(data);
1365 Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ? ELM_SEL_PRIMARY : ELM_SEL_CLIPBOARD;
1367 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1368 if (wd->sel_notify_handler)
1370 #ifdef HAVE_ELEMENTARY_X
1373 top = elm_widget_top_get(data);
1374 if ((top) && (elm_win_xwindow_get(top)))
1376 wd->selection_asked = EINA_TRUE;
1377 elm_selection_get(type, ELM_SEL_FORMAT_MARKUP, data,
1385 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1387 Widget_Data *wd = elm_widget_data_get(data);
1389 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1390 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1391 elm_entry_selection_get(data));
1395 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1397 Widget_Data *wd = elm_widget_data_get(data);
1399 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1400 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1401 elm_entry_selection_get(data));
1402 edje_object_part_text_insert(wd->ent, "elm.text", "");
1403 wd->changed = EINA_TRUE;
1408 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1410 Widget_Data *wd = elm_widget_data_get(data);
1412 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1413 wd->cur_changed = EINA_TRUE;
1414 _recalc_cursor_geometry(data);
1418 _signal_anchor_geoms_do_things_with(Widget_Data *wd, Elm_Entry_Anchor_Info *ei)
1420 const Eina_List *geoms, *l;
1421 Evas_Textblock_Rectangle *r;
1422 Evas_Coord px, py, x, y;
1424 geoms = edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei->name);
1428 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1429 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1430 EINA_LIST_FOREACH(geoms, l, r)
1432 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1433 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1445 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1447 Widget_Data *wd = elm_widget_data_get(data);
1448 Elm_Entry_Anchor_Info ei;
1452 p = emission + sizeof("nchor,mouse,down,");
1453 ei.button = strtol(p, &p2, 10);
1455 ei.x = ei.y = ei.w = ei.h = 0;
1457 _signal_anchor_geoms_do_things_with(wd, &ei);
1460 evas_object_smart_callback_call(data, SIG_ANCHOR_DOWN, &ei);
1464 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1466 Widget_Data *wd = elm_widget_data_get(data);
1467 Elm_Entry_Anchor_Info ei;
1471 p = emission + sizeof("nchor,mouse,up,");
1472 ei.button = strtol(p, &p2, 10);
1474 ei.x = ei.y = ei.w = ei.h = 0;
1476 _signal_anchor_geoms_do_things_with(wd, &ei);
1479 evas_object_smart_callback_call(data, SIG_ANCHOR_UP, &ei);
1483 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1485 Widget_Data *wd = elm_widget_data_get(data);
1486 Elm_Entry_Anchor_Info ei;
1490 p = emission + sizeof("nchor,mouse,clicked,");
1491 ei.button = strtol(p, &p2, 10);
1493 ei.x = ei.y = ei.w = ei.h = 0;
1495 _signal_anchor_geoms_do_things_with(wd, &ei);
1498 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1502 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1504 Widget_Data *wd = elm_widget_data_get(data);
1509 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1511 Widget_Data *wd = elm_widget_data_get(data);
1512 Elm_Entry_Anchor_Info ei;
1514 ei.name = emission + sizeof("nchor,mouse,in,");
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_IN, &ei);
1525 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1527 Widget_Data *wd = elm_widget_data_get(data);
1528 Elm_Entry_Anchor_Info ei;
1530 ei.name = emission + sizeof("nchor,mouse,out,");
1532 ei.x = ei.y = ei.w = ei.h = 0;
1534 _signal_anchor_geoms_do_things_with(wd, &ei);
1537 evas_object_smart_callback_call(data, SIG_ANCHOR_OUT, &ei);
1541 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1543 Widget_Data *wd = elm_widget_data_get(data);
1545 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1549 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1551 Widget_Data *wd = elm_widget_data_get(data);
1553 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1557 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1559 Widget_Data *wd = elm_widget_data_get(data);
1561 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1565 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1567 Widget_Data *wd = elm_widget_data_get(data);
1569 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1572 #ifdef HAVE_ELEMENTARY_X
1574 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1576 Widget_Data *wd = elm_widget_data_get(data);
1577 Ecore_X_Event_Selection_Notify *ev = event;
1578 if (!wd) return ECORE_CALLBACK_PASS_ON;
1579 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1580 return ECORE_CALLBACK_PASS_ON;
1582 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1583 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1585 Ecore_X_Selection_Data_Text *text_data;
1587 text_data = ev->data;
1588 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1590 if (text_data->text)
1592 char *txt = _elm_util_text_to_mkup(text_data->text);
1596 elm_entry_entry_insert(data, txt);
1601 wd->selection_asked = EINA_FALSE;
1603 else if (ev->selection == ECORE_X_SELECTION_XDND)
1605 Ecore_X_Selection_Data_Text *text_data;
1607 text_data = ev->data;
1608 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1610 if (text_data->text)
1612 char *txt = _elm_util_text_to_mkup(text_data->text);
1616 /* Massive FIXME: this should be at the drag point */
1617 elm_entry_entry_insert(data, txt);
1622 wd->drag_selection_asked = EINA_FALSE;
1624 ecore_x_dnd_send_finished();
1627 return ECORE_CALLBACK_PASS_ON;
1631 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1633 Widget_Data *wd = elm_widget_data_get(data);
1634 Ecore_X_Event_Selection_Clear *ev = event;
1635 if (!wd) return ECORE_CALLBACK_PASS_ON;
1636 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1637 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1638 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1640 elm_entry_select_none(data);
1642 return ECORE_CALLBACK_PASS_ON;
1646 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1651 wd = elm_widget_data_get(obj);
1652 if (!wd) return EINA_FALSE;
1653 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1655 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1656 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1657 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1658 EDJE_CURSOR_MAIN,drop->x,drop->y);
1659 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1660 elm_entry_entry_insert(obj, drop->data);
1661 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1662 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1668 static Evas_Object *
1669 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1671 Widget_Data *wd = elm_widget_data_get(data);
1674 Elm_Entry_Item_Provider *ip;
1676 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1678 o = ip->func(ip->data, data, item);
1681 if (!strncmp(item, "file://", 7))
1683 const char *fname = item + 7;
1685 o = evas_object_image_filled_add(evas_object_evas_get(data));
1686 evas_object_image_file_set(o, fname, NULL);
1687 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1689 evas_object_show(o);
1694 o = edje_object_add(evas_object_evas_get(data));
1695 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1699 o = edje_object_add(evas_object_evas_get(data));
1700 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1701 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1706 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1708 Widget_Data *wd = elm_widget_data_get(data);
1710 Elm_Entry_Text_Filter *tf;
1712 if (type == EDJE_TEXT_FILTER_FORMAT)
1715 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1717 tf->func(tf->data, data, text);
1723 /* This function is used to insert text by chunks in jobs */
1725 _text_append_idler(void *data)
1729 Evas_Object *obj = (Evas_Object *) data;
1730 Widget_Data *wd = elm_widget_data_get(obj);
1731 if (wd->text) eina_stringshare_del(wd->text);
1733 wd->changed = EINA_TRUE;
1735 start = wd->append_text_position;
1736 if(start + _CHUNK_SIZE < wd->append_text_len)
1738 wd->append_text_position = (start + _CHUNK_SIZE);
1739 /* Go to the start of the nearest codepoint, because we don't want
1740 * to cut it in the middle */
1741 eina_unicode_utf8_get_prev(wd->append_text_left,
1742 &wd->append_text_position);
1746 wd->append_text_position = wd->append_text_len;
1749 backup = wd->append_text_left[wd->append_text_position];
1750 wd->append_text_left[wd->append_text_position] = '\0';
1752 edje_object_part_text_append(wd->ent, "elm.text",
1753 wd->append_text_left + start);
1755 wd->append_text_left[wd->append_text_position] = backup;
1757 /* If there's still more to go, renew the idler, else, cleanup */
1758 if (wd->append_text_position < wd->append_text_len)
1760 return ECORE_CALLBACK_RENEW;
1764 free(wd->append_text_left);
1765 wd->append_text_left = NULL;
1766 wd->append_text_idler = NULL;
1767 return ECORE_CALLBACK_CANCEL;
1772 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
1774 int i = 0, unit_size;
1775 int current_len = strlen(*text);
1776 char *new_text = *text;
1777 if (unit >= LENGTH_UNIT_LAST) return;
1780 if (*new_text == '<')
1782 while (*new_text != '>')
1785 if (!*new_text) break;
1792 if (*new_text == '&')
1794 while (*(new_text + index) != ';')
1797 if (!*(new_text + index)) break;
1801 index = evas_string_char_next_get(new_text, index, NULL);
1802 markup = malloc(index + 1);
1803 strncpy(markup, new_text, index);
1805 if (unit == LENGTH_UNIT_BYTE)
1806 unit_size = strlen(elm_entry_markup_to_utf8(markup));
1807 else if (unit == LENGTH_UNIT_CHAR)
1808 unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
1814 if (can_add < unit_size)
1818 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1824 strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
1825 current_len -= index;
1826 (*text)[current_len] = 0;
1831 can_add -= unit_size;
1836 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1840 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
1843 ELM_CHECK_WIDTYPE(obj, widtype);
1844 if (item && strcmp(item, "default")) return;
1845 Widget_Data *wd = elm_widget_data_get(obj);
1847 if (!entry) entry = "";
1848 if (wd->text) eina_stringshare_del(wd->text);
1850 wd->changed = EINA_TRUE;
1852 /* Clear currently pending job if there is one */
1853 if (wd->append_text_idler)
1855 ecore_idler_del(wd->append_text_idler);
1856 free(wd->append_text_left);
1857 wd->append_text_left = NULL;
1858 wd->append_text_idler = NULL;
1861 len = strlen(entry);
1862 /* Split to ~_CHUNK_SIZE chunks */
1863 if (len > _CHUNK_SIZE)
1865 wd->append_text_left = (char *) malloc(len + 1);
1868 /* If we decided to use the idler */
1869 if (wd->append_text_left)
1871 /* Need to clear the entry first */
1872 edje_object_part_text_set(wd->ent, "elm.text", "");
1873 memcpy(wd->append_text_left, entry, len + 1);
1874 wd->append_text_position = 0;
1875 wd->append_text_len = len;
1876 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
1880 edje_object_part_text_set(wd->ent, "elm.text", entry);
1885 _elm_entry_text_get(const Evas_Object *obj, const char *item)
1887 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1888 Widget_Data *wd = elm_widget_data_get(obj);
1889 if (item && strcmp(item, "default")) return NULL;
1891 if (!wd) return NULL;
1892 if (wd->text) return wd->text;
1893 text = edje_object_part_text_get(wd->ent, "elm.text");
1896 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1899 eina_stringshare_replace(&wd->text, text);
1904 elm_entry_add(Evas_Object *parent)
1906 Evas_Object *obj, *top;
1910 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1912 ELM_SET_WIDTYPE(widtype, "entry");
1913 elm_widget_type_set(obj, "entry");
1914 elm_widget_sub_object_add(parent, obj);
1915 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1916 elm_widget_data_set(obj, wd);
1917 elm_widget_del_hook_set(obj, _del_hook);
1918 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1919 elm_widget_theme_hook_set(obj, _theme_hook);
1920 elm_widget_disable_hook_set(obj, _disable_hook);
1921 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1922 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
1923 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1924 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1925 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1926 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1927 elm_widget_can_focus_set(obj, EINA_TRUE);
1928 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1929 elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
1930 elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
1932 wd->scroller = elm_smart_scroller_add(e);
1933 elm_widget_sub_object_add(obj, wd->scroller);
1934 elm_smart_scroller_widget_set(wd->scroller, obj);
1935 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
1936 elm_widget_style_get(obj));
1937 evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1938 evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
1939 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
1940 evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
1942 wd->linewrap = ELM_WRAP_WORD;
1943 wd->editable = EINA_TRUE;
1944 wd->disabled = EINA_FALSE;
1945 wd->context_menu = EINA_TRUE;
1946 wd->autosave = EINA_TRUE;
1947 wd->textonly = EINA_FALSE;
1949 wd->ent = edje_object_add(e);
1950 elm_widget_sub_object_add(obj, wd->ent);
1951 edje_object_item_provider_set(wd->ent, _get_item, obj);
1952 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1953 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1954 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1956 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1958 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1960 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1962 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1963 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1964 _signal_entry_changed, obj);
1965 edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
1966 _signal_preedit_changed, obj);
1967 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1968 _signal_selection_start, obj);
1969 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1970 _signal_selection_changed, obj);
1971 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1972 _signal_selection_cleared, obj);
1973 edje_object_signal_callback_add(wd->ent, "entry,paste,request,1", "elm.text",
1974 _signal_entry_paste_request, obj);
1975 edje_object_signal_callback_add(wd->ent, "entry,paste,request,3", "elm.text",
1976 _signal_entry_paste_request, obj);
1977 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1978 _signal_entry_copy_notify, obj);
1979 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1980 _signal_entry_cut_notify, obj);
1981 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1982 _signal_cursor_changed, obj);
1983 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1984 _signal_anchor_down, obj);
1985 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1986 _signal_anchor_up, obj);
1987 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1988 _signal_anchor_clicked, obj);
1989 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1990 _signal_anchor_move, obj);
1991 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1992 _signal_anchor_in, obj);
1993 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1994 _signal_anchor_out, obj);
1995 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1996 _signal_key_enter, obj);
1997 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1998 _signal_mouse_down, obj);
1999 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2000 _signal_mouse_clicked, obj);
2001 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2002 _signal_mouse_double, obj);
2003 edje_object_part_text_set(wd->ent, "elm.text", "");
2004 if (_elm_config->desktop_entry)
2005 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2006 elm_widget_resize_object_set(obj, wd->ent);
2009 #ifdef HAVE_ELEMENTARY_X
2010 top = elm_widget_top_get(obj);
2011 if ((top) && (elm_win_xwindow_get(top)))
2013 wd->sel_notify_handler =
2014 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2015 _event_selection_notify, obj);
2016 wd->sel_clear_handler =
2017 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2018 _event_selection_clear, obj);
2021 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2022 _drag_drop_cb, NULL);
2025 entries = eina_list_prepend(entries, obj);
2027 // module - find module for entry
2028 wd->api = _module(obj);
2029 // if found - hook in
2030 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2032 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2033 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2034 // TODO: and save some bytes, making descriptions per-class and not instance!
2035 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2040 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2042 ELM_CHECK_WIDTYPE(obj, widtype);
2043 Widget_Data *wd = elm_widget_data_get(obj);
2045 if (wd->single_line == single_line) return;
2046 wd->single_line = single_line;
2047 wd->linewrap = ELM_WRAP_NONE;
2048 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2052 if (wd->single_line)
2053 elm_smart_scroller_policy_set(wd->scroller,
2054 ELM_SMART_SCROLLER_POLICY_OFF,
2055 ELM_SMART_SCROLLER_POLICY_OFF);
2058 const Elm_Scroller_Policy map[3] =
2060 ELM_SMART_SCROLLER_POLICY_AUTO,
2061 ELM_SMART_SCROLLER_POLICY_ON,
2062 ELM_SMART_SCROLLER_POLICY_OFF
2064 elm_smart_scroller_policy_set(wd->scroller,
2073 elm_entry_single_line_get(const Evas_Object *obj)
2075 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2076 Widget_Data *wd = elm_widget_data_get(obj);
2077 if (!wd) return EINA_FALSE;
2078 return wd->single_line;
2082 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2084 ELM_CHECK_WIDTYPE(obj, widtype);
2085 Widget_Data *wd = elm_widget_data_get(obj);
2087 if (wd->password == password) return;
2088 wd->password = password;
2089 wd->single_line = EINA_TRUE;
2090 wd->linewrap = ELM_WRAP_NONE;
2095 elm_entry_password_get(const Evas_Object *obj)
2097 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2098 Widget_Data *wd = elm_widget_data_get(obj);
2099 if (!wd) return EINA_FALSE;
2100 return wd->password;
2104 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2106 _elm_entry_text_set(obj, NULL, entry);
2110 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2113 ELM_CHECK_WIDTYPE(obj, widtype);
2114 Widget_Data *wd = elm_widget_data_get(obj);
2116 if (!entry) entry = "";
2117 wd->changed = EINA_TRUE;
2119 len = strlen(entry);
2120 if (wd->append_text_left)
2123 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
2129 wd->append_text_left = tmpbuf;
2130 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
2131 wd->append_text_len += len;
2135 /* FIXME: Add chunked appending here (like in entry_set) */
2136 edje_object_part_text_append(wd->ent, "elm.text", entry);
2141 elm_entry_entry_get(const Evas_Object *obj)
2143 return _elm_entry_text_get(obj, NULL);
2147 elm_entry_is_empty(const Evas_Object *obj)
2149 /* FIXME: until there's support for that in textblock, we just check
2150 * to see if the there is text or not. */
2151 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2152 Widget_Data *wd = elm_widget_data_get(obj);
2153 const Evas_Object *tb;
2154 Evas_Textblock_Cursor *cur;
2156 if (!wd) return EINA_TRUE;
2157 /* It's a hack until we get the support suggested above.
2158 * We just create a cursor, point it to the begining, and then
2159 * try to advance it, if it can advance, the tb is not empty,
2160 * otherwise it is. */
2161 tb = edje_object_part_object_get(wd->ent, "elm.text");
2162 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2163 actually, ok for the time being, thsese hackish stuff will be removed
2164 once evas 1.0 is out*/
2165 evas_textblock_cursor_pos_set(cur, 0);
2166 ret = evas_textblock_cursor_char_next(cur);
2167 evas_textblock_cursor_free(cur);
2173 elm_entry_selection_get(const Evas_Object *obj)
2175 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2176 Widget_Data *wd = elm_widget_data_get(obj);
2177 if (!wd) return NULL;
2178 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2182 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2184 ELM_CHECK_WIDTYPE(obj, widtype);
2185 Widget_Data *wd = elm_widget_data_get(obj);
2187 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2188 wd->changed = EINA_TRUE;
2193 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2195 ELM_CHECK_WIDTYPE(obj, widtype);
2196 Widget_Data *wd = elm_widget_data_get(obj);
2198 if (wd->linewrap == wrap) return;
2200 wd->linewrap = wrap;
2205 elm_entry_line_wrap_get(const Evas_Object *obj)
2207 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2208 Widget_Data *wd = elm_widget_data_get(obj);
2209 if (!wd) return EINA_FALSE;
2210 return wd->linewrap;
2214 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2216 ELM_CHECK_WIDTYPE(obj, widtype);
2217 Widget_Data *wd = elm_widget_data_get(obj);
2219 if (wd->editable == editable) return;
2220 wd->editable = editable;
2223 #ifdef HAVE_ELEMENTARY_X
2225 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2227 elm_drop_target_del(obj);
2232 elm_entry_editable_get(const Evas_Object *obj)
2234 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2235 Widget_Data *wd = elm_widget_data_get(obj);
2236 if (!wd) return EINA_FALSE;
2237 return wd->editable;
2241 elm_entry_select_none(Evas_Object *obj)
2243 ELM_CHECK_WIDTYPE(obj, widtype);
2244 Widget_Data *wd = elm_widget_data_get(obj);
2248 wd->selmode = EINA_FALSE;
2249 if (!_elm_config->desktop_entry)
2250 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2251 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2253 wd->have_selection = EINA_FALSE;
2254 edje_object_part_text_select_none(wd->ent, "elm.text");
2258 elm_entry_select_all(Evas_Object *obj)
2260 ELM_CHECK_WIDTYPE(obj, widtype);
2261 Widget_Data *wd = elm_widget_data_get(obj);
2265 wd->selmode = EINA_FALSE;
2266 if (!_elm_config->desktop_entry)
2267 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2268 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2270 wd->have_selection = EINA_TRUE;
2271 edje_object_part_text_select_all(wd->ent, "elm.text");
2275 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2277 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2278 Widget_Data *wd = elm_widget_data_get(obj);
2279 if (!wd) return EINA_FALSE;
2280 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2285 elm_entry_cursor_next(Evas_Object *obj)
2287 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2288 Widget_Data *wd = elm_widget_data_get(obj);
2289 if (!wd) return EINA_FALSE;
2290 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2294 elm_entry_cursor_prev(Evas_Object *obj)
2296 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2297 Widget_Data *wd = elm_widget_data_get(obj);
2298 if (!wd) return EINA_FALSE;
2299 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2303 elm_entry_cursor_up(Evas_Object *obj)
2305 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2306 Widget_Data *wd = elm_widget_data_get(obj);
2307 if (!wd) return EINA_FALSE;
2308 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2312 elm_entry_cursor_down(Evas_Object *obj)
2314 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2315 Widget_Data *wd = elm_widget_data_get(obj);
2316 if (!wd) return EINA_FALSE;
2317 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2321 elm_entry_cursor_begin_set(Evas_Object *obj)
2323 ELM_CHECK_WIDTYPE(obj, widtype);
2324 Widget_Data *wd = elm_widget_data_get(obj);
2326 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2330 elm_entry_cursor_end_set(Evas_Object *obj)
2332 ELM_CHECK_WIDTYPE(obj, widtype);
2333 Widget_Data *wd = elm_widget_data_get(obj);
2337 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2340 elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
2341 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
2346 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2348 ELM_CHECK_WIDTYPE(obj, widtype);
2349 Widget_Data *wd = elm_widget_data_get(obj);
2351 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2355 elm_entry_cursor_line_end_set(Evas_Object *obj)
2357 ELM_CHECK_WIDTYPE(obj, widtype);
2358 Widget_Data *wd = elm_widget_data_get(obj);
2360 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2364 elm_entry_cursor_selection_begin(Evas_Object *obj)
2366 ELM_CHECK_WIDTYPE(obj, widtype);
2367 Widget_Data *wd = elm_widget_data_get(obj);
2369 edje_object_part_text_select_begin(wd->ent, "elm.text");
2373 elm_entry_cursor_selection_end(Evas_Object *obj)
2375 ELM_CHECK_WIDTYPE(obj, widtype);
2376 Widget_Data *wd = elm_widget_data_get(obj);
2378 edje_object_part_text_select_extend(wd->ent, "elm.text");
2382 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2384 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2385 Widget_Data *wd = elm_widget_data_get(obj);
2386 if (!wd) return EINA_FALSE;
2387 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2391 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2393 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2394 Widget_Data *wd = elm_widget_data_get(obj);
2395 if (!wd) return EINA_FALSE;
2396 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2400 elm_entry_cursor_content_get(const Evas_Object *obj)
2402 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2403 Widget_Data *wd = elm_widget_data_get(obj);
2404 if (!wd) return NULL;
2405 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2409 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2411 ELM_CHECK_WIDTYPE(obj, widtype);
2412 Widget_Data *wd = elm_widget_data_get(obj);
2414 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2415 edje_object_message_signal_process(wd->ent);
2419 elm_entry_cursor_pos_get(const Evas_Object *obj)
2421 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2422 Widget_Data *wd = elm_widget_data_get(obj);
2424 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2428 elm_entry_selection_cut(Evas_Object *obj)
2430 ELM_CHECK_WIDTYPE(obj, widtype);
2431 Widget_Data *wd = elm_widget_data_get(obj);
2433 _cut(obj, NULL, NULL);
2437 elm_entry_selection_copy(Evas_Object *obj)
2439 ELM_CHECK_WIDTYPE(obj, widtype);
2440 Widget_Data *wd = elm_widget_data_get(obj);
2442 _copy(obj, NULL, NULL);
2446 elm_entry_selection_paste(Evas_Object *obj)
2448 ELM_CHECK_WIDTYPE(obj, widtype);
2449 Widget_Data *wd = elm_widget_data_get(obj);
2451 _paste(obj, NULL, NULL);
2455 elm_entry_context_menu_clear(Evas_Object *obj)
2457 ELM_CHECK_WIDTYPE(obj, widtype);
2458 Widget_Data *wd = elm_widget_data_get(obj);
2459 Elm_Entry_Context_Menu_Item *it;
2461 EINA_LIST_FREE(wd->items, it)
2463 eina_stringshare_del(it->label);
2464 eina_stringshare_del(it->icon_file);
2465 eina_stringshare_del(it->icon_group);
2471 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)
2473 ELM_CHECK_WIDTYPE(obj, widtype);
2474 Widget_Data *wd = elm_widget_data_get(obj);
2475 Elm_Entry_Context_Menu_Item *it;
2477 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2479 wd->items = eina_list_append(wd->items, it);
2481 it->label = eina_stringshare_add(label);
2482 it->icon_file = eina_stringshare_add(icon_file);
2483 it->icon_type = icon_type;
2485 it->data = (void *)data;
2489 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2491 ELM_CHECK_WIDTYPE(obj, widtype);
2492 Widget_Data *wd = elm_widget_data_get(obj);
2494 if (wd->context_menu == !disabled) return;
2495 wd->context_menu = !disabled;
2499 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2501 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2502 Widget_Data *wd = elm_widget_data_get(obj);
2503 if (!wd) return EINA_FALSE;
2504 return !wd->context_menu;
2508 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2510 ELM_CHECK_WIDTYPE(obj, widtype);
2511 Widget_Data *wd = elm_widget_data_get(obj);
2513 EINA_SAFETY_ON_NULL_RETURN(func);
2514 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2518 wd->item_providers = eina_list_append(wd->item_providers, ip);
2522 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2524 ELM_CHECK_WIDTYPE(obj, widtype);
2525 Widget_Data *wd = elm_widget_data_get(obj);
2527 EINA_SAFETY_ON_NULL_RETURN(func);
2528 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2532 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2536 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2538 ELM_CHECK_WIDTYPE(obj, widtype);
2539 Widget_Data *wd = elm_widget_data_get(obj);
2541 Elm_Entry_Item_Provider *ip;
2543 EINA_SAFETY_ON_NULL_RETURN(func);
2544 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2546 if ((ip->func == func) && ((!data) || (ip->data == data)))
2548 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2556 elm_entry_text_filter_append(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2559 Elm_Entry_Text_Filter *tf;
2560 ELM_CHECK_WIDTYPE(obj, widtype);
2562 wd = elm_widget_data_get(obj);
2564 EINA_SAFETY_ON_NULL_RETURN(func);
2566 tf = _filter_new(func, data);
2569 wd->text_filters = eina_list_append(wd->text_filters, tf);
2573 elm_entry_text_filter_prepend(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2576 Elm_Entry_Text_Filter *tf;
2577 ELM_CHECK_WIDTYPE(obj, widtype);
2579 wd = elm_widget_data_get(obj);
2581 EINA_SAFETY_ON_NULL_RETURN(func);
2583 tf = _filter_new(func, data);
2586 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2590 elm_entry_text_filter_remove(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2594 Elm_Entry_Text_Filter *tf;
2595 ELM_CHECK_WIDTYPE(obj, widtype);
2597 wd = elm_widget_data_get(obj);
2599 EINA_SAFETY_ON_NULL_RETURN(func);
2601 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2603 if ((tf->func == func) && ((!data) || (tf->data == data)))
2605 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2613 elm_entry_markup_to_utf8(const char *s)
2615 char *ss = _elm_util_mkup_to_text(s);
2616 if (!ss) ss = strdup("");
2621 elm_entry_utf8_to_markup(const char *s)
2623 char *ss = _elm_util_text_to_mkup(s);
2624 if (!ss) ss = strdup("");
2629 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2631 Elm_Entry_Filter_Limit_Size *lim = data;
2634 const char *(*text_get)(const Evas_Object *);
2635 const char *widget_type;
2637 EINA_SAFETY_ON_NULL_RETURN(data);
2638 EINA_SAFETY_ON_NULL_RETURN(entry);
2639 EINA_SAFETY_ON_NULL_RETURN(text);
2641 /* hack. I don't want to copy the entire function to work with
2643 widget_type = elm_widget_type_get(entry);
2644 if (!strcmp(widget_type, "entry"))
2645 text_get = elm_entry_entry_get;
2649 current = elm_entry_markup_to_utf8(text_get(entry));
2651 if (lim->max_char_count > 0)
2653 len = evas_string_char_len_get(current);
2654 if (len >= lim->max_char_count)
2656 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2662 newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
2663 if ((len + newlen) > lim->max_char_count)
2664 _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
2666 else if (lim->max_byte_count > 0)
2668 len = strlen(current);
2669 if (len >= lim->max_byte_count)
2671 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2677 newlen = strlen(elm_entry_markup_to_utf8(*text));
2678 if ((len + newlen) > lim->max_byte_count)
2679 _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
2685 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2687 Elm_Entry_Filter_Accept_Set *as = data;
2691 int read_idx, last_read_idx = 0, read_char;
2693 EINA_SAFETY_ON_NULL_RETURN(data);
2694 EINA_SAFETY_ON_NULL_RETURN(text);
2696 if ((!as->accepted) && (!as->rejected))
2702 goes_in = EINA_TRUE;
2707 goes_in = EINA_FALSE;
2711 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2714 int cmp_idx, cmp_char;
2715 Eina_Bool in_set = EINA_FALSE;
2717 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2720 if (read_char == cmp_char)
2725 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2727 if (in_set == goes_in)
2729 int size = read_idx - last_read_idx;
2730 const char *src = (*text) + last_read_idx;
2732 memcpy(insert, *text + last_read_idx, size);
2735 last_read_idx = read_idx;
2736 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2742 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2744 ELM_CHECK_WIDTYPE(obj, widtype);
2745 Widget_Data *wd = elm_widget_data_get(obj);
2747 if (wd->delay_write)
2749 ecore_timer_del(wd->delay_write);
2750 wd->delay_write = NULL;
2752 if (wd->autosave) _save(obj);
2753 eina_stringshare_replace(&wd->file, file);
2754 wd->format = format;
2759 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2761 ELM_CHECK_WIDTYPE(obj, widtype);
2762 Widget_Data *wd = elm_widget_data_get(obj);
2764 if (file) *file = wd->file;
2765 if (format) *format = wd->format;
2769 elm_entry_file_save(Evas_Object *obj)
2771 ELM_CHECK_WIDTYPE(obj, widtype);
2772 Widget_Data *wd = elm_widget_data_get(obj);
2774 if (wd->delay_write)
2776 ecore_timer_del(wd->delay_write);
2777 wd->delay_write = NULL;
2780 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2784 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2786 ELM_CHECK_WIDTYPE(obj, widtype);
2787 Widget_Data *wd = elm_widget_data_get(obj);
2789 wd->autosave = !!autosave;
2793 elm_entry_autosave_get(const Evas_Object *obj)
2795 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2796 Widget_Data *wd = elm_widget_data_get(obj);
2797 if (!wd) return EINA_FALSE;
2798 return wd->autosave;
2802 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2804 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2805 ELM_CHECK_WIDTYPE(obj, widtype);
2806 Widget_Data *wd = elm_widget_data_get(obj);
2808 textonly = !!textonly;
2809 if (wd->textonly == textonly) return;
2810 wd->textonly = !!textonly;
2811 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2812 #ifdef HAVE_ELEMENTARY_X
2813 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2818 elm_entry_cnp_textonly_get(const Evas_Object *obj)
2820 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2821 Widget_Data *wd = elm_widget_data_get(obj);
2822 if (!wd) return EINA_FALSE;
2823 return wd->textonly;
2827 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
2829 ELM_CHECK_WIDTYPE(obj, widtype);
2830 Widget_Data *wd = elm_widget_data_get(obj);
2833 if (wd->scroll == scroll) return;
2834 wd->scroll = scroll;
2837 elm_widget_sub_object_del(obj, wd->scroller);
2838 elm_widget_resize_object_set(obj, wd->scroller);
2839 elm_widget_sub_object_add(obj, wd->ent);
2840 elm_smart_scroller_child_set(wd->scroller, wd->ent);
2841 evas_object_show(wd->scroller);
2842 elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
2846 elm_smart_scroller_child_set(wd->scroller, NULL);
2847 elm_widget_sub_object_del(obj, wd->ent);
2848 elm_widget_resize_object_set(obj, wd->ent);
2849 evas_object_smart_member_add(wd->scroller, obj);
2850 elm_widget_sub_object_add(obj, wd->scroller);
2851 evas_object_hide(wd->scroller);
2852 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
2859 elm_entry_scrollable_get(const Evas_Object *obj)
2861 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2862 Widget_Data *wd = elm_widget_data_get(obj);
2863 if (!wd) return EINA_FALSE;
2868 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
2870 ELM_CHECK_WIDTYPE(obj, widtype);
2871 Widget_Data *wd = elm_widget_data_get(obj);
2874 EINA_SAFETY_ON_NULL_RETURN(icon);
2875 if (wd->icon == icon) return;
2876 if (wd->icon) evas_object_del(wd->icon);
2878 edje = elm_smart_scroller_edje_object_get(wd->scroller);
2880 edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
2881 edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
2886 elm_entry_icon_get(const Evas_Object *obj)
2888 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2889 Widget_Data *wd = elm_widget_data_get(obj);
2890 if (!wd) return NULL;
2895 elm_entry_icon_unset(Evas_Object *obj)
2897 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2898 Widget_Data *wd = elm_widget_data_get(obj);
2899 Evas_Object *ret = NULL;
2900 if (!wd) return NULL;
2903 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
2904 if (!edje) return NULL;
2906 edje_object_part_unswallow(edje, wd->icon);
2907 edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
2915 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
2917 ELM_CHECK_WIDTYPE(obj, widtype);
2918 Widget_Data *wd = elm_widget_data_get(obj);
2919 if ((!wd) || (!wd->icon)) return;
2921 evas_object_hide(wd->icon);
2923 evas_object_show(wd->icon);
2928 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
2930 ELM_CHECK_WIDTYPE(obj, widtype);
2931 Widget_Data *wd = elm_widget_data_get(obj);
2934 EINA_SAFETY_ON_NULL_RETURN(end);
2935 if (wd->end == end) return;
2936 if (wd->end) evas_object_del(wd->end);
2938 edje = elm_smart_scroller_edje_object_get(wd->scroller);
2940 edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
2941 edje_object_signal_emit(edje, "elm,action,show,end", "elm");
2946 elm_entry_end_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_end_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->end);
2967 edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
2975 elm_entry_end_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->end)) return;
2981 evas_object_hide(wd->end);
2983 evas_object_show(wd->end);
2988 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
2990 ELM_CHECK_WIDTYPE(obj, widtype);
2991 Widget_Data *wd = elm_widget_data_get(obj);
2992 const Elm_Scroller_Policy map[3] =
2994 ELM_SMART_SCROLLER_POLICY_AUTO,
2995 ELM_SMART_SCROLLER_POLICY_ON,
2996 ELM_SMART_SCROLLER_POLICY_OFF
3001 elm_smart_scroller_policy_set(wd->scroller,
3007 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3009 ELM_CHECK_WIDTYPE(obj, widtype);
3010 Widget_Data *wd = elm_widget_data_get(obj);
3012 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
3016 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3018 ELM_CHECK_WIDTYPE(obj, widtype);
3019 Widget_Data *wd = elm_widget_data_get(obj);
3021 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);