2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 #include <Elementary.h>
6 #include "elm_module_priv.h"
8 * @defgroup Entry Entry
11 * An entry is a convenience widget which shows
12 * a box that the user can enter text into. Unlike a
13 * @ref Scrolled_Entry widget, entries DO NOT scroll with user
14 * input. Entry widgets are capable of expanding past the
15 * boundaries of the window, thus resizing the window to its
18 * You can also insert "items" in the entry with:
20 * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
22 * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
23 * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry
24 * supports a list of emoticon names by default. These are:
27 * - emoticon/angry-shout
28 * - emoticon/crazy-laugh
29 * - emoticon/evil-laugh
31 * - emoticon/goggle-smile
33 * - emoticon/grumpy-smile
35 * - emoticon/guilty-smile
37 * - emoticon/half-smile
38 * - emoticon/happy-panting
40 * - emoticon/indifferent
42 * - emoticon/knowing-grin
44 * - emoticon/little-bit-sorry
45 * - emoticon/love-lots
47 * - emoticon/minimal-smile
48 * - emoticon/not-happy
49 * - emoticon/not-impressed
51 * - emoticon/opensmile
54 * - emoticon/squint-laugh
55 * - emoticon/surprised
56 * - emoticon/suspicious
57 * - emoticon/tongue-dangling
58 * - emoticon/tongue-poke
61 * - emoticon/very-sorry
67 * These are built-in currently, but you can add your own item provieer that
68 * can create inlined objects in the text and fill the space allocated to the
69 * item with a custom object of your own.
71 * See the entry test for some more examples of use of this.
73 * Signals that you can add callbacks for are:
74 * - "changed" - The text within the entry was changed
75 * - "activated" - The entry has received focus and the cursor
76 * - "press" - The entry has been clicked
77 * - "longpressed" - The entry has been clicked for a couple seconds
78 * - "clicked" - The entry has been clicked
79 * - "clicked,double" - The entry has been double clicked
80 * - "focused" - The entry has received focus
81 * - "unfocused" - The entry has lost focus
82 * - "selection,paste" - A paste action has occurred
83 * - "selection,copy" - A copy action has occurred
84 * - "selection,cut" - A cut action has occurred
85 * - "selection,start" - A selection has begun
86 * - "selection,changed" - The selection has changed
87 * - "selection,cleared" - The selection has been cleared
88 * - "cursor,changed" - The cursor has changed
89 * - "anchor,clicked" - The anchor has been clicked
92 typedef struct _Mod_Api Mod_Api;
94 typedef struct _Widget_Data Widget_Data;
95 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
100 Evas_Object *popup;/*copy paste UI - elm_popup*/
101 Evas_Object *ctxpopup;/*copy paste UI - elm_ctxpopup*/
103 Evas_Object *hoversel;
104 Ecore_Job *deferred_recalc_job;
105 Ecore_Event_Handler *sel_notify_handler;
106 Ecore_Event_Handler *sel_clear_handler;
107 Ecore_Timer *longpress_timer;
108 /* Only for clipboard */
112 int ellipsis_threshold;
114 Evas_Coord downx, downy;
115 Evas_Coord cx, cy, cw, ch;
117 Eina_List *item_providers;
118 Ecore_Job *hovdeljob;
119 Mod_Api *api; // module api if supplied
121 Eina_Bool changed : 1;
122 Eina_Bool linewrap : 1;
123 Eina_Bool char_linewrap : 1;
124 Eina_Bool single_line : 1;
125 Eina_Bool password : 1;
126 Eina_Bool show_last_character : 1;
127 Eina_Bool editable : 1;
128 Eina_Bool selection_asked : 1;
129 Eina_Bool have_selection : 1;
130 Eina_Bool selmode : 1;
131 Eina_Bool deferred_cur : 1;
132 Eina_Bool disabled : 1;
133 Eina_Bool context_menu : 1;
134 Eina_Bool bgcolor : 1;
135 Eina_Bool ellipsis : 1;
136 Eina_Bool autoreturnkey : 1;
137 Eina_Bool input_panel_enable : 1;
138 Eina_Bool autocapitalize : 1;
139 Elm_Input_Panel_Layout input_panel_layout;
140 Eina_Bool autoperiod : 1;
143 struct _Elm_Entry_Item_Provider
145 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
149 static const char *widtype = NULL;
150 static void _del_hook(Evas_Object *obj);
151 static void _theme_hook(Evas_Object *obj);
152 static void _disable_hook(Evas_Object *obj);
153 static void _sizing_eval(Evas_Object *obj);
154 static void _on_focus_hook(void *data, Evas_Object *obj);
155 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
156 static const char *_getbase(Evas_Object *obj);
157 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
158 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
159 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
160 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
161 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
162 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
163 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
164 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
165 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
166 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
167 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
168 static int _is_width_over(Evas_Object *obj);
169 static void _ellipsis_entry_to_width(Evas_Object *obj);
170 static void _reverse_ellipsis_entry(Evas_Object *obj);
171 static int _textinput_control_function(void *data,void *input_data);
172 static int _entry_length_get(Evas_Object *obj);
174 static const char SIG_CHANGED[] = "changed";
175 static const char SIG_ACTIVATED[] = "activated";
176 static const char SIG_PRESS[] = "press";
177 static const char SIG_LONGPRESSED[] = "longpressed";
178 static const char SIG_CLICKED[] = "clicked";
179 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
180 static const char SIG_FOCUSED[] = "focused";
181 static const char SIG_UNFOCUSED[] = "unfocused";
182 static const char SIG_SELECTION_PASTE[] = "selection,paste";
183 static const char SIG_SELECTION_COPY[] = "selection,copy";
184 static const char SIG_SELECTION_CUT[] = "selection,cut";
185 static const char SIG_SELECTION_START[] = "selection,start";
186 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
187 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
188 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
189 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
190 static const Evas_Smart_Cb_Description _signals[] = {
194 {SIG_LONGPRESSED, ""},
196 {SIG_CLICKED_DOUBLE, ""},
199 {SIG_SELECTION_PASTE, ""},
200 {SIG_SELECTION_COPY, ""},
201 {SIG_SELECTION_CUT, ""},
202 {SIG_SELECTION_START, ""},
203 {SIG_SELECTION_CHANGED, ""},
204 {SIG_SELECTION_CLEARED, ""},
205 {SIG_CURSOR_CHANGED, ""},
206 {SIG_ANCHOR_CLICKED, ""},
210 static Eina_List *entries = NULL;
214 void (*obj_hook) (Evas_Object *obj);
215 void (*obj_unhook) (Evas_Object *obj);
216 void (*obj_longpress) (Evas_Object *obj);
217 void (*obj_mouseup) (Evas_Object *obj);
221 _module(Evas_Object *obj __UNUSED__)
223 static Elm_Module *m = NULL;
224 if (m) goto ok; // already found - just use
225 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
227 m->api = malloc(sizeof(Mod_Api));
228 if (!m->api) return NULL;
229 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
230 _elm_module_symbol_get(m, "obj_hook");
231 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
232 _elm_module_symbol_get(m, "obj_unhook");
233 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
234 _elm_module_symbol_get(m, "obj_longpress");
235 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
236 _elm_module_symbol_get(m, "obj_mouseup");
237 ok: // ok - return api
242 _del_hook(Evas_Object *obj)
244 Widget_Data *wd = elm_widget_data_get(obj);
245 Elm_Entry_Context_Menu_Item *it;
246 Elm_Entry_Item_Provider *ip;
248 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
249 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
251 entries = eina_list_remove(entries, obj);
252 #ifdef HAVE_ELEMENTARY_X
253 ecore_event_handler_del(wd->sel_notify_handler);
254 ecore_event_handler_del(wd->sel_clear_handler);
256 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
257 if (wd->text) eina_stringshare_del(wd->text);
258 if (wd->bg) evas_object_del(wd->bg);
259 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
260 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
261 EINA_LIST_FREE(wd->items, it)
263 eina_stringshare_del(it->label);
264 eina_stringshare_del(it->icon_file);
265 eina_stringshare_del(it->icon_group);
268 EINA_LIST_FREE(wd->item_providers, ip)
276 _theme_hook(Evas_Object *obj)
278 Widget_Data *wd = elm_widget_data_get(obj);
280 Ecore_IMF_Context *ic;
282 t = eina_stringshare_add(elm_entry_entry_get(obj));
283 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
284 elm_entry_entry_set(obj, t);
285 eina_stringshare_del(t);
286 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
287 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
288 // edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
289 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
291 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
294 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
301 _disable_hook(Evas_Object *obj)
303 Widget_Data *wd = elm_widget_data_get(obj);
305 if (elm_widget_disabled_get(obj))
307 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
308 wd->disabled = EINA_TRUE;
312 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
313 wd->disabled = EINA_FALSE;
318 _elm_win_recalc_job(void *data)
320 Widget_Data *wd = elm_widget_data_get(data);
321 Evas_Coord minw = -1, minh = -1, maxh = -1;
322 Evas_Coord resw, resh, minminw;
324 wd->deferred_recalc_job = NULL;
325 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
328 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
329 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
331 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
332 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
333 evas_object_size_hint_min_set(data, minminw, minh);
334 if (wd->single_line) maxh = minh;
335 evas_object_size_hint_max_set(data, -1, maxh);
336 if (wd->deferred_cur)
337 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
341 _sizing_eval(Evas_Object *obj)
343 Widget_Data *wd = elm_widget_data_get(obj);
344 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
345 Evas_Coord resw, resh;
347 if (wd->linewrap || wd->char_linewrap)
349 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
350 if ((resw == wd->lastw) && (!wd->changed)) return;
351 wd->changed = EINA_FALSE;
353 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
354 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
358 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
359 edje_object_size_min_calc(wd->ent, &minw, &minh);
360 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
361 evas_object_size_hint_min_set(obj, minw, minh);
362 if (wd->single_line) maxh = minh;
363 evas_object_size_hint_max_set(obj, maxw, maxh);
365 if (wd->ellipsis && wd->single_line)
367 if (_is_width_over(obj))
368 _ellipsis_entry_to_width(obj);
369 else if (wd->ellipsis_threshold > 1 && _entry_length_get(obj) < wd->ellipsis_threshold)
370 _reverse_ellipsis_entry(obj);
376 _check_enable_returnkey(Evas_Object *obj)
378 Widget_Data *wd = elm_widget_data_get(obj);
381 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
384 if (!wd->autoreturnkey) return;
386 if (_entry_length_get(obj) == 0)
388 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
392 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
397 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
399 Widget_Data *wd = elm_widget_data_get(obj);
400 Evas_Object *top = elm_widget_top_get(obj);
402 if (!wd->editable) return;
403 if (elm_widget_focus_get(obj))
405 evas_object_focus_set(wd->ent, 1);
406 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
408 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
412 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
415 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
416 _check_enable_returnkey(obj);
420 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
421 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", "");
422 evas_object_focus_set(wd->ent, 0);
423 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
424 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
429 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
431 Widget_Data *wd = elm_widget_data_get(obj);
433 edje_object_signal_emit(wd->ent, emission, source);
437 _hoversel_position(Evas_Object *obj)
439 Widget_Data *wd = elm_widget_data_get(obj);
440 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
442 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
443 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
445 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
456 evas_object_move(wd->hoversel, x + cx, y + cy);
457 evas_object_resize(wd->hoversel, cw, ch);
461 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
463 Widget_Data *wd = elm_widget_data_get(data);
465 if (wd->hoversel) _hoversel_position(data);
469 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
471 Widget_Data *wd = elm_widget_data_get(data);
473 if (wd->linewrap || wd->char_linewrap)
477 if (wd->hoversel) _hoversel_position(data);
478 // Evas_Coord ww, hh;
479 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
483 _hover_del(void *data)
485 Widget_Data *wd = elm_widget_data_get(data);
490 evas_object_del(wd->hoversel);
493 wd->hovdeljob = NULL;
497 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
499 Widget_Data *wd = elm_widget_data_get(data);
501 if (wd->hoversel) evas_object_hide(wd->hoversel);
505 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
507 elm_widget_scroll_freeze_pop(data);
508 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
509 wd->hovdeljob = ecore_job_add(_hover_del, data);
513 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
515 Widget_Data *wd = elm_widget_data_get(data);
517 wd->selmode = EINA_TRUE;
518 edje_object_part_text_select_none(wd->ent, "elm.text");
520 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
521 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
522 elm_widget_scroll_hold_push(data);
526 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
528 Widget_Data *wd = elm_widget_data_get(data);
530 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
531 if (wd->sel_notify_handler)
533 #ifdef HAVE_ELEMENTARY_X
534 wd->selection_asked = EINA_TRUE;
535 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_MARKUP, data);
541 _store_selection(enum _elm_sel_type seltype, Evas_Object *obj)
543 Widget_Data *wd = elm_widget_data_get(obj);
547 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
548 elm_selection_set(seltype, obj, ELM_SEL_MARKUP, sel);
549 if (seltype == ELM_SEL_CLIPBOARD)
550 eina_stringshare_replace(&wd->cut_sel, sel);
554 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
556 Widget_Data *wd = elm_widget_data_get(data);
559 wd->selmode = EINA_FALSE;
560 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
561 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
562 elm_widget_scroll_hold_pop(data);
563 _store_selection(ELM_SEL_CLIPBOARD, data);
564 edje_object_part_text_insert(wd->ent, "elm.text", "");
565 edje_object_part_text_select_none(wd->ent, "elm.text");
569 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
571 Widget_Data *wd = elm_widget_data_get(data);
573 wd->selmode = EINA_FALSE;
574 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
575 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
576 elm_widget_scroll_hold_pop(data);
577 _store_selection(ELM_SEL_CLIPBOARD, data);
578 // edje_object_part_text_select_none(wd->ent, "elm.text");
582 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
584 Widget_Data *wd = elm_widget_data_get(data);
586 wd->selmode = EINA_FALSE;
587 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
588 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
589 elm_widget_scroll_hold_pop(data);
590 edje_object_part_text_select_none(wd->ent, "elm.text");
594 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
596 Elm_Entry_Context_Menu_Item *it = data;
597 Evas_Object *obj2 = it->obj;
598 if (it->func) it->func(it->data, obj2, NULL);
602 _long_press(void *data)
604 Widget_Data *wd = elm_widget_data_get(data);
607 const Elm_Entry_Context_Menu_Item *it;
608 if (!wd) return ECORE_CALLBACK_CANCEL;
609 if ((wd->api) && (wd->api->obj_longpress))
611 wd->api->obj_longpress(data);
613 else if (wd->context_menu)
615 const char *context_menu_orientation;
617 if (wd->hoversel) evas_object_del(wd->hoversel);
618 else elm_widget_scroll_freeze_push(data);
619 wd->hoversel = elm_hoversel_add(data);
620 context_menu_orientation = edje_object_data_get
621 (wd->ent, "context_menu_orientation");
622 if ((context_menu_orientation) &&
623 (!strcmp(context_menu_orientation, "horizontal")))
624 elm_hoversel_horizontal_set(wd->hoversel, 1);
625 elm_object_style_set(wd->hoversel, "entry");
626 elm_widget_sub_object_add(data, wd->hoversel);
627 elm_hoversel_label_set(wd->hoversel, "Text");
628 top = elm_widget_top_get(data);
629 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
630 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
634 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
636 if (1) // need way to detect if someone has a selection
639 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
647 if (wd->have_selection)
649 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
652 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
655 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
659 EINA_LIST_FOREACH(wd->items, l, it)
661 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
662 it->icon_type, _item_clicked, it);
666 _hoversel_position(data);
667 evas_object_show(wd->hoversel);
668 elm_hoversel_hover_begin(wd->hoversel);
670 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
671 edje_object_part_text_select_abort(wd->ent, "elm.text");
673 wd->longpress_timer = NULL;
674 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
675 return ECORE_CALLBACK_CANCEL;
679 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
681 Widget_Data *wd = elm_widget_data_get(data);
682 Evas_Event_Mouse_Down *ev = event_info;
684 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
685 if (ev->button != 1) return;
686 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
687 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
688 wd->longpress_timer = ecore_timer_add(1.0, _long_press, data);
689 wd->downx = ev->canvas.x;
690 wd->downy = ev->canvas.y;
694 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
696 Widget_Data *wd = elm_widget_data_get(data);
697 Evas_Event_Mouse_Up *ev = event_info;
699 if (ev->button != 1) return;
700 if ((wd->api) && (wd->api->obj_mouseup))
702 wd->api->obj_mouseup(data);
704 if (wd->longpress_timer)
706 ecore_timer_del(wd->longpress_timer);
707 wd->longpress_timer = NULL;
712 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
714 Widget_Data *wd = elm_widget_data_get(data);
715 Evas_Event_Mouse_Move *ev = event_info;
719 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
721 if (wd->longpress_timer)
723 ecore_timer_del(wd->longpress_timer);
724 wd->longpress_timer = NULL;
727 else if (wd->longpress_timer)
731 dx = wd->downx - ev->cur.canvas.x;
733 dy = wd->downy - ev->cur.canvas.y;
736 ((_elm_config->finger_size / 2) *
737 (_elm_config->finger_size / 2)))
739 ecore_timer_del(wd->longpress_timer);
740 wd->longpress_timer = NULL;
744 else if (wd->longpress_timer)
748 dx = wd->downx - ev->cur.canvas.x;
750 dy = wd->downy - ev->cur.canvas.y;
753 ((_elm_config->finger_size / 2) *
754 (_elm_config->finger_size / 2)))
756 ecore_timer_del(wd->longpress_timer);
757 wd->longpress_timer = NULL;
763 _getbase(Evas_Object *obj)
765 Widget_Data *wd = elm_widget_data_get(obj);
766 if (!wd) return "base";
769 if((wd->password)&&(wd->show_last_character)) return "custom-password";
770 else if(wd->password) return "base-password";
773 if (wd->single_line) return "base-single";
776 if (wd->linewrap) return "base";
777 else if (wd->char_linewrap) return "base-charwrap";
778 else return "base-nowrap";
784 if((wd->password)&&(wd->show_last_character)) return "custom-password";
785 else if(wd->password) return "base-password";
788 if (wd->single_line) return "base-single-noedit";
791 if (wd->linewrap) return "base-noedit";
792 else if (wd->char_linewrap) return "base-noedit-charwrap";
793 else return "base-nowrap-noedit";
801 _str_append(char *str, const char *txt, int *len, int *alloc)
803 int txt_len = strlen(txt);
805 if (txt_len <= 0) return str;
806 if ((*len + txt_len) >= *alloc)
811 alloc2 = *alloc + txt_len + 128;
812 str2 = realloc(str, alloc2);
813 if (!str2) return str;
817 strcpy(str + *len, txt);
822 /*FIXME: Sholud be implemented somewhere else, it really depends on the context
823 * because some markups can be implemented otherwise according to style.
824 * probably doing it in textblock and making it translate according to it's
825 * style is correct. */
827 _strncpy(char* dest, const char* src, size_t count)
831 ERR( "dest is NULL" );
836 ERR( "src is NULL" );
841 ERR( "count is smaller than 0" );
845 return strncpy( dest, src, count );
849 _mkup_to_text(const char *mkup)
852 int str_len = 0, str_alloc = 0;
854 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
856 if (!mkup) return NULL;
858 tag_start = tag_end = esc_start = esc_end = NULL;
863 if (((p!=NULL)&&(*p == 0)) ||
864 (tag_end) || (esc_end) ||
865 (tag_start) || (esc_start))
871 ttag = malloc(tag_end - tag_start);
874 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
875 ttag[tag_end - tag_start - 1] = 0;
876 if (!strcmp(ttag, "br"))
877 str = _str_append(str, "\n", &str_len, &str_alloc);
878 else if (!strcmp(ttag, "\n"))
879 str = _str_append(str, "\n", &str_len, &str_alloc);
880 else if (!strcmp(ttag, "\\n"))
881 str = _str_append(str, "\n", &str_len, &str_alloc);
882 else if (!strcmp(ttag, "\t"))
883 str = _str_append(str, "\t", &str_len, &str_alloc);
884 else if (!strcmp(ttag, "\\t"))
885 str = _str_append(str, "\t", &str_len, &str_alloc);
886 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
887 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
890 tag_start = tag_end = NULL;
894 ts = malloc(esc_end - esc_start + 1);
898 _strncpy(ts, esc_start, esc_end - esc_start);
899 ts[esc_end - esc_start] = 0;
900 esc = evas_textblock_escape_string_get(ts);
902 str = _str_append(str, esc, &str_len, &str_alloc);
905 esc_start = esc_end = NULL;
907 else if ((p!=NULL)&&(*p == 0))
909 ts = malloc(p - s + 1);
912 _strncpy(ts, s, p - s);
914 str = _str_append(str, ts, &str_len, &str_alloc);
920 if ((p!=NULL)&&(*p == '<'))
926 ts = malloc(p - s + 1);
929 _strncpy(ts, s, p - s);
931 str = _str_append(str, ts, &str_len, &str_alloc);
937 else if ((p!=NULL)&&(*p == '>'))
945 else if ((p!=NULL)&&(*p == '&'))
951 ts = malloc(p - s + 1);
954 _strncpy(ts, s, p - s);
956 str = _str_append(str, ts, &str_len, &str_alloc);
962 else if ((p!=NULL)&&(*p == ';'))
976 _entry_length_get(Evas_Object *obj)
979 const char *str = elm_entry_entry_get(obj);
982 char *plain_str = _mkup_to_text(str);
983 if (!plain_str) return 0;
985 len = strlen(plain_str);
992 _text_to_mkup(const char *text)
995 int str_len = 0, str_alloc = 0;
996 int ch, pos = 0, pos2 = 0;
998 if (!text) return NULL;
1002 pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
1003 if ((ch <= 0) || (pos2 <= 0)) break;
1005 str = _str_append(str, "<br>", &str_len, &str_alloc);
1006 else if (ch == '\t')
1007 str = _str_append(str, "<\t>", &str_len, &str_alloc);
1009 str = _str_append(str, "<", &str_len, &str_alloc);
1011 str = _str_append(str, ">", &str_len, &str_alloc);
1013 str = _str_append(str, "&", &str_len, &str_alloc);
1018 _strncpy(tstr, text + pos, pos2 - pos);
1019 tstr[pos2 - pos] = 0;
1020 str = _str_append(str, tstr, &str_len, &str_alloc);
1027 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1029 Widget_Data *wd = elm_widget_data_get(data);
1031 wd->changed = EINA_TRUE;
1033 if (wd->text) eina_stringshare_del(wd->text);
1035 _check_enable_returnkey(data);
1036 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1040 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1042 Widget_Data *wd = elm_widget_data_get(data);
1046 EINA_LIST_FOREACH(entries, l, entry)
1048 if (entry != data) elm_entry_select_none(entry);
1050 wd->have_selection = EINA_TRUE;
1051 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1052 #ifdef HAVE_ELEMENTARY_X
1053 if (wd->sel_notify_handler)
1055 const char *txt = elm_entry_selection_get(data);
1058 top = elm_widget_top_get(data);
1059 if ((top) && (elm_win_xwindow_get(top)))
1060 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP, txt);
1066 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1068 Widget_Data *wd = elm_widget_data_get(data);
1070 wd->have_selection = EINA_TRUE;
1071 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1072 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_MARKUP,
1073 elm_entry_selection_get(data));
1077 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1079 Widget_Data *wd = elm_widget_data_get(data);
1081 if (!wd->have_selection) return;
1082 wd->have_selection = EINA_FALSE;
1083 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1084 if (wd->sel_notify_handler)
1088 #ifdef HAVE_ELEMENTARY_X
1091 top = elm_widget_top_get(data);
1092 if ((top) && (elm_win_xwindow_get(top)))
1093 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP,
1096 eina_stringshare_del(wd->cut_sel);
1101 #ifdef HAVE_ELEMENTARY_X
1104 top = elm_widget_top_get(data);
1105 if ((top) && (elm_win_xwindow_get(top)))
1106 elm_selection_clear(ELM_SEL_PRIMARY, data);
1113 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1115 Widget_Data *wd = elm_widget_data_get(data);
1117 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1118 if (wd->sel_notify_handler)
1120 #ifdef HAVE_ELEMENTARY_X
1123 top = elm_widget_top_get(data);
1124 if ((top) && (elm_win_xwindow_get(top)))
1126 wd->selection_asked = EINA_TRUE;
1127 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_MARKUP, data);
1134 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1136 Widget_Data *wd = elm_widget_data_get(data);
1138 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1139 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1140 elm_entry_selection_get(data));
1144 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1146 Widget_Data *wd = elm_widget_data_get(data);
1148 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1149 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1150 elm_entry_selection_get(data));
1151 edje_object_part_text_insert(wd->ent, "elm.text", "");
1152 wd->changed = EINA_TRUE;
1157 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1159 Widget_Data *wd = elm_widget_data_get(data);
1160 Evas_Coord cx, cy, cw, ch;
1162 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1163 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1164 &cx, &cy, &cw, &ch);
1165 if (!wd->deferred_recalc_job)
1166 elm_widget_show_region_set(data, cx, cy, cw, ch);
1169 wd->deferred_cur = EINA_TRUE;
1178 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1180 Widget_Data *wd = elm_widget_data_get(data);
1185 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1187 Widget_Data *wd = elm_widget_data_get(data);
1188 Elm_Entry_Anchor_Info ei;
1189 char *buf2, *p, *p2, *n;
1191 p = strrchr(emission, ',');
1194 const Eina_List *geoms;
1198 while (p2 >= emission)
1200 if (*p2 == ',') break;
1204 buf2 = alloca(5 + p - p2);
1205 strncpy(buf2, p2, p - p2);
1208 ei.button = atoi(buf2);
1209 ei.x = ei.y = ei.w = ei.h = 0;
1211 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1214 Evas_Textblock_Rectangle *r;
1216 Evas_Coord px, py, x, y;
1218 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1219 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1220 EINA_LIST_FOREACH(geoms, l, r)
1222 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1223 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1234 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1239 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1241 Widget_Data *wd = elm_widget_data_get(data);
1246 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1248 Widget_Data *wd = elm_widget_data_get(data);
1253 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1255 Widget_Data *wd = elm_widget_data_get(data);
1260 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1262 Widget_Data *wd = elm_widget_data_get(data);
1264 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1268 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1270 Widget_Data *wd = elm_widget_data_get(data);
1272 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1276 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1278 Widget_Data *wd = elm_widget_data_get(data);
1280 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1284 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1286 Widget_Data *wd = elm_widget_data_get(data);
1288 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1291 #ifdef HAVE_ELEMENTARY_X
1293 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1295 Widget_Data *wd = elm_widget_data_get(data);
1296 Ecore_X_Event_Selection_Notify *ev = event;
1297 if (!wd) return ECORE_CALLBACK_PASS_ON;
1298 if (!wd->selection_asked) return ECORE_CALLBACK_PASS_ON;
1300 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1301 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1303 Ecore_X_Selection_Data_Text *text_data;
1305 text_data = ev->data;
1306 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1308 if (text_data->text)
1310 char *txt = _text_to_mkup(text_data->text);
1314 elm_entry_entry_insert(data, txt);
1319 wd->selection_asked = EINA_FALSE;
1321 return ECORE_CALLBACK_PASS_ON;
1325 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1328 Widget_Data *wd = elm_widget_data_get(data);
1329 Ecore_X_Event_Selection_Clear *ev = event;
1331 if (!wd->have_selection) return 1;
1332 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1333 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1335 elm_entry_select_none(data);
1340 Evas_Object *top = elm_widget_top_get(data);
1341 Ecore_X_Event_Selection_Clear *ev = event;
1344 return ECORE_CALLBACK_PASS_ON;
1346 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1348 return ECORE_CALLBACK_PASS_ON;
1351 elm_selection_get(1/*ELM_SEL_SECONDARY*/,0x1/*Markup */,data);
1353 return ECORE_CALLBACK_PASS_ON;
1357 static Evas_Object *
1358 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1360 Widget_Data *wd = elm_widget_data_get(data);
1363 Elm_Entry_Item_Provider *ip;
1366 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1368 o = ip->func(ip->data, data, item);
1371 o = edje_object_add(evas_object_evas_get(data));
1372 if (!strncmp(item, "emoticon/", 9))
1373 ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1375 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1380 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1382 char *curlocater, *starttag, *endtag;
1383 int firstindex = 0, foundflag = -1;
1385 curlocater = strstr(oldstring, key);
1388 starttag = curlocater;
1389 endtag = curlocater + strlen(key);
1390 if (endtag == NULL || *endtag != '=')
1396 firstindex = abs(oldstring - curlocater);
1397 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1398 *value = (char*)oldstring + firstindex;
1400 while (oldstring != starttag)
1402 if (*starttag == '>')
1407 if (*starttag == '<')
1411 if (starttag == NULL) break;
1414 while (NULL != endtag)
1425 if (endtag == NULL) break;
1428 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1438 if (foundflag == 1) return 0;
1444 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1446 const char *srcstring = NULL;
1447 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1448 char *curlocater, *replocater;
1449 char *starttag, *endtag;
1450 int tagtxtlen = 0, insertflag = 0;
1452 srcstring = eina_strbuf_string_get(srcbuf);
1453 curlocater = strstr(srcstring, key);
1455 if (curlocater == NULL)
1463 starttag = strchr(srcstring, '<');
1464 endtag = strchr(srcstring, '>');
1465 tagtxtlen = endtag - starttag;
1466 if (tagtxtlen <= 0) tagtxtlen = 0;
1467 if (starttag < curlocater && curlocater < endtag) break;
1468 if (endtag != NULL && endtag+1 != NULL)
1469 srcstring = endtag+1;
1472 } while (strlen(srcstring) > 1);
1474 if (starttag && endtag && tagtxtlen > strlen(key))
1476 repbuf = eina_strbuf_new();
1477 diffbuf = eina_strbuf_new();
1478 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1479 srcstring = eina_strbuf_string_get(repbuf);
1480 curlocater = strstr(srcstring, key);
1482 if (curlocater != NULL)
1484 replocater = curlocater + strlen(key) + 1;
1486 while (*replocater == ' ' || *replocater == '=')
1491 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1494 if (replocater-curlocater > strlen(key)+1)
1497 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1506 eina_strbuf_reset(repbuf);
1514 if (repbuf == NULL) repbuf = eina_strbuf_new();
1515 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1519 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1520 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1526 eina_strbuf_prepend(diffbuf, "<");
1527 eina_strbuf_append(diffbuf, ">");
1528 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1532 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1533 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1537 if (repbuf) eina_strbuf_free(repbuf);
1538 if (diffbuf) eina_strbuf_free(diffbuf);
1544 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1546 Eina_Strbuf *sharebuf = NULL;
1548 sharebuf = eina_strbuf_new();
1549 eina_strbuf_append(sharebuf, *srcstring);
1550 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1551 eina_stringshare_del(*srcstring);
1552 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1553 eina_strbuf_free(sharebuf);
1559 _is_width_over(Evas_Object *obj)
1561 Evas_Coord x, y, w, h;
1562 Evas_Coord vx, vy, vw, vh;
1563 Widget_Data *wd = elm_widget_data_get(obj);
1567 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1569 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1571 if (x >= 0 && y >= 0)
1574 if (4 < wd->wrap_w && w > wd->wrap_w)
1581 _reverse_ellipsis_entry(Evas_Object *obj)
1583 Widget_Data *wd = elm_widget_data_get(obj);
1584 int cur_fontsize = 0;
1585 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1586 char **kvalue = NULL;
1587 const char *minfont, *deffont, *maxfont;
1588 const char *ellipsis_string = "...";
1589 int minfontsize, maxfontsize, minshowcount;
1591 minshowcount = strlen(ellipsis_string) + 1;
1592 minfont = edje_object_data_get(wd->ent, "min_font_size");
1593 if (minfont) minfontsize = atoi(minfont);
1594 else minfontsize = 1;
1595 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1596 if (maxfont) maxfontsize = atoi(maxfont);
1597 else maxfontsize = 1;
1598 deffont = edje_object_data_get(wd->ent, "default_font_size");
1599 if (deffont) cur_fontsize = atoi(deffont);
1600 else cur_fontsize = 1;
1601 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1602 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1604 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1606 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1609 txtbuf = eina_strbuf_new();
1610 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1612 if (cur_fontsize >= atoi(deffont))
1614 if (txtbuf) eina_strbuf_free(txtbuf);
1618 if (_is_width_over(obj) != 1)
1620 int rev_fontsize = cur_fontsize;
1624 if (rev_fontsize > atoi(deffont))
1627 if (fontbuf != NULL)
1629 eina_strbuf_free(fontbuf);
1632 fontbuf = eina_strbuf_new();
1633 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1634 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1635 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1637 eina_strbuf_free(fontbuf);
1639 } while (_is_width_over(obj) != 1);
1641 while (_is_width_over(obj))
1644 if (rev_fontsize < atoi(deffont))
1647 if (fontbuf != NULL)
1649 eina_strbuf_free(fontbuf);
1652 fontbuf = eina_strbuf_new();
1653 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1654 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1655 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1656 eina_strbuf_free(fontbuf);
1661 if (txtbuf) eina_strbuf_free(txtbuf);
1667 _ellipsis_entry_to_width(Evas_Object *obj)
1669 Widget_Data *wd = elm_widget_data_get(obj);
1670 int cur_fontsize = 0, len, jumpcount;
1671 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1672 char **kvalue = NULL;
1673 const char *minfont, *deffont, *maxfont;
1674 const char *ellipsis_string = "...";
1675 int minfontsize, maxfontsize, minshowcount;
1676 int i, tagend, cur_len;
1679 minshowcount = strlen(ellipsis_string) + 1;
1680 minfont = edje_object_data_get(wd->ent, "min_font_size");
1681 if (minfont) minfontsize = atoi(minfont);
1682 else minfontsize = 1;
1683 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1684 if (maxfont) maxfontsize = atoi(maxfont);
1685 else maxfontsize = 1;
1686 deffont = edje_object_data_get(wd->ent, "default_font_size");
1687 if (deffont) cur_fontsize = atoi(deffont);
1688 else cur_fontsize = 1;
1689 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1690 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1692 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1694 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1697 txtbuf = eina_strbuf_new();
1698 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1700 while (_is_width_over(obj))
1702 if (wd->ellipsis_threshold == 0)
1703 wd->ellipsis_threshold = _entry_length_get(obj);
1704 if (cur_fontsize > minfontsize)
1707 if (fontbuf != NULL)
1709 eina_strbuf_free(fontbuf);
1712 fontbuf = eina_strbuf_new();
1713 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1714 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1715 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1716 eina_strbuf_free(fontbuf);
1718 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1722 len = _entry_length_get(obj);
1723 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1724 cur_len = strlen(cur_str);
1726 for (i = 0; i < len; i++)
1728 if(cur_str[i] == '>' && cur_str[i+1] != NULL &&
1729 cur_str[i+1] != '<')
1736 while (jumpcount < len-strlen(ellipsis_string))
1738 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1742 eina_strbuf_free(txtbuf);
1745 txtbuf = eina_strbuf_new();
1746 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1747 eina_strbuf_append(txtbuf, ellipsis_string);
1748 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1749 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1750 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1752 if (_is_width_over(obj))
1760 if (txtbuf) eina_strbuf_free(txtbuf);
1765 static int _textinput_control_function(void *data,void *input_data)
1767 /*calculate character count*/
1768 Evas_Object *entry = (Evas_Object *)data;
1769 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1772 size_t insert_text_len=0;
1773 char *text = edje_object_part_text_get(wd->ent, "elm.text");
1775 size_t remain_bytes;
1778 byte_len = strlen(text);/*no of bytes*/
1779 remain_bytes = wd->max_no_of_bytes-byte_len;
1780 sprintf(buf,"%d",remain_bytes);
1781 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1784 insert_text = (char *)input_data;
1785 insert_text_len = strlen(insert_text);
1786 if(remain_bytes<insert_text_len)
1788 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1791 if(byte_len>=wd->max_no_of_bytes)
1793 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1802 * This adds an entry to @p parent object.
1804 * @param parent The parent object
1805 * @return The new object or NULL if it cannot be created
1810 elm_entry_add(Evas_Object *parent)
1812 Evas_Object *obj, *top;
1816 wd = ELM_NEW(Widget_Data);
1817 e = evas_object_evas_get(parent);
1818 wd->bgcolor = EINA_FALSE;
1819 wd->bg = evas_object_rectangle_add(e);
1820 evas_object_color_set(wd->bg, 0, 0, 0, 0);
1821 obj = elm_widget_add(e);
1822 ELM_SET_WIDTYPE(widtype, "entry");
1823 elm_widget_type_set(obj, "entry");
1824 elm_widget_sub_object_add(parent, obj);
1825 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1826 elm_widget_data_set(obj, wd);
1827 elm_widget_del_hook_set(obj, _del_hook);
1828 elm_widget_theme_hook_set(obj, _theme_hook);
1829 elm_widget_disable_hook_set(obj, _disable_hook);
1830 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1831 elm_widget_can_focus_set(obj, 1);
1833 wd->linewrap = EINA_TRUE;
1834 wd->ellipsis = EINA_FALSE;
1835 wd->char_linewrap= EINA_FALSE;
1836 wd->editable = EINA_TRUE;
1837 wd->disabled = EINA_FALSE;
1838 wd->context_menu = EINA_TRUE;
1840 wd->ellipsis_threshold = 0;
1842 wd->ent = edje_object_add(e);
1843 edje_object_item_provider_set(wd->ent, _get_item, obj);
1844 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1845 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1846 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1848 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1850 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1853 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1854 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1855 _signal_entry_changed, obj);
1856 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1857 _signal_selection_start, obj);
1858 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1859 _signal_selection_changed, obj);
1860 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1861 _signal_selection_cleared, obj);
1862 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1863 _signal_entry_paste_request, obj);
1864 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1865 _signal_entry_copy_notify, obj);
1866 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1867 _signal_entry_cut_notify, obj);
1868 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1869 _signal_cursor_changed, obj);
1870 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1871 _signal_anchor_down, obj);
1872 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1873 _signal_anchor_up, obj);
1874 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1875 _signal_anchor_move, obj);
1876 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1877 _signal_anchor_in, obj);
1878 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1879 _signal_anchor_out, obj);
1880 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1881 _signal_key_enter, obj);
1882 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1883 _signal_mouse_down, obj);
1884 edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
1885 _signal_mouse_up, obj);
1886 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1887 _signal_mouse_double, obj);
1888 edje_object_part_text_set(wd->ent, "elm.text", "");
1889 elm_widget_resize_object_set(obj, wd->ent);
1892 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
1894 #ifdef HAVE_ELEMENTARY_X
1895 top = elm_widget_top_get(obj);
1896 if ((top) && (elm_win_xwindow_get(top)))
1898 wd->sel_notify_handler =
1899 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1900 _event_selection_notify, obj);
1901 wd->sel_clear_handler =
1902 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1903 _event_selection_clear, obj);
1907 entries = eina_list_prepend(entries, obj);
1909 // module - find module for entry
1910 wd->api = _module(obj);
1911 // if found - hook in
1912 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1914 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1915 // TODO: and save some bytes, making descriptions per-class and not instance!
1916 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1920 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
1922 ELM_CHECK_WIDTYPE(obj, widtype);
1923 Widget_Data *wd = elm_widget_data_get(obj);
1925 ext_mod->cancel = _cancel;
1926 ext_mod->copy = _copy;
1927 ext_mod->cut = _cut;
1928 ext_mod->paste = _paste;
1929 ext_mod->select = _select;
1930 ext_mod->selectall = NULL; /* to be implemented*/
1931 ext_mod->ent = wd->ent;
1932 ext_mod->items = wd->items;
1933 ext_mod->longpress_timer = wd->longpress_timer;
1934 ext_mod->editable = wd->editable;
1935 ext_mod->have_selection = wd->have_selection;
1936 ext_mod->password = wd->password;
1937 ext_mod->selmode = wd->selmode;
1938 ext_mod->context_menu = wd->context_menu;
1942 * This sets the entry object not to line wrap. All input will
1943 * be on a single line, and the entry box will extend with user input.
1945 * @param obj The entry object
1946 * @param single_line If true, the text in the entry
1947 * will be on a single line.
1952 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1954 ELM_CHECK_WIDTYPE(obj, widtype);
1955 Widget_Data *wd = elm_widget_data_get(obj);
1957 Ecore_IMF_Context *ic;
1959 if (wd->single_line == single_line) return;
1960 wd->single_line = single_line;
1961 wd->linewrap = EINA_FALSE;
1962 wd->char_linewrap = EINA_FALSE;
1963 t = eina_stringshare_add(elm_entry_entry_get(obj));
1964 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1965 elm_entry_entry_set(obj, t);
1966 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
1967 // edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
1968 ic = elm_entry_imf_context_get(obj);
1971 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
1974 eina_stringshare_del(t);
1979 * This returns true if the entry has been set to single line mode.
1980 * See also elm_entry_single_line_set().
1982 * @param obj The entry object
1983 * @return single_line If true, the text in the entry is set to display
1989 elm_entry_single_line_get(const Evas_Object *obj)
1991 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1992 Widget_Data *wd = elm_widget_data_get(obj);
1993 if (!wd) return EINA_FALSE;
1994 return wd->single_line;
1998 * This set's the maximum bytes that can be added in entry.
2000 * @param obj The entry object
2001 * @param max_no_of_bytes Maximum number of bytes entry can have.
2006 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2008 Widget_Data *wd = elm_widget_data_get(obj);
2010 wd->max_no_of_bytes = max_no_of_bytes;
2011 edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2012 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2017 * This sets the entry object to password mode. All text entered
2018 * and/or displayed within the widget will be replaced with asterisks (*).
2020 * @param obj The entry object
2021 * @param password If true, password mode is enabled.
2026 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2028 ELM_CHECK_WIDTYPE(obj, widtype);
2029 Widget_Data *wd = elm_widget_data_get(obj);
2030 Ecore_IMF_Context *ic;
2033 if (wd->password == password) return;
2034 wd->password = password;
2035 wd->show_last_character = EINA_FALSE;
2036 wd->single_line = EINA_TRUE;
2037 wd->linewrap = EINA_FALSE;
2038 wd->char_linewrap = EINA_FALSE;
2039 t = eina_stringshare_add(elm_entry_entry_get(obj));
2040 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2041 elm_entry_entry_set(obj, t);
2043 ic = elm_entry_imf_context_get(obj);
2046 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2049 eina_stringshare_del(t);
2054 * This set's the entry in password mode with out masking the last character entered by user,
2055 * and later masking the character after 2 seconds.
2057 * @param obj The entry object
2058 * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character"
2064 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2066 Widget_Data *wd = elm_widget_data_get(obj);
2069 if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character)) return;
2070 wd->show_last_character = show_last_character;
2071 wd->password = show_last_character;
2072 wd->single_line = EINA_TRUE;
2073 wd->linewrap = EINA_FALSE;
2074 wd->char_linewrap = EINA_FALSE;
2075 t = eina_stringshare_add(elm_entry_entry_get(obj));
2076 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2077 elm_entry_entry_set(obj, t);
2078 eina_stringshare_del(t);
2083 * This returns whether password mode is enabled.
2084 * See also elm_entry_password_set().
2086 * @param obj The entry object
2087 * @return If true, the entry is set to display all characters
2093 elm_entry_password_get(const Evas_Object *obj)
2095 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2096 Widget_Data *wd = elm_widget_data_get(obj);
2097 if (!wd) return EINA_FALSE;
2098 return wd->password;
2102 * This sets the text displayed within the entry to @p entry.
2104 * @param obj The entry object
2105 * @param entry The text to be displayed
2110 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2112 ELM_CHECK_WIDTYPE(obj, widtype);
2113 Widget_Data *wd = elm_widget_data_get(obj);
2115 if (!entry) entry = "";
2116 if(wd->max_no_of_bytes)
2118 int len = strlen(entry);
2119 if(len > wd->max_no_of_bytes)
2121 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2125 edje_object_part_text_set(wd->ent, "elm.text", entry);
2126 if (wd->text) eina_stringshare_del(wd->text);
2128 wd->changed = EINA_TRUE;
2133 * This returns the text currently shown in object @p entry.
2134 * See also elm_entry_entry_set().
2136 * @param obj The entry object
2137 * @return The currently displayed text or NULL on failure
2142 elm_entry_entry_get(const Evas_Object *obj)
2144 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2145 Widget_Data *wd = elm_widget_data_get(obj);
2147 if (!wd) return NULL;
2148 if (wd->text) return wd->text;
2149 text = edje_object_part_text_get(wd->ent, "elm.text");
2152 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2155 eina_stringshare_replace(&wd->text, text);
2160 * This returns all selected text within the entry.
2162 * @param obj The entry object
2163 * @return The selected text within the entry or NULL on failure
2168 elm_entry_selection_get(const Evas_Object *obj)
2170 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2171 Widget_Data *wd = elm_widget_data_get(obj);
2172 if (!wd) return NULL;
2173 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2177 * This inserts text in @p entry at the beginning of the entry
2180 * @param obj The entry object
2181 * @param entry The text to insert
2186 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2188 ELM_CHECK_WIDTYPE(obj, widtype);
2189 Widget_Data *wd = elm_widget_data_get(obj);
2191 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2192 wd->changed = EINA_TRUE;
2197 * This enables word line wrapping in the entry object. It is the opposite
2198 * of elm_entry_single_line_set(). Additionally, setting this disables
2199 * character line wrapping.
2200 * See also elm_entry_line_char_wrap_set().
2202 * @param obj The entry object
2203 * @param wrap If true, the entry will be wrapped once it reaches the end
2204 * of the object. Wrapping will occur at the end of the word before the end of the
2210 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2212 ELM_CHECK_WIDTYPE(obj, widtype);
2213 Widget_Data *wd = elm_widget_data_get(obj);
2216 if (wd->linewrap == wrap) return;
2217 wd->linewrap = wrap;
2219 wd->char_linewrap = EINA_FALSE;
2220 t = eina_stringshare_add(elm_entry_entry_get(obj));
2221 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2222 elm_entry_entry_set(obj, t);
2223 eina_stringshare_del(t);
2228 * Set wrap width of the entry
2230 * @param obj The entry object
2231 * @param w The wrap width in pixels at a minimum where words need to wrap
2235 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2237 Widget_Data *wd = elm_widget_data_get(obj);
2238 if (wd->wrap_w == w) return;
2244 * get wrap width of the entry
2246 * @param obj The entry object
2247 * @return The wrap width in pixels at a minimum where words need to wrap
2251 elm_entry_wrap_width_get(const Evas_Object *obj)
2253 Widget_Data *wd = elm_widget_data_get(obj);
2258 * This enables character line wrapping in the entry object. It is the opposite
2259 * of elm_entry_single_line_set(). Additionally, setting this disables
2260 * word line wrapping.
2261 * See also elm_entry_line_wrap_set().
2263 * @param obj The entry object
2264 * @param wrap If true, the entry will be wrapped once it reaches the end
2265 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2270 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2272 ELM_CHECK_WIDTYPE(obj, widtype);
2273 Widget_Data *wd = elm_widget_data_get(obj);
2276 if (wd->char_linewrap == wrap) return;
2277 wd->char_linewrap = wrap;
2278 if(wd->char_linewrap)
2279 wd->linewrap = EINA_FALSE;
2280 t = eina_stringshare_add(elm_entry_entry_get(obj));
2281 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2282 elm_entry_entry_set(obj, t);
2283 eina_stringshare_del(t);
2288 * This sets the editable attribute of the entry.
2290 * @param obj The entry object
2291 * @param editable If true, the entry will be editable by the user.
2292 * If false, it will be set to the disabled state.
2297 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2299 ELM_CHECK_WIDTYPE(obj, widtype);
2300 Widget_Data *wd = elm_widget_data_get(obj);
2303 if (wd->editable == editable) return;
2304 wd->editable = editable;
2305 t = eina_stringshare_add(elm_entry_entry_get(obj));
2306 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2307 elm_entry_entry_set(obj, t);
2308 eina_stringshare_del(t);
2313 * This gets the editable attribute of the entry.
2314 * See also elm_entry_editable_set().
2316 * @param obj The entry object
2317 * @return If true, the entry is editable by the user.
2318 * If false, it is not editable by the user
2323 elm_entry_editable_get(const Evas_Object *obj)
2325 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2326 Widget_Data *wd = elm_widget_data_get(obj);
2327 if (!wd) return EINA_FALSE;
2328 return wd->editable;
2332 * This drops any existing text selection within the entry.
2334 * @param obj The entry object
2339 elm_entry_select_none(Evas_Object *obj)
2341 ELM_CHECK_WIDTYPE(obj, widtype);
2342 Widget_Data *wd = elm_widget_data_get(obj);
2346 wd->selmode = EINA_FALSE;
2347 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2348 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2350 wd->have_selection = EINA_FALSE;
2351 edje_object_part_text_select_none(wd->ent, "elm.text");
2355 * This selects all text within the entry.
2357 * @param obj The entry object
2362 elm_entry_select_all(Evas_Object *obj)
2364 ELM_CHECK_WIDTYPE(obj, widtype);
2365 Widget_Data *wd = elm_widget_data_get(obj);
2369 wd->selmode = EINA_FALSE;
2370 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2371 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2373 wd->have_selection = EINA_TRUE;
2374 edje_object_part_text_select_all(wd->ent, "elm.text");
2378 * This moves the cursor one place to the right within the entry.
2380 * @param obj The entry object
2381 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2386 elm_entry_cursor_next(Evas_Object *obj)
2388 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2389 Widget_Data *wd = elm_widget_data_get(obj);
2390 if (!wd) return EINA_FALSE;
2391 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2395 * This moves the cursor one place to the left within the entry.
2397 * @param obj The entry object
2398 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2403 elm_entry_cursor_prev(Evas_Object *obj)
2405 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2406 Widget_Data *wd = elm_widget_data_get(obj);
2407 if (!wd) return EINA_FALSE;
2408 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2412 * This moves the cursor one line up within the entry.
2414 * @param obj The entry object
2415 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2420 elm_entry_cursor_up(Evas_Object *obj)
2422 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2423 Widget_Data *wd = elm_widget_data_get(obj);
2424 if (!wd) return EINA_FALSE;
2425 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2429 * This moves the cursor one line down within the entry.
2431 * @param obj The entry object
2432 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2437 elm_entry_cursor_down(Evas_Object *obj)
2439 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2440 Widget_Data *wd = elm_widget_data_get(obj);
2441 if (!wd) return EINA_FALSE;
2442 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2446 * This moves the cursor to the beginning of the entry.
2448 * @param obj The entry object
2453 elm_entry_cursor_begin_set(Evas_Object *obj)
2455 ELM_CHECK_WIDTYPE(obj, widtype);
2456 Widget_Data *wd = elm_widget_data_get(obj);
2458 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2462 * This moves the cursor to the end of the entry.
2464 * @param obj The entry object
2469 elm_entry_cursor_end_set(Evas_Object *obj)
2471 ELM_CHECK_WIDTYPE(obj, widtype);
2472 Widget_Data *wd = elm_widget_data_get(obj);
2474 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2478 * This moves the cursor to the beginning of the current line.
2480 * @param obj The entry object
2485 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2487 ELM_CHECK_WIDTYPE(obj, widtype);
2488 Widget_Data *wd = elm_widget_data_get(obj);
2490 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2494 * This moves the cursor to the end of the current line.
2496 * @param obj The entry object
2501 elm_entry_cursor_line_end_set(Evas_Object *obj)
2503 ELM_CHECK_WIDTYPE(obj, widtype);
2504 Widget_Data *wd = elm_widget_data_get(obj);
2506 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2510 * This begins a selection within the entry as though
2511 * the user were holding down the mouse button to make a selection.
2513 * @param obj The entry object
2518 elm_entry_cursor_selection_begin(Evas_Object *obj)
2520 ELM_CHECK_WIDTYPE(obj, widtype);
2521 Widget_Data *wd = elm_widget_data_get(obj);
2523 edje_object_part_text_select_begin(wd->ent, "elm.text");
2527 * This ends a selection within the entry as though
2528 * the user had just released the mouse button while making a selection.
2530 * @param obj The entry object
2535 elm_entry_cursor_selection_end(Evas_Object *obj)
2537 ELM_CHECK_WIDTYPE(obj, widtype);
2538 Widget_Data *wd = elm_widget_data_get(obj);
2540 edje_object_part_text_select_extend(wd->ent, "elm.text");
2544 * TODO: fill this in
2546 * @param obj The entry object
2547 * @return TODO: fill this in
2552 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2554 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2555 Widget_Data *wd = elm_widget_data_get(obj);
2556 if (!wd) return EINA_FALSE;
2557 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2561 * This returns whether the cursor is visible.
2563 * @param obj The entry object
2564 * @return If true, the cursor is visible.
2569 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2571 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2572 Widget_Data *wd = elm_widget_data_get(obj);
2573 if (!wd) return EINA_FALSE;
2574 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2578 * TODO: fill this in
2580 * @param obj The entry object
2581 * @return TODO: fill this in
2586 elm_entry_cursor_content_get(const Evas_Object *obj)
2588 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2589 Widget_Data *wd = elm_widget_data_get(obj);
2590 if (!wd) return NULL;
2591 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2595 * This executes a "cut" action on the selected text in the entry.
2597 * @param obj The entry object
2602 elm_entry_selection_cut(Evas_Object *obj)
2604 ELM_CHECK_WIDTYPE(obj, widtype);
2605 Widget_Data *wd = elm_widget_data_get(obj);
2607 _cut(obj, NULL, NULL);
2611 * This executes a "copy" action on the selected text in the entry.
2613 * @param obj The entry object
2618 elm_entry_selection_copy(Evas_Object *obj)
2620 ELM_CHECK_WIDTYPE(obj, widtype);
2621 Widget_Data *wd = elm_widget_data_get(obj);
2623 _copy(obj, NULL, NULL);
2627 * This executes a "paste" action in the entry.
2629 * @param obj The entry object
2634 elm_entry_selection_paste(Evas_Object *obj)
2636 ELM_CHECK_WIDTYPE(obj, widtype);
2637 Widget_Data *wd = elm_widget_data_get(obj);
2639 _paste(obj, NULL, NULL);
2643 * This clears and frees the items in a entry's contextual (right click) menu.
2645 * @param obj The entry object
2650 elm_entry_context_menu_clear(Evas_Object *obj)
2652 ELM_CHECK_WIDTYPE(obj, widtype);
2653 Widget_Data *wd = elm_widget_data_get(obj);
2654 Elm_Entry_Context_Menu_Item *it;
2656 EINA_LIST_FREE(wd->items, it)
2658 eina_stringshare_del(it->label);
2659 eina_stringshare_del(it->icon_file);
2660 eina_stringshare_del(it->icon_group);
2666 * This adds an item to the entry's contextual menu.
2668 * @param obj The entry object
2669 * @param label The item's text label
2670 * @param icon_file The item's icon file
2671 * @param icon_type The item's icon type
2672 * @param func The callback to execute when the item is clicked
2673 * @param data The data to associate with the item for related functions
2678 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)
2680 ELM_CHECK_WIDTYPE(obj, widtype);
2681 Widget_Data *wd = elm_widget_data_get(obj);
2682 Elm_Entry_Context_Menu_Item *it;
2684 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2686 wd->items = eina_list_append(wd->items, it);
2688 it->label = eina_stringshare_add(label);
2689 it->icon_file = eina_stringshare_add(icon_file);
2690 it->icon_type = icon_type;
2692 it->data = (void *)data;
2696 * This disables the entry's contextual (right click) menu.
2698 * @param obj The entry object
2699 * @param disabled If true, the menu is disabled
2704 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2706 ELM_CHECK_WIDTYPE(obj, widtype);
2707 Widget_Data *wd = elm_widget_data_get(obj);
2709 if (wd->context_menu == !disabled) return;
2710 wd->context_menu = !disabled;
2714 * This returns whether the entry's contextual (right click) menu is disabled.
2716 * @param obj The entry object
2717 * @return If true, the menu is disabled
2722 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2724 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2725 Widget_Data *wd = elm_widget_data_get(obj);
2726 if (!wd) return EINA_FALSE;
2727 return !wd->context_menu;
2731 * This appends a custom item provider to the list for that entry
2733 * This appends the given callback. The list is walked from beginning to end
2734 * with each function called given the item href string in the text. If the
2735 * function returns an object handle other than NULL (it should create an
2736 * and object to do this), then this object is used to replace that item. If
2737 * not the next provider is called until one provides an item object, or the
2738 * default provider in entry does.
2740 * @param obj The entry object
2741 * @param func The function called to provide the item object
2742 * @param data The data passed to @p func
2747 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2749 ELM_CHECK_WIDTYPE(obj, widtype);
2750 Widget_Data *wd = elm_widget_data_get(obj);
2753 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2757 wd->item_providers = eina_list_append(wd->item_providers, ip);
2761 * This prepends a custom item provider to the list for that entry
2763 * This prepends the given callback. See elm_entry_item_provider_append() for
2766 * @param obj The entry object
2767 * @param func The function called to provide the item object
2768 * @param data The data passed to @p func
2773 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2775 ELM_CHECK_WIDTYPE(obj, widtype);
2776 Widget_Data *wd = elm_widget_data_get(obj);
2779 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2783 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2787 * This removes a custom item provider to the list for that entry
2789 * This removes the given callback. See elm_entry_item_provider_append() for
2792 * @param obj The entry object
2793 * @param func The function called to provide the item object
2794 * @param data The data passed to @p func
2799 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2801 ELM_CHECK_WIDTYPE(obj, widtype);
2802 Widget_Data *wd = elm_widget_data_get(obj);
2804 Elm_Entry_Item_Provider *ip;
2807 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2809 if ((ip->func == func) && (ip->data == data))
2811 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2819 * This converts a markup (HTML-like) string into UTF-8.
2821 * @param s The string (in markup) to be converted
2822 * @return The converted string (in UTF-8)
2827 elm_entry_markup_to_utf8(const char *s)
2829 char *ss = _mkup_to_text(s);
2830 if (!ss) ss = strdup("");
2835 * This converts a UTF-8 string into markup (HTML-like).
2837 * @param s The string (in UTF-8) to be converted
2838 * @return The converted string (in markup)
2843 elm_entry_utf8_to_markup(const char *s)
2845 char *ss = _text_to_mkup(s);
2846 if (!ss) ss = strdup("");
2851 * Get the input method context in the entry widget
2853 * @param obj The entry object
2854 * @return The input method context
2858 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2860 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2861 Widget_Data *wd = elm_widget_data_get(obj);
2862 if (!wd || !wd->ent) return NULL;
2864 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2868 * Set whether entry should enable the return key on soft keyboard automatically
2870 * @param obj The entry object
2871 * @param on If true, entry enables the return key on soft keyboard automatically.
2876 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
2878 ELM_CHECK_WIDTYPE(obj, widtype);
2879 Widget_Data *wd = elm_widget_data_get(obj);
2882 wd->autoreturnkey = on;
2883 _check_enable_returnkey(obj);
2887 * Set whether entry should support auto capitalization
2889 * @param obj The entry object
2890 * @param on If true, entry suports auto capitalization.
2895 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
2897 ELM_CHECK_WIDTYPE(obj, widtype);
2898 Widget_Data *wd = elm_widget_data_get(obj);
2902 wd->autocapitalize = EINA_FALSE;
2904 wd->autocapitalize = autocap;
2906 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2910 * Set whether entry should support auto period
2912 * @param obj The entry object
2913 * @param on If true, entry suports auto period.
2918 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
2920 ELM_CHECK_WIDTYPE(obj, widtype);
2921 Widget_Data *wd = elm_widget_data_get(obj);
2925 wd->autoperiod = EINA_FALSE;
2927 wd->autoperiod = autoperiod;
2929 // edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2933 * Set the font size on the entry object
2935 * @param obj The entry object
2936 * @param size font size
2941 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
2943 ELM_CHECK_WIDTYPE(obj, widtype);
2944 Widget_Data *wd = elm_widget_data_get(obj);
2945 Eina_Strbuf *fontbuf = NULL;
2950 t = eina_stringshare_add(elm_entry_entry_get(obj));
2951 fontbuf = eina_strbuf_new();
2952 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
2954 if (fontsize == 0) removeflag = 1; // remove fontsize tag
2956 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
2958 elm_entry_entry_set(obj, t);
2962 eina_strbuf_free(fontbuf);
2963 eina_stringshare_del(t);
2967 * Set the text align on the entry object
2969 * @param obj The entry object
2970 * @param align align mode
2975 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
2977 ELM_CHECK_WIDTYPE(obj, widtype);
2978 Widget_Data *wd = elm_widget_data_get(obj);
2983 t = eina_stringshare_add(elm_entry_entry_get(obj));
2985 if (len <= 0) return;
2987 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
2988 elm_entry_entry_set(obj, t);
2992 eina_stringshare_del(t);
2996 * Set the text color on the entry object
2998 * @param obj The entry object
2999 * @param r Red property background color of The entry object
3000 * @param g Green property background color of The entry object
3001 * @param b Blue property background color of The entry object
3002 * @param a Alpha property background alpha of The entry object
3007 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3009 ELM_CHECK_WIDTYPE(obj, widtype);
3010 Widget_Data *wd = elm_widget_data_get(obj);
3011 Eina_Strbuf *colorbuf = NULL;
3016 t = eina_stringshare_add(elm_entry_entry_get(obj));
3018 if (len <= 0) return;
3019 colorbuf = eina_strbuf_new();
3020 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3022 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3024 elm_entry_entry_set(obj, t);
3028 eina_strbuf_free(colorbuf);
3029 eina_stringshare_del(t);
3034 * Set background color of the entry
3036 * @param obj The entry object
3037 * @param r Red property background color of The entry object
3038 * @param g Green property background color of The entry object
3039 * @param b Blue property background color of The entry object
3040 * @param a Alpha property background alpha of The entry object
3044 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3046 ELM_CHECK_WIDTYPE(obj, widtype);
3047 Widget_Data *wd = elm_widget_data_get(obj);
3048 evas_object_color_set(wd->bg, r, g, b, a);
3050 if (wd->bgcolor == EINA_FALSE)
3053 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3058 * Set the ellipsis behavior of the entry
3060 * @param obj The entry object
3061 * @param ellipsis To ellipsis text or not
3065 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3067 ELM_CHECK_WIDTYPE(obj, widtype);
3068 Widget_Data *wd = elm_widget_data_get(obj);
3069 if (wd->ellipsis == ellipsis) return;
3070 wd->ellipsis = ellipsis;
3076 * This sets the attribute to show the input panel automatically.
3078 * @param obj The entry object
3079 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3084 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3086 ELM_CHECK_WIDTYPE(obj, widtype);
3087 Widget_Data *wd = elm_widget_data_get(obj);
3090 wd->input_panel_enable = enabled;
3091 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3095 * Set the input panel layout of the entry
3097 * @param obj The entry object
3098 * @param layout the layout to set
3103 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3105 ELM_CHECK_WIDTYPE(obj, widtype);
3106 Widget_Data *wd = elm_widget_data_get(obj);
3109 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3112 wd->input_panel_layout = layout;
3114 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);