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_all(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1317 Widget_Data *wd = elm_widget_data_get(data);
1319 elm_entry_select_all(data);
1323 _signal_selection_none(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1325 Widget_Data *wd = elm_widget_data_get(data);
1327 elm_entry_select_none(data);
1331 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1333 Widget_Data *wd = elm_widget_data_get(data);
1335 wd->have_selection = EINA_TRUE;
1336 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1337 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1338 elm_entry_selection_get(data));
1342 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1344 Widget_Data *wd = elm_widget_data_get(data);
1346 if (!wd->have_selection) return;
1347 wd->have_selection = EINA_FALSE;
1348 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1349 if (wd->sel_notify_handler)
1353 #ifdef HAVE_ELEMENTARY_X
1356 top = elm_widget_top_get(data);
1357 if ((top) && (elm_win_xwindow_get(top)))
1358 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1361 eina_stringshare_del(wd->cut_sel);
1366 #ifdef HAVE_ELEMENTARY_X
1369 top = elm_widget_top_get(data);
1370 if ((top) && (elm_win_xwindow_get(top)))
1371 elm_selection_clear(ELM_SEL_PRIMARY, data);
1378 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1380 Widget_Data *wd = elm_widget_data_get(data);
1381 Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ? ELM_SEL_PRIMARY : ELM_SEL_CLIPBOARD;
1383 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1384 if (wd->sel_notify_handler)
1386 #ifdef HAVE_ELEMENTARY_X
1389 top = elm_widget_top_get(data);
1390 if ((top) && (elm_win_xwindow_get(top)))
1392 wd->selection_asked = EINA_TRUE;
1393 elm_selection_get(type, ELM_SEL_FORMAT_MARKUP, data,
1401 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1403 Widget_Data *wd = elm_widget_data_get(data);
1405 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1406 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1407 elm_entry_selection_get(data));
1411 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1413 Widget_Data *wd = elm_widget_data_get(data);
1415 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1416 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1417 elm_entry_selection_get(data));
1418 edje_object_part_text_insert(wd->ent, "elm.text", "");
1419 wd->changed = EINA_TRUE;
1424 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1426 Widget_Data *wd = elm_widget_data_get(data);
1428 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1429 wd->cur_changed = EINA_TRUE;
1430 _recalc_cursor_geometry(data);
1434 _signal_anchor_geoms_do_things_with(Widget_Data *wd, Elm_Entry_Anchor_Info *ei)
1436 const Eina_List *geoms, *l;
1437 Evas_Textblock_Rectangle *r;
1438 Evas_Coord px, py, x, y;
1440 geoms = edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei->name);
1444 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1445 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1446 EINA_LIST_FOREACH(geoms, l, r)
1448 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1449 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1461 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1463 Widget_Data *wd = elm_widget_data_get(data);
1464 Elm_Entry_Anchor_Info ei;
1468 p = emission + sizeof("nchor,mouse,down,");
1469 ei.button = strtol(p, &p2, 10);
1471 ei.x = ei.y = ei.w = ei.h = 0;
1473 _signal_anchor_geoms_do_things_with(wd, &ei);
1476 evas_object_smart_callback_call(data, SIG_ANCHOR_DOWN, &ei);
1480 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1482 Widget_Data *wd = elm_widget_data_get(data);
1483 Elm_Entry_Anchor_Info ei;
1487 p = emission + sizeof("nchor,mouse,up,");
1488 ei.button = strtol(p, &p2, 10);
1490 ei.x = ei.y = ei.w = ei.h = 0;
1492 _signal_anchor_geoms_do_things_with(wd, &ei);
1495 evas_object_smart_callback_call(data, SIG_ANCHOR_UP, &ei);
1499 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1501 Widget_Data *wd = elm_widget_data_get(data);
1502 Elm_Entry_Anchor_Info ei;
1506 p = emission + sizeof("nchor,mouse,clicked,");
1507 ei.button = strtol(p, &p2, 10);
1509 ei.x = ei.y = ei.w = ei.h = 0;
1511 _signal_anchor_geoms_do_things_with(wd, &ei);
1514 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1518 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1520 Widget_Data *wd = elm_widget_data_get(data);
1525 _signal_anchor_in(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,in,");
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_IN, &ei);
1541 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1543 Widget_Data *wd = elm_widget_data_get(data);
1544 Elm_Entry_Anchor_Info ei;
1546 ei.name = emission + sizeof("nchor,mouse,out,");
1548 ei.x = ei.y = ei.w = ei.h = 0;
1550 _signal_anchor_geoms_do_things_with(wd, &ei);
1553 evas_object_smart_callback_call(data, SIG_ANCHOR_OUT, &ei);
1557 _signal_key_enter(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_ACTIVATED, NULL);
1565 _signal_mouse_down(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_PRESS, NULL);
1573 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1575 Widget_Data *wd = elm_widget_data_get(data);
1577 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1581 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1583 Widget_Data *wd = elm_widget_data_get(data);
1585 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1588 #ifdef HAVE_ELEMENTARY_X
1590 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1592 Widget_Data *wd = elm_widget_data_get(data);
1593 Ecore_X_Event_Selection_Notify *ev = event;
1594 if (!wd) return ECORE_CALLBACK_PASS_ON;
1595 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1596 return ECORE_CALLBACK_PASS_ON;
1598 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1599 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1601 Ecore_X_Selection_Data_Text *text_data;
1603 text_data = ev->data;
1604 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1606 if (text_data->text)
1608 char *txt = _elm_util_text_to_mkup(text_data->text);
1612 elm_entry_entry_insert(data, txt);
1617 wd->selection_asked = EINA_FALSE;
1619 else if (ev->selection == ECORE_X_SELECTION_XDND)
1621 Ecore_X_Selection_Data_Text *text_data;
1623 text_data = ev->data;
1624 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1626 if (text_data->text)
1628 char *txt = _elm_util_text_to_mkup(text_data->text);
1632 /* Massive FIXME: this should be at the drag point */
1633 elm_entry_entry_insert(data, txt);
1638 wd->drag_selection_asked = EINA_FALSE;
1640 ecore_x_dnd_send_finished();
1643 return ECORE_CALLBACK_PASS_ON;
1647 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1649 Widget_Data *wd = elm_widget_data_get(data);
1650 Ecore_X_Event_Selection_Clear *ev = event;
1651 if (!wd) return ECORE_CALLBACK_PASS_ON;
1652 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1653 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1654 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1656 elm_entry_select_none(data);
1658 return ECORE_CALLBACK_PASS_ON;
1662 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1667 wd = elm_widget_data_get(obj);
1668 if (!wd) return EINA_FALSE;
1669 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1671 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1672 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1673 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1674 EDJE_CURSOR_MAIN,drop->x,drop->y);
1675 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1676 elm_entry_entry_insert(obj, drop->data);
1677 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1678 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1684 static Evas_Object *
1685 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1687 Widget_Data *wd = elm_widget_data_get(data);
1690 Elm_Entry_Item_Provider *ip;
1692 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1694 o = ip->func(ip->data, data, item);
1697 if (!strncmp(item, "file://", 7))
1699 const char *fname = item + 7;
1701 o = evas_object_image_filled_add(evas_object_evas_get(data));
1702 evas_object_image_file_set(o, fname, NULL);
1703 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1705 evas_object_show(o);
1710 o = edje_object_add(evas_object_evas_get(data));
1711 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1715 o = edje_object_add(evas_object_evas_get(data));
1716 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1717 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1722 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1724 Widget_Data *wd = elm_widget_data_get(data);
1726 Elm_Entry_Text_Filter *tf;
1728 if (type == EDJE_TEXT_FILTER_FORMAT)
1731 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1733 tf->func(tf->data, data, text);
1739 /* This function is used to insert text by chunks in jobs */
1741 _text_append_idler(void *data)
1745 Evas_Object *obj = (Evas_Object *) data;
1746 Widget_Data *wd = elm_widget_data_get(obj);
1747 if (wd->text) eina_stringshare_del(wd->text);
1749 wd->changed = EINA_TRUE;
1751 start = wd->append_text_position;
1752 if(start + _CHUNK_SIZE < wd->append_text_len)
1754 wd->append_text_position = (start + _CHUNK_SIZE);
1755 /* Go to the start of the nearest codepoint, because we don't want
1756 * to cut it in the middle */
1757 eina_unicode_utf8_get_prev(wd->append_text_left,
1758 &wd->append_text_position);
1762 wd->append_text_position = wd->append_text_len;
1765 backup = wd->append_text_left[wd->append_text_position];
1766 wd->append_text_left[wd->append_text_position] = '\0';
1768 edje_object_part_text_append(wd->ent, "elm.text",
1769 wd->append_text_left + start);
1771 wd->append_text_left[wd->append_text_position] = backup;
1773 /* If there's still more to go, renew the idler, else, cleanup */
1774 if (wd->append_text_position < wd->append_text_len)
1776 return ECORE_CALLBACK_RENEW;
1780 free(wd->append_text_left);
1781 wd->append_text_left = NULL;
1782 wd->append_text_idler = NULL;
1783 return ECORE_CALLBACK_CANCEL;
1788 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
1790 int i = 0, unit_size;
1791 int current_len = strlen(*text);
1792 char *new_text = *text;
1793 if (unit >= LENGTH_UNIT_LAST) return;
1796 if (*new_text == '<')
1798 while (*new_text != '>')
1801 if (!*new_text) break;
1808 if (*new_text == '&')
1810 while (*(new_text + index) != ';')
1813 if (!*(new_text + index)) break;
1817 index = evas_string_char_next_get(new_text, index, NULL);
1818 markup = malloc(index + 1);
1819 strncpy(markup, new_text, index);
1821 if (unit == LENGTH_UNIT_BYTE)
1822 unit_size = strlen(elm_entry_markup_to_utf8(markup));
1823 else if (unit == LENGTH_UNIT_CHAR)
1824 unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
1830 if (can_add < unit_size)
1834 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1840 strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
1841 current_len -= index;
1842 (*text)[current_len] = 0;
1847 can_add -= unit_size;
1852 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1856 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
1859 ELM_CHECK_WIDTYPE(obj, widtype);
1860 if (item && strcmp(item, "default")) return;
1861 Widget_Data *wd = elm_widget_data_get(obj);
1863 if (!entry) entry = "";
1864 if (wd->text) eina_stringshare_del(wd->text);
1866 wd->changed = EINA_TRUE;
1868 /* Clear currently pending job if there is one */
1869 if (wd->append_text_idler)
1871 ecore_idler_del(wd->append_text_idler);
1872 free(wd->append_text_left);
1873 wd->append_text_left = NULL;
1874 wd->append_text_idler = NULL;
1877 len = strlen(entry);
1878 /* Split to ~_CHUNK_SIZE chunks */
1879 if (len > _CHUNK_SIZE)
1881 wd->append_text_left = (char *) malloc(len + 1);
1884 /* If we decided to use the idler */
1885 if (wd->append_text_left)
1887 /* Need to clear the entry first */
1888 edje_object_part_text_set(wd->ent, "elm.text", "");
1889 memcpy(wd->append_text_left, entry, len + 1);
1890 wd->append_text_position = 0;
1891 wd->append_text_len = len;
1892 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
1896 edje_object_part_text_set(wd->ent, "elm.text", entry);
1901 _elm_entry_text_get(const Evas_Object *obj, const char *item)
1903 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1904 Widget_Data *wd = elm_widget_data_get(obj);
1905 if (item && strcmp(item, "default")) return NULL;
1907 if (!wd) return NULL;
1908 if (wd->text) return wd->text;
1909 text = edje_object_part_text_get(wd->ent, "elm.text");
1912 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1915 eina_stringshare_replace(&wd->text, text);
1920 elm_entry_add(Evas_Object *parent)
1922 Evas_Object *obj, *top;
1926 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1928 ELM_SET_WIDTYPE(widtype, "entry");
1929 elm_widget_type_set(obj, "entry");
1930 elm_widget_sub_object_add(parent, obj);
1931 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1932 elm_widget_data_set(obj, wd);
1933 elm_widget_del_hook_set(obj, _del_hook);
1934 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1935 elm_widget_theme_hook_set(obj, _theme_hook);
1936 elm_widget_disable_hook_set(obj, _disable_hook);
1937 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1938 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
1939 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1940 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1941 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1942 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1943 elm_widget_can_focus_set(obj, EINA_TRUE);
1944 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1945 elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
1946 elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
1948 wd->scroller = elm_smart_scroller_add(e);
1949 elm_widget_sub_object_add(obj, wd->scroller);
1950 elm_smart_scroller_widget_set(wd->scroller, obj);
1951 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
1952 elm_widget_style_get(obj));
1953 evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1954 evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
1955 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
1956 evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
1958 wd->linewrap = ELM_WRAP_WORD;
1959 wd->editable = EINA_TRUE;
1960 wd->disabled = EINA_FALSE;
1961 wd->context_menu = EINA_TRUE;
1962 wd->autosave = EINA_TRUE;
1963 wd->textonly = EINA_FALSE;
1965 wd->ent = edje_object_add(e);
1966 elm_widget_sub_object_add(obj, wd->ent);
1967 edje_object_item_provider_set(wd->ent, _get_item, obj);
1968 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1969 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1970 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1972 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1974 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1976 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1978 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1979 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1980 _signal_entry_changed, obj);
1981 edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
1982 _signal_preedit_changed, obj);
1983 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1984 _signal_selection_start, obj);
1985 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1986 _signal_selection_changed, obj);
1987 edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
1988 _signal_selection_all, obj);
1989 edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
1990 _signal_selection_none, obj);
1991 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1992 _signal_selection_cleared, obj);
1993 edje_object_signal_callback_add(wd->ent, "entry,paste,request,1", "elm.text",
1994 _signal_entry_paste_request, obj);
1995 edje_object_signal_callback_add(wd->ent, "entry,paste,request,3", "elm.text",
1996 _signal_entry_paste_request, obj);
1997 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1998 _signal_entry_cut_notify, obj);
1999 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2000 _signal_cursor_changed, obj);
2001 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2002 _signal_anchor_down, obj);
2003 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2004 _signal_anchor_up, obj);
2005 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2006 _signal_anchor_clicked, obj);
2007 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2008 _signal_anchor_move, obj);
2009 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2010 _signal_anchor_in, obj);
2011 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2012 _signal_anchor_out, obj);
2013 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2014 _signal_key_enter, obj);
2015 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2016 _signal_mouse_down, obj);
2017 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2018 _signal_mouse_clicked, obj);
2019 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2020 _signal_mouse_double, obj);
2021 edje_object_part_text_set(wd->ent, "elm.text", "");
2022 if (_elm_config->desktop_entry)
2023 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2024 elm_widget_resize_object_set(obj, wd->ent);
2027 #ifdef HAVE_ELEMENTARY_X
2028 top = elm_widget_top_get(obj);
2029 if ((top) && (elm_win_xwindow_get(top)))
2031 wd->sel_notify_handler =
2032 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2033 _event_selection_notify, obj);
2034 wd->sel_clear_handler =
2035 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2036 _event_selection_clear, obj);
2039 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2040 _drag_drop_cb, NULL);
2043 entries = eina_list_prepend(entries, obj);
2045 // module - find module for entry
2046 wd->api = _module(obj);
2047 // if found - hook in
2048 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2050 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2051 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2052 // TODO: and save some bytes, making descriptions per-class and not instance!
2053 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2058 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2060 ELM_CHECK_WIDTYPE(obj, widtype);
2061 Widget_Data *wd = elm_widget_data_get(obj);
2063 if (wd->single_line == single_line) return;
2064 wd->single_line = single_line;
2065 wd->linewrap = ELM_WRAP_NONE;
2066 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2070 if (wd->single_line)
2071 elm_smart_scroller_policy_set(wd->scroller,
2072 ELM_SMART_SCROLLER_POLICY_OFF,
2073 ELM_SMART_SCROLLER_POLICY_OFF);
2076 const Elm_Scroller_Policy map[3] =
2078 ELM_SMART_SCROLLER_POLICY_AUTO,
2079 ELM_SMART_SCROLLER_POLICY_ON,
2080 ELM_SMART_SCROLLER_POLICY_OFF
2082 elm_smart_scroller_policy_set(wd->scroller,
2091 elm_entry_single_line_get(const Evas_Object *obj)
2093 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2094 Widget_Data *wd = elm_widget_data_get(obj);
2095 if (!wd) return EINA_FALSE;
2096 return wd->single_line;
2100 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2102 ELM_CHECK_WIDTYPE(obj, widtype);
2103 Widget_Data *wd = elm_widget_data_get(obj);
2105 if (wd->password == password) return;
2106 wd->password = password;
2107 wd->single_line = EINA_TRUE;
2108 wd->linewrap = ELM_WRAP_NONE;
2113 elm_entry_password_get(const Evas_Object *obj)
2115 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2116 Widget_Data *wd = elm_widget_data_get(obj);
2117 if (!wd) return EINA_FALSE;
2118 return wd->password;
2122 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2124 _elm_entry_text_set(obj, NULL, entry);
2128 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2131 ELM_CHECK_WIDTYPE(obj, widtype);
2132 Widget_Data *wd = elm_widget_data_get(obj);
2134 if (!entry) entry = "";
2135 wd->changed = EINA_TRUE;
2137 len = strlen(entry);
2138 if (wd->append_text_left)
2141 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
2147 wd->append_text_left = tmpbuf;
2148 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
2149 wd->append_text_len += len;
2153 /* FIXME: Add chunked appending here (like in entry_set) */
2154 edje_object_part_text_append(wd->ent, "elm.text", entry);
2159 elm_entry_entry_get(const Evas_Object *obj)
2161 return _elm_entry_text_get(obj, NULL);
2165 elm_entry_is_empty(const Evas_Object *obj)
2167 /* FIXME: until there's support for that in textblock, we just check
2168 * to see if the there is text or not. */
2169 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2170 Widget_Data *wd = elm_widget_data_get(obj);
2171 const Evas_Object *tb;
2172 Evas_Textblock_Cursor *cur;
2174 if (!wd) return EINA_TRUE;
2175 /* It's a hack until we get the support suggested above.
2176 * We just create a cursor, point it to the begining, and then
2177 * try to advance it, if it can advance, the tb is not empty,
2178 * otherwise it is. */
2179 tb = edje_object_part_object_get(wd->ent, "elm.text");
2180 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2181 actually, ok for the time being, thsese hackish stuff will be removed
2182 once evas 1.0 is out*/
2183 evas_textblock_cursor_pos_set(cur, 0);
2184 ret = evas_textblock_cursor_char_next(cur);
2185 evas_textblock_cursor_free(cur);
2191 elm_entry_selection_get(const Evas_Object *obj)
2193 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2194 Widget_Data *wd = elm_widget_data_get(obj);
2195 if (!wd) return NULL;
2196 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2200 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2202 ELM_CHECK_WIDTYPE(obj, widtype);
2203 Widget_Data *wd = elm_widget_data_get(obj);
2205 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2206 wd->changed = EINA_TRUE;
2211 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2213 ELM_CHECK_WIDTYPE(obj, widtype);
2214 Widget_Data *wd = elm_widget_data_get(obj);
2216 if (wd->linewrap == wrap) return;
2218 wd->linewrap = wrap;
2223 elm_entry_line_wrap_get(const Evas_Object *obj)
2225 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2226 Widget_Data *wd = elm_widget_data_get(obj);
2227 if (!wd) return EINA_FALSE;
2228 return wd->linewrap;
2232 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2234 ELM_CHECK_WIDTYPE(obj, widtype);
2235 Widget_Data *wd = elm_widget_data_get(obj);
2237 if (wd->editable == editable) return;
2238 wd->editable = editable;
2241 #ifdef HAVE_ELEMENTARY_X
2243 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2245 elm_drop_target_del(obj);
2250 elm_entry_editable_get(const Evas_Object *obj)
2252 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2253 Widget_Data *wd = elm_widget_data_get(obj);
2254 if (!wd) return EINA_FALSE;
2255 return wd->editable;
2259 elm_entry_select_none(Evas_Object *obj)
2261 ELM_CHECK_WIDTYPE(obj, widtype);
2262 Widget_Data *wd = elm_widget_data_get(obj);
2266 wd->selmode = EINA_FALSE;
2267 if (!_elm_config->desktop_entry)
2268 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2269 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2271 wd->have_selection = EINA_FALSE;
2272 edje_object_part_text_select_none(wd->ent, "elm.text");
2276 elm_entry_select_all(Evas_Object *obj)
2278 ELM_CHECK_WIDTYPE(obj, widtype);
2279 Widget_Data *wd = elm_widget_data_get(obj);
2283 wd->selmode = EINA_FALSE;
2284 if (!_elm_config->desktop_entry)
2285 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2286 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2288 wd->have_selection = EINA_TRUE;
2289 edje_object_part_text_select_all(wd->ent, "elm.text");
2293 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2295 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2296 Widget_Data *wd = elm_widget_data_get(obj);
2297 if (!wd) return EINA_FALSE;
2298 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2303 elm_entry_cursor_next(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_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2312 elm_entry_cursor_prev(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_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2321 elm_entry_cursor_up(Evas_Object *obj)
2323 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2324 Widget_Data *wd = elm_widget_data_get(obj);
2325 if (!wd) return EINA_FALSE;
2326 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2330 elm_entry_cursor_down(Evas_Object *obj)
2332 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2333 Widget_Data *wd = elm_widget_data_get(obj);
2334 if (!wd) return EINA_FALSE;
2335 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2339 elm_entry_cursor_begin_set(Evas_Object *obj)
2341 ELM_CHECK_WIDTYPE(obj, widtype);
2342 Widget_Data *wd = elm_widget_data_get(obj);
2344 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2348 elm_entry_cursor_end_set(Evas_Object *obj)
2350 ELM_CHECK_WIDTYPE(obj, widtype);
2351 Widget_Data *wd = elm_widget_data_get(obj);
2355 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2358 elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
2359 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
2364 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2366 ELM_CHECK_WIDTYPE(obj, widtype);
2367 Widget_Data *wd = elm_widget_data_get(obj);
2369 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2373 elm_entry_cursor_line_end_set(Evas_Object *obj)
2375 ELM_CHECK_WIDTYPE(obj, widtype);
2376 Widget_Data *wd = elm_widget_data_get(obj);
2378 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2382 elm_entry_cursor_selection_begin(Evas_Object *obj)
2384 ELM_CHECK_WIDTYPE(obj, widtype);
2385 Widget_Data *wd = elm_widget_data_get(obj);
2387 edje_object_part_text_select_begin(wd->ent, "elm.text");
2391 elm_entry_cursor_selection_end(Evas_Object *obj)
2393 ELM_CHECK_WIDTYPE(obj, widtype);
2394 Widget_Data *wd = elm_widget_data_get(obj);
2396 edje_object_part_text_select_extend(wd->ent, "elm.text");
2400 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2402 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2403 Widget_Data *wd = elm_widget_data_get(obj);
2404 if (!wd) return EINA_FALSE;
2405 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2409 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2411 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2412 Widget_Data *wd = elm_widget_data_get(obj);
2413 if (!wd) return EINA_FALSE;
2414 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2418 elm_entry_cursor_content_get(const Evas_Object *obj)
2420 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2421 Widget_Data *wd = elm_widget_data_get(obj);
2422 if (!wd) return NULL;
2423 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2427 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2429 ELM_CHECK_WIDTYPE(obj, widtype);
2430 Widget_Data *wd = elm_widget_data_get(obj);
2432 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2433 edje_object_message_signal_process(wd->ent);
2437 elm_entry_cursor_pos_get(const Evas_Object *obj)
2439 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2440 Widget_Data *wd = elm_widget_data_get(obj);
2442 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2446 elm_entry_selection_cut(Evas_Object *obj)
2448 ELM_CHECK_WIDTYPE(obj, widtype);
2449 Widget_Data *wd = elm_widget_data_get(obj);
2451 _cut(obj, NULL, NULL);
2455 elm_entry_selection_copy(Evas_Object *obj)
2457 ELM_CHECK_WIDTYPE(obj, widtype);
2458 Widget_Data *wd = elm_widget_data_get(obj);
2460 _copy(obj, NULL, NULL);
2464 elm_entry_selection_paste(Evas_Object *obj)
2466 ELM_CHECK_WIDTYPE(obj, widtype);
2467 Widget_Data *wd = elm_widget_data_get(obj);
2469 _paste(obj, NULL, NULL);
2473 elm_entry_context_menu_clear(Evas_Object *obj)
2475 ELM_CHECK_WIDTYPE(obj, widtype);
2476 Widget_Data *wd = elm_widget_data_get(obj);
2477 Elm_Entry_Context_Menu_Item *it;
2479 EINA_LIST_FREE(wd->items, it)
2481 eina_stringshare_del(it->label);
2482 eina_stringshare_del(it->icon_file);
2483 eina_stringshare_del(it->icon_group);
2489 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)
2491 ELM_CHECK_WIDTYPE(obj, widtype);
2492 Widget_Data *wd = elm_widget_data_get(obj);
2493 Elm_Entry_Context_Menu_Item *it;
2495 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2497 wd->items = eina_list_append(wd->items, it);
2499 it->label = eina_stringshare_add(label);
2500 it->icon_file = eina_stringshare_add(icon_file);
2501 it->icon_type = icon_type;
2503 it->data = (void *)data;
2507 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2509 ELM_CHECK_WIDTYPE(obj, widtype);
2510 Widget_Data *wd = elm_widget_data_get(obj);
2512 if (wd->context_menu == !disabled) return;
2513 wd->context_menu = !disabled;
2517 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2519 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2520 Widget_Data *wd = elm_widget_data_get(obj);
2521 if (!wd) return EINA_FALSE;
2522 return !wd->context_menu;
2526 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2528 ELM_CHECK_WIDTYPE(obj, widtype);
2529 Widget_Data *wd = elm_widget_data_get(obj);
2531 EINA_SAFETY_ON_NULL_RETURN(func);
2532 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2536 wd->item_providers = eina_list_append(wd->item_providers, ip);
2540 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2542 ELM_CHECK_WIDTYPE(obj, widtype);
2543 Widget_Data *wd = elm_widget_data_get(obj);
2545 EINA_SAFETY_ON_NULL_RETURN(func);
2546 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2550 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2554 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2556 ELM_CHECK_WIDTYPE(obj, widtype);
2557 Widget_Data *wd = elm_widget_data_get(obj);
2559 Elm_Entry_Item_Provider *ip;
2561 EINA_SAFETY_ON_NULL_RETURN(func);
2562 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2564 if ((ip->func == func) && ((!data) || (ip->data == data)))
2566 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2574 elm_entry_text_filter_append(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2577 Elm_Entry_Text_Filter *tf;
2578 ELM_CHECK_WIDTYPE(obj, widtype);
2580 wd = elm_widget_data_get(obj);
2582 EINA_SAFETY_ON_NULL_RETURN(func);
2584 tf = _filter_new(func, data);
2587 wd->text_filters = eina_list_append(wd->text_filters, tf);
2591 elm_entry_text_filter_prepend(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 tf = _filter_new(func, data);
2604 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2608 elm_entry_text_filter_remove(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2612 Elm_Entry_Text_Filter *tf;
2613 ELM_CHECK_WIDTYPE(obj, widtype);
2615 wd = elm_widget_data_get(obj);
2617 EINA_SAFETY_ON_NULL_RETURN(func);
2619 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2621 if ((tf->func == func) && ((!data) || (tf->data == data)))
2623 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2631 elm_entry_markup_to_utf8(const char *s)
2633 char *ss = _elm_util_mkup_to_text(s);
2634 if (!ss) ss = strdup("");
2639 elm_entry_utf8_to_markup(const char *s)
2641 char *ss = _elm_util_text_to_mkup(s);
2642 if (!ss) ss = strdup("");
2647 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2649 Elm_Entry_Filter_Limit_Size *lim = data;
2652 const char *(*text_get)(const Evas_Object *);
2653 const char *widget_type;
2655 EINA_SAFETY_ON_NULL_RETURN(data);
2656 EINA_SAFETY_ON_NULL_RETURN(entry);
2657 EINA_SAFETY_ON_NULL_RETURN(text);
2659 /* hack. I don't want to copy the entire function to work with
2661 widget_type = elm_widget_type_get(entry);
2662 if (!strcmp(widget_type, "entry"))
2663 text_get = elm_entry_entry_get;
2667 current = elm_entry_markup_to_utf8(text_get(entry));
2669 if (lim->max_char_count > 0)
2671 len = evas_string_char_len_get(current);
2672 if (len >= lim->max_char_count)
2674 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2680 newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
2681 if ((len + newlen) > lim->max_char_count)
2682 _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
2684 else if (lim->max_byte_count > 0)
2686 len = strlen(current);
2687 if (len >= lim->max_byte_count)
2689 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2695 newlen = strlen(elm_entry_markup_to_utf8(*text));
2696 if ((len + newlen) > lim->max_byte_count)
2697 _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
2703 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2705 Elm_Entry_Filter_Accept_Set *as = data;
2709 int read_idx, last_read_idx = 0, read_char;
2711 EINA_SAFETY_ON_NULL_RETURN(data);
2712 EINA_SAFETY_ON_NULL_RETURN(text);
2714 if ((!as->accepted) && (!as->rejected))
2720 goes_in = EINA_TRUE;
2725 goes_in = EINA_FALSE;
2729 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2732 int cmp_idx, cmp_char;
2733 Eina_Bool in_set = EINA_FALSE;
2735 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2738 if (read_char == cmp_char)
2743 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2745 if (in_set == goes_in)
2747 int size = read_idx - last_read_idx;
2748 const char *src = (*text) + last_read_idx;
2750 memcpy(insert, *text + last_read_idx, size);
2753 last_read_idx = read_idx;
2754 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2760 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2762 ELM_CHECK_WIDTYPE(obj, widtype);
2763 Widget_Data *wd = elm_widget_data_get(obj);
2765 if (wd->delay_write)
2767 ecore_timer_del(wd->delay_write);
2768 wd->delay_write = NULL;
2770 if (wd->autosave) _save(obj);
2771 eina_stringshare_replace(&wd->file, file);
2772 wd->format = format;
2777 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2779 ELM_CHECK_WIDTYPE(obj, widtype);
2780 Widget_Data *wd = elm_widget_data_get(obj);
2782 if (file) *file = wd->file;
2783 if (format) *format = wd->format;
2787 elm_entry_file_save(Evas_Object *obj)
2789 ELM_CHECK_WIDTYPE(obj, widtype);
2790 Widget_Data *wd = elm_widget_data_get(obj);
2792 if (wd->delay_write)
2794 ecore_timer_del(wd->delay_write);
2795 wd->delay_write = NULL;
2798 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2802 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2804 ELM_CHECK_WIDTYPE(obj, widtype);
2805 Widget_Data *wd = elm_widget_data_get(obj);
2807 wd->autosave = !!autosave;
2811 elm_entry_autosave_get(const Evas_Object *obj)
2813 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2814 Widget_Data *wd = elm_widget_data_get(obj);
2815 if (!wd) return EINA_FALSE;
2816 return wd->autosave;
2820 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2822 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2823 ELM_CHECK_WIDTYPE(obj, widtype);
2824 Widget_Data *wd = elm_widget_data_get(obj);
2826 textonly = !!textonly;
2827 if (wd->textonly == textonly) return;
2828 wd->textonly = !!textonly;
2829 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2830 #ifdef HAVE_ELEMENTARY_X
2831 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2836 elm_entry_cnp_textonly_get(const Evas_Object *obj)
2838 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2839 Widget_Data *wd = elm_widget_data_get(obj);
2840 if (!wd) return EINA_FALSE;
2841 return wd->textonly;
2845 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
2847 ELM_CHECK_WIDTYPE(obj, widtype);
2848 Widget_Data *wd = elm_widget_data_get(obj);
2851 if (wd->scroll == scroll) return;
2852 wd->scroll = scroll;
2855 elm_widget_sub_object_del(obj, wd->scroller);
2856 elm_widget_resize_object_set(obj, wd->scroller);
2857 elm_widget_sub_object_add(obj, wd->ent);
2858 elm_smart_scroller_child_set(wd->scroller, wd->ent);
2859 evas_object_show(wd->scroller);
2860 elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
2864 elm_smart_scroller_child_set(wd->scroller, NULL);
2865 elm_widget_sub_object_del(obj, wd->ent);
2866 elm_widget_resize_object_set(obj, wd->ent);
2867 evas_object_smart_member_add(wd->scroller, obj);
2868 elm_widget_sub_object_add(obj, wd->scroller);
2869 evas_object_hide(wd->scroller);
2870 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
2877 elm_entry_scrollable_get(const Evas_Object *obj)
2879 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2880 Widget_Data *wd = elm_widget_data_get(obj);
2881 if (!wd) return EINA_FALSE;
2886 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
2888 ELM_CHECK_WIDTYPE(obj, widtype);
2889 Widget_Data *wd = elm_widget_data_get(obj);
2892 EINA_SAFETY_ON_NULL_RETURN(icon);
2893 if (wd->icon == icon) return;
2894 if (wd->icon) evas_object_del(wd->icon);
2896 edje = elm_smart_scroller_edje_object_get(wd->scroller);
2898 edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
2899 edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
2904 elm_entry_icon_get(const Evas_Object *obj)
2906 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2907 Widget_Data *wd = elm_widget_data_get(obj);
2908 if (!wd) return NULL;
2913 elm_entry_icon_unset(Evas_Object *obj)
2915 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2916 Widget_Data *wd = elm_widget_data_get(obj);
2917 Evas_Object *ret = NULL;
2918 if (!wd) return NULL;
2921 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
2922 if (!edje) return NULL;
2924 edje_object_part_unswallow(edje, wd->icon);
2925 edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
2933 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
2935 ELM_CHECK_WIDTYPE(obj, widtype);
2936 Widget_Data *wd = elm_widget_data_get(obj);
2937 if ((!wd) || (!wd->icon)) return;
2939 evas_object_hide(wd->icon);
2941 evas_object_show(wd->icon);
2946 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
2948 ELM_CHECK_WIDTYPE(obj, widtype);
2949 Widget_Data *wd = elm_widget_data_get(obj);
2952 EINA_SAFETY_ON_NULL_RETURN(end);
2953 if (wd->end == end) return;
2954 if (wd->end) evas_object_del(wd->end);
2956 edje = elm_smart_scroller_edje_object_get(wd->scroller);
2958 edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
2959 edje_object_signal_emit(edje, "elm,action,show,end", "elm");
2964 elm_entry_end_get(const Evas_Object *obj)
2966 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2967 Widget_Data *wd = elm_widget_data_get(obj);
2968 if (!wd) return NULL;
2973 elm_entry_end_unset(Evas_Object *obj)
2975 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2976 Widget_Data *wd = elm_widget_data_get(obj);
2977 Evas_Object *ret = NULL;
2978 if (!wd) return NULL;
2981 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
2982 if (!edje) return NULL;
2984 edje_object_part_unswallow(edje, wd->end);
2985 edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
2993 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
2995 ELM_CHECK_WIDTYPE(obj, widtype);
2996 Widget_Data *wd = elm_widget_data_get(obj);
2997 if ((!wd) || (!wd->end)) return;
2999 evas_object_hide(wd->end);
3001 evas_object_show(wd->end);
3006 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
3008 ELM_CHECK_WIDTYPE(obj, widtype);
3009 Widget_Data *wd = elm_widget_data_get(obj);
3010 const Elm_Scroller_Policy map[3] =
3012 ELM_SMART_SCROLLER_POLICY_AUTO,
3013 ELM_SMART_SCROLLER_POLICY_ON,
3014 ELM_SMART_SCROLLER_POLICY_OFF
3019 elm_smart_scroller_policy_set(wd->scroller,
3025 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3027 ELM_CHECK_WIDTYPE(obj, widtype);
3028 Widget_Data *wd = elm_widget_data_get(obj);
3030 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
3034 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3036 ELM_CHECK_WIDTYPE(obj, widtype);
3037 Widget_Data *wd = elm_widget_data_get(obj);
3039 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);