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, void *event_info __UNUSED__)
596 Elm_Entry_Context_Menu_Item *it = data;
597 Evas_Object *obj2 = it->obj;
600 if (!strcmp(it->label, "Menu"))
602 elm_cbhm_helper_init(obj);
603 elm_cbhm_send_raw_data("show");
607 if (it->func) it->func(it->data, obj2, NULL);
611 _long_press(void *data)
613 Widget_Data *wd = elm_widget_data_get(data);
616 const Elm_Entry_Context_Menu_Item *it;
617 if (!wd) return ECORE_CALLBACK_CANCEL;
618 if ((wd->api) && (wd->api->obj_longpress))
620 wd->api->obj_longpress(data);
622 else if (wd->context_menu)
624 const char *context_menu_orientation;
626 if (wd->hoversel) evas_object_del(wd->hoversel);
627 else elm_widget_scroll_freeze_push(data);
628 wd->hoversel = elm_hoversel_add(data);
629 context_menu_orientation = edje_object_data_get
630 (wd->ent, "context_menu_orientation");
631 if ((context_menu_orientation) &&
632 (!strcmp(context_menu_orientation, "horizontal")))
633 elm_hoversel_horizontal_set(wd->hoversel, 1);
634 elm_object_style_set(wd->hoversel, "entry");
635 elm_widget_sub_object_add(data, wd->hoversel);
636 elm_hoversel_label_set(wd->hoversel, "Text");
637 top = elm_widget_top_get(data);
638 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
639 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
643 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
645 if (1) // need way to detect if someone has a selection
648 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
656 if (wd->have_selection)
658 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
661 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
664 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
668 EINA_LIST_FOREACH(wd->items, l, it)
670 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
671 it->icon_type, _item_clicked, it);
675 _hoversel_position(data);
676 evas_object_show(wd->hoversel);
677 elm_hoversel_hover_begin(wd->hoversel);
679 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
680 edje_object_part_text_select_abort(wd->ent, "elm.text");
682 wd->longpress_timer = NULL;
683 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
684 return ECORE_CALLBACK_CANCEL;
688 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
690 Widget_Data *wd = elm_widget_data_get(data);
691 Evas_Event_Mouse_Down *ev = event_info;
693 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
694 if (ev->button != 1) return;
695 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
696 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
697 wd->longpress_timer = ecore_timer_add(1.0, _long_press, data);
698 wd->downx = ev->canvas.x;
699 wd->downy = ev->canvas.y;
703 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
705 Widget_Data *wd = elm_widget_data_get(data);
706 Evas_Event_Mouse_Up *ev = event_info;
708 if (ev->button != 1) return;
709 if ((wd->api) && (wd->api->obj_mouseup))
711 wd->api->obj_mouseup(data);
713 if (wd->longpress_timer)
715 ecore_timer_del(wd->longpress_timer);
716 wd->longpress_timer = NULL;
721 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
723 Widget_Data *wd = elm_widget_data_get(data);
724 Evas_Event_Mouse_Move *ev = event_info;
728 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
730 if (wd->longpress_timer)
732 ecore_timer_del(wd->longpress_timer);
733 wd->longpress_timer = NULL;
736 else if (wd->longpress_timer)
740 dx = wd->downx - ev->cur.canvas.x;
742 dy = wd->downy - ev->cur.canvas.y;
745 ((_elm_config->finger_size / 2) *
746 (_elm_config->finger_size / 2)))
748 ecore_timer_del(wd->longpress_timer);
749 wd->longpress_timer = NULL;
753 else if (wd->longpress_timer)
757 dx = wd->downx - ev->cur.canvas.x;
759 dy = wd->downy - ev->cur.canvas.y;
762 ((_elm_config->finger_size / 2) *
763 (_elm_config->finger_size / 2)))
765 ecore_timer_del(wd->longpress_timer);
766 wd->longpress_timer = NULL;
772 _getbase(Evas_Object *obj)
774 Widget_Data *wd = elm_widget_data_get(obj);
775 if (!wd) return "base";
778 if((wd->password)&&(wd->show_last_character)) return "custom-password";
779 else if(wd->password) return "base-password";
782 if (wd->single_line) return "base-single";
785 if (wd->linewrap) return "base";
786 else if (wd->char_linewrap) return "base-charwrap";
787 else return "base-nowrap";
793 if((wd->password)&&(wd->show_last_character)) return "custom-password";
794 else if(wd->password) return "base-password";
797 if (wd->single_line) return "base-single-noedit";
800 if (wd->linewrap) return "base-noedit";
801 else if (wd->char_linewrap) return "base-noedit-charwrap";
802 else return "base-nowrap-noedit";
810 _str_append(char *str, const char *txt, int *len, int *alloc)
812 int txt_len = strlen(txt);
814 if (txt_len <= 0) return str;
815 if ((*len + txt_len) >= *alloc)
820 alloc2 = *alloc + txt_len + 128;
821 str2 = realloc(str, alloc2);
822 if (!str2) return str;
826 strcpy(str + *len, txt);
831 /*FIXME: Sholud be implemented somewhere else, it really depends on the context
832 * because some markups can be implemented otherwise according to style.
833 * probably doing it in textblock and making it translate according to it's
834 * style is correct. */
836 _strncpy(char* dest, const char* src, size_t count)
840 ERR( "dest is NULL" );
845 ERR( "src is NULL" );
850 ERR( "count is smaller than 0" );
854 return strncpy( dest, src, count );
858 _mkup_to_text(const char *mkup)
861 int str_len = 0, str_alloc = 0;
863 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
865 if (!mkup) return NULL;
867 tag_start = tag_end = esc_start = esc_end = NULL;
872 if (((p!=NULL)&&(*p == 0)) ||
873 (tag_end) || (esc_end) ||
874 (tag_start) || (esc_start))
880 ttag = malloc(tag_end - tag_start);
883 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
884 ttag[tag_end - tag_start - 1] = 0;
885 if (!strcmp(ttag, "br"))
886 str = _str_append(str, "\n", &str_len, &str_alloc);
887 else if (!strcmp(ttag, "\n"))
888 str = _str_append(str, "\n", &str_len, &str_alloc);
889 else if (!strcmp(ttag, "\\n"))
890 str = _str_append(str, "\n", &str_len, &str_alloc);
891 else if (!strcmp(ttag, "\t"))
892 str = _str_append(str, "\t", &str_len, &str_alloc);
893 else if (!strcmp(ttag, "\\t"))
894 str = _str_append(str, "\t", &str_len, &str_alloc);
895 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
896 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
899 tag_start = tag_end = NULL;
903 ts = malloc(esc_end - esc_start + 1);
907 _strncpy(ts, esc_start, esc_end - esc_start);
908 ts[esc_end - esc_start] = 0;
909 esc = evas_textblock_escape_string_get(ts);
911 str = _str_append(str, esc, &str_len, &str_alloc);
914 esc_start = esc_end = NULL;
916 else if ((p!=NULL)&&(*p == 0))
918 ts = malloc(p - s + 1);
921 _strncpy(ts, s, p - s);
923 str = _str_append(str, ts, &str_len, &str_alloc);
929 if ((p!=NULL)&&(*p == '<'))
935 ts = malloc(p - s + 1);
938 _strncpy(ts, s, p - s);
940 str = _str_append(str, ts, &str_len, &str_alloc);
946 else if ((p!=NULL)&&(*p == '>'))
954 else if ((p!=NULL)&&(*p == '&'))
960 ts = malloc(p - s + 1);
963 _strncpy(ts, s, p - s);
965 str = _str_append(str, ts, &str_len, &str_alloc);
971 else if ((p!=NULL)&&(*p == ';'))
985 _entry_length_get(Evas_Object *obj)
988 const char *str = elm_entry_entry_get(obj);
991 char *plain_str = _mkup_to_text(str);
992 if (!plain_str) return 0;
994 len = strlen(plain_str);
1001 _text_to_mkup(const char *text)
1004 int str_len = 0, str_alloc = 0;
1005 int ch, pos = 0, pos2 = 0;
1007 if (!text) return NULL;
1011 pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
1012 if ((ch <= 0) || (pos2 <= 0)) break;
1014 str = _str_append(str, "<br>", &str_len, &str_alloc);
1015 else if (ch == '\t')
1016 str = _str_append(str, "<\t>", &str_len, &str_alloc);
1018 str = _str_append(str, "<", &str_len, &str_alloc);
1020 str = _str_append(str, ">", &str_len, &str_alloc);
1022 str = _str_append(str, "&", &str_len, &str_alloc);
1027 _strncpy(tstr, text + pos, pos2 - pos);
1028 tstr[pos2 - pos] = 0;
1029 str = _str_append(str, tstr, &str_len, &str_alloc);
1036 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1038 Widget_Data *wd = elm_widget_data_get(data);
1040 wd->changed = EINA_TRUE;
1042 if (wd->text) eina_stringshare_del(wd->text);
1044 _check_enable_returnkey(data);
1045 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1049 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1051 Widget_Data *wd = elm_widget_data_get(data);
1055 EINA_LIST_FOREACH(entries, l, entry)
1057 if (entry != data) elm_entry_select_none(entry);
1059 wd->have_selection = EINA_TRUE;
1060 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1061 #ifdef HAVE_ELEMENTARY_X
1062 if (wd->sel_notify_handler)
1064 const char *txt = elm_entry_selection_get(data);
1067 top = elm_widget_top_get(data);
1068 if ((top) && (elm_win_xwindow_get(top)))
1069 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP, txt);
1075 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1077 Widget_Data *wd = elm_widget_data_get(data);
1079 wd->have_selection = EINA_TRUE;
1080 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1081 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_MARKUP,
1082 elm_entry_selection_get(data));
1086 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1088 Widget_Data *wd = elm_widget_data_get(data);
1090 if (!wd->have_selection) return;
1091 wd->have_selection = EINA_FALSE;
1092 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1093 if (wd->sel_notify_handler)
1097 #ifdef HAVE_ELEMENTARY_X
1100 top = elm_widget_top_get(data);
1101 if ((top) && (elm_win_xwindow_get(top)))
1102 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP,
1105 eina_stringshare_del(wd->cut_sel);
1110 #ifdef HAVE_ELEMENTARY_X
1113 top = elm_widget_top_get(data);
1114 if ((top) && (elm_win_xwindow_get(top)))
1115 elm_selection_clear(ELM_SEL_PRIMARY, data);
1122 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1124 Widget_Data *wd = elm_widget_data_get(data);
1126 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1127 if (wd->sel_notify_handler)
1129 #ifdef HAVE_ELEMENTARY_X
1132 top = elm_widget_top_get(data);
1133 if ((top) && (elm_win_xwindow_get(top)))
1135 wd->selection_asked = EINA_TRUE;
1136 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_MARKUP, data);
1143 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1145 Widget_Data *wd = elm_widget_data_get(data);
1147 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1148 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1149 elm_entry_selection_get(data));
1153 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1155 Widget_Data *wd = elm_widget_data_get(data);
1157 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1158 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1159 elm_entry_selection_get(data));
1160 edje_object_part_text_insert(wd->ent, "elm.text", "");
1161 wd->changed = EINA_TRUE;
1166 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1168 Widget_Data *wd = elm_widget_data_get(data);
1169 Evas_Coord cx, cy, cw, ch;
1171 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1172 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1173 &cx, &cy, &cw, &ch);
1174 if (!wd->deferred_recalc_job)
1175 elm_widget_show_region_set(data, cx, cy, cw, ch);
1178 wd->deferred_cur = EINA_TRUE;
1187 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1189 Widget_Data *wd = elm_widget_data_get(data);
1194 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1196 Widget_Data *wd = elm_widget_data_get(data);
1197 Elm_Entry_Anchor_Info ei;
1198 char *buf2, *p, *p2, *n;
1200 p = strrchr(emission, ',');
1203 const Eina_List *geoms;
1207 while (p2 >= emission)
1209 if (*p2 == ',') break;
1213 buf2 = alloca(5 + p - p2);
1214 strncpy(buf2, p2, p - p2);
1217 ei.button = atoi(buf2);
1218 ei.x = ei.y = ei.w = ei.h = 0;
1220 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1223 Evas_Textblock_Rectangle *r;
1225 Evas_Coord px, py, x, y;
1227 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1228 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1229 EINA_LIST_FOREACH(geoms, l, r)
1231 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1232 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1243 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1248 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1250 Widget_Data *wd = elm_widget_data_get(data);
1255 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1257 Widget_Data *wd = elm_widget_data_get(data);
1262 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1264 Widget_Data *wd = elm_widget_data_get(data);
1269 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1271 Widget_Data *wd = elm_widget_data_get(data);
1273 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1277 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1279 Widget_Data *wd = elm_widget_data_get(data);
1281 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1285 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1287 Widget_Data *wd = elm_widget_data_get(data);
1289 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1293 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1295 Widget_Data *wd = elm_widget_data_get(data);
1297 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1300 #ifdef HAVE_ELEMENTARY_X
1302 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1304 Widget_Data *wd = elm_widget_data_get(data);
1305 Ecore_X_Event_Selection_Notify *ev = event;
1306 if (!wd) return ECORE_CALLBACK_PASS_ON;
1307 if (!wd->selection_asked) return ECORE_CALLBACK_PASS_ON;
1309 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1310 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1312 Ecore_X_Selection_Data_Text *text_data;
1314 text_data = ev->data;
1315 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1317 if (text_data->text)
1319 char *txt = _text_to_mkup(text_data->text);
1323 elm_entry_entry_insert(data, txt);
1328 wd->selection_asked = EINA_FALSE;
1330 return ECORE_CALLBACK_PASS_ON;
1334 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1337 Widget_Data *wd = elm_widget_data_get(data);
1338 Ecore_X_Event_Selection_Clear *ev = event;
1340 if (!wd->have_selection) return 1;
1341 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1342 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1344 elm_entry_select_none(data);
1349 Evas_Object *top = elm_widget_top_get(data);
1350 Ecore_X_Event_Selection_Clear *ev = event;
1353 return ECORE_CALLBACK_PASS_ON;
1355 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1357 return ECORE_CALLBACK_PASS_ON;
1360 elm_selection_get(1/*ELM_SEL_SECONDARY*/,0x1/*Markup */,data);
1362 return ECORE_CALLBACK_PASS_ON;
1366 static Evas_Object *
1367 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1369 Widget_Data *wd = elm_widget_data_get(data);
1372 Elm_Entry_Item_Provider *ip;
1375 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1377 o = ip->func(ip->data, data, item);
1380 o = edje_object_add(evas_object_evas_get(data));
1381 if (!strncmp(item, "emoticon/", 9))
1382 ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1384 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1389 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1391 char *curlocater, *starttag, *endtag;
1392 int firstindex = 0, foundflag = -1;
1394 curlocater = strstr(oldstring, key);
1397 starttag = curlocater;
1398 endtag = curlocater + strlen(key);
1399 if (endtag == NULL || *endtag != '=')
1405 firstindex = abs(oldstring - curlocater);
1406 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1407 *value = (char*)oldstring + firstindex;
1409 while (oldstring != starttag)
1411 if (*starttag == '>')
1416 if (*starttag == '<')
1420 if (starttag == NULL) break;
1423 while (NULL != endtag)
1434 if (endtag == NULL) break;
1437 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1447 if (foundflag == 1) return 0;
1453 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1455 const char *srcstring = NULL;
1456 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1457 char *curlocater, *replocater;
1458 char *starttag, *endtag;
1459 int tagtxtlen = 0, insertflag = 0;
1461 srcstring = eina_strbuf_string_get(srcbuf);
1462 curlocater = strstr(srcstring, key);
1464 if (curlocater == NULL)
1472 starttag = strchr(srcstring, '<');
1473 endtag = strchr(srcstring, '>');
1474 tagtxtlen = endtag - starttag;
1475 if (tagtxtlen <= 0) tagtxtlen = 0;
1476 if (starttag < curlocater && curlocater < endtag) break;
1477 if (endtag != NULL && endtag+1 != NULL)
1478 srcstring = endtag+1;
1481 } while (strlen(srcstring) > 1);
1483 if (starttag && endtag && tagtxtlen > strlen(key))
1485 repbuf = eina_strbuf_new();
1486 diffbuf = eina_strbuf_new();
1487 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1488 srcstring = eina_strbuf_string_get(repbuf);
1489 curlocater = strstr(srcstring, key);
1491 if (curlocater != NULL)
1493 replocater = curlocater + strlen(key) + 1;
1495 while (*replocater == ' ' || *replocater == '=')
1500 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1503 if (replocater-curlocater > strlen(key)+1)
1506 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1515 eina_strbuf_reset(repbuf);
1523 if (repbuf == NULL) repbuf = eina_strbuf_new();
1524 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1528 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1529 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1535 eina_strbuf_prepend(diffbuf, "<");
1536 eina_strbuf_append(diffbuf, ">");
1537 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1541 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1542 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1546 if (repbuf) eina_strbuf_free(repbuf);
1547 if (diffbuf) eina_strbuf_free(diffbuf);
1553 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1555 Eina_Strbuf *sharebuf = NULL;
1557 sharebuf = eina_strbuf_new();
1558 eina_strbuf_append(sharebuf, *srcstring);
1559 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1560 eina_stringshare_del(*srcstring);
1561 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1562 eina_strbuf_free(sharebuf);
1568 _is_width_over(Evas_Object *obj)
1570 Evas_Coord x, y, w, h;
1571 Evas_Coord vx, vy, vw, vh;
1572 Widget_Data *wd = elm_widget_data_get(obj);
1576 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1578 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1580 if (x >= 0 && y >= 0)
1583 if (4 < wd->wrap_w && w > wd->wrap_w)
1590 _reverse_ellipsis_entry(Evas_Object *obj)
1592 Widget_Data *wd = elm_widget_data_get(obj);
1593 int cur_fontsize = 0;
1594 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1595 char **kvalue = NULL;
1596 const char *minfont, *deffont, *maxfont;
1597 const char *ellipsis_string = "...";
1598 int minfontsize, maxfontsize, minshowcount;
1600 minshowcount = strlen(ellipsis_string) + 1;
1601 minfont = edje_object_data_get(wd->ent, "min_font_size");
1602 if (minfont) minfontsize = atoi(minfont);
1603 else minfontsize = 1;
1604 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1605 if (maxfont) maxfontsize = atoi(maxfont);
1606 else maxfontsize = 1;
1607 deffont = edje_object_data_get(wd->ent, "default_font_size");
1608 if (deffont) cur_fontsize = atoi(deffont);
1609 else cur_fontsize = 1;
1610 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1611 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1613 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1615 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1618 txtbuf = eina_strbuf_new();
1619 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1621 if (cur_fontsize >= atoi(deffont))
1623 if (txtbuf) eina_strbuf_free(txtbuf);
1627 if (_is_width_over(obj) != 1)
1629 int rev_fontsize = cur_fontsize;
1633 if (rev_fontsize > atoi(deffont))
1636 if (fontbuf != NULL)
1638 eina_strbuf_free(fontbuf);
1641 fontbuf = eina_strbuf_new();
1642 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1643 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1644 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1646 eina_strbuf_free(fontbuf);
1648 } while (_is_width_over(obj) != 1);
1650 while (_is_width_over(obj))
1653 if (rev_fontsize < atoi(deffont))
1656 if (fontbuf != NULL)
1658 eina_strbuf_free(fontbuf);
1661 fontbuf = eina_strbuf_new();
1662 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1663 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1664 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1665 eina_strbuf_free(fontbuf);
1670 if (txtbuf) eina_strbuf_free(txtbuf);
1676 _ellipsis_entry_to_width(Evas_Object *obj)
1678 Widget_Data *wd = elm_widget_data_get(obj);
1679 int cur_fontsize = 0, len, jumpcount;
1680 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1681 char **kvalue = NULL;
1682 const char *minfont, *deffont, *maxfont;
1683 const char *ellipsis_string = "...";
1684 int minfontsize, maxfontsize, minshowcount;
1685 int i, tagend, cur_len;
1688 minshowcount = strlen(ellipsis_string) + 1;
1689 minfont = edje_object_data_get(wd->ent, "min_font_size");
1690 if (minfont) minfontsize = atoi(minfont);
1691 else minfontsize = 1;
1692 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1693 if (maxfont) maxfontsize = atoi(maxfont);
1694 else maxfontsize = 1;
1695 deffont = edje_object_data_get(wd->ent, "default_font_size");
1696 if (deffont) cur_fontsize = atoi(deffont);
1697 else cur_fontsize = 1;
1698 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1699 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1701 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1703 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1706 txtbuf = eina_strbuf_new();
1707 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1709 while (_is_width_over(obj))
1711 if (wd->ellipsis_threshold == 0)
1712 wd->ellipsis_threshold = _entry_length_get(obj);
1713 if (cur_fontsize > minfontsize)
1716 if (fontbuf != NULL)
1718 eina_strbuf_free(fontbuf);
1721 fontbuf = eina_strbuf_new();
1722 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1723 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1724 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1725 eina_strbuf_free(fontbuf);
1727 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1731 len = _entry_length_get(obj);
1732 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1733 cur_len = strlen(cur_str);
1735 for (i = 0; i < len; i++)
1737 if(cur_str[i] == '>' && cur_str[i+1] != NULL &&
1738 cur_str[i+1] != '<')
1745 while (jumpcount < len-strlen(ellipsis_string))
1747 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1751 eina_strbuf_free(txtbuf);
1754 txtbuf = eina_strbuf_new();
1755 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1756 eina_strbuf_append(txtbuf, ellipsis_string);
1757 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1758 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1759 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1761 if (_is_width_over(obj))
1769 if (txtbuf) eina_strbuf_free(txtbuf);
1774 static int _textinput_control_function(void *data,void *input_data)
1776 /*calculate character count*/
1777 Evas_Object *entry = (Evas_Object *)data;
1778 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1781 size_t insert_text_len=0;
1782 char *text = edje_object_part_text_get(wd->ent, "elm.text");
1784 size_t remain_bytes;
1787 byte_len = strlen(text);/*no of bytes*/
1788 remain_bytes = wd->max_no_of_bytes-byte_len;
1789 sprintf(buf,"%d",remain_bytes);
1790 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1793 insert_text = (char *)input_data;
1794 insert_text_len = strlen(insert_text);
1795 if(remain_bytes<insert_text_len)
1797 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1800 if(byte_len>=wd->max_no_of_bytes)
1802 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1811 * This adds an entry to @p parent object.
1813 * @param parent The parent object
1814 * @return The new object or NULL if it cannot be created
1819 elm_entry_add(Evas_Object *parent)
1821 Evas_Object *obj, *top;
1825 wd = ELM_NEW(Widget_Data);
1826 e = evas_object_evas_get(parent);
1827 wd->bgcolor = EINA_FALSE;
1828 wd->bg = evas_object_rectangle_add(e);
1829 evas_object_color_set(wd->bg, 0, 0, 0, 0);
1830 obj = elm_widget_add(e);
1831 ELM_SET_WIDTYPE(widtype, "entry");
1832 elm_widget_type_set(obj, "entry");
1833 elm_widget_sub_object_add(parent, obj);
1834 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1835 elm_widget_data_set(obj, wd);
1836 elm_widget_del_hook_set(obj, _del_hook);
1837 elm_widget_theme_hook_set(obj, _theme_hook);
1838 elm_widget_disable_hook_set(obj, _disable_hook);
1839 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1840 elm_widget_can_focus_set(obj, 1);
1842 wd->linewrap = EINA_TRUE;
1843 wd->ellipsis = EINA_FALSE;
1844 wd->char_linewrap= EINA_FALSE;
1845 wd->editable = EINA_TRUE;
1846 wd->disabled = EINA_FALSE;
1847 wd->context_menu = EINA_TRUE;
1849 wd->ellipsis_threshold = 0;
1851 wd->ent = edje_object_add(e);
1852 edje_object_item_provider_set(wd->ent, _get_item, obj);
1853 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1854 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1855 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1857 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1859 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1862 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1863 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1864 _signal_entry_changed, obj);
1865 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1866 _signal_selection_start, obj);
1867 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1868 _signal_selection_changed, obj);
1869 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1870 _signal_selection_cleared, obj);
1871 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1872 _signal_entry_paste_request, obj);
1873 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1874 _signal_entry_copy_notify, obj);
1875 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1876 _signal_entry_cut_notify, obj);
1877 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1878 _signal_cursor_changed, obj);
1879 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1880 _signal_anchor_down, obj);
1881 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1882 _signal_anchor_up, obj);
1883 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1884 _signal_anchor_move, obj);
1885 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1886 _signal_anchor_in, obj);
1887 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1888 _signal_anchor_out, obj);
1889 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1890 _signal_key_enter, obj);
1891 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1892 _signal_mouse_down, obj);
1893 edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
1894 _signal_mouse_up, obj);
1895 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1896 _signal_mouse_double, obj);
1897 edje_object_part_text_set(wd->ent, "elm.text", "");
1898 elm_widget_resize_object_set(obj, wd->ent);
1901 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
1903 #ifdef HAVE_ELEMENTARY_X
1904 top = elm_widget_top_get(obj);
1905 if ((top) && (elm_win_xwindow_get(top)))
1907 wd->sel_notify_handler =
1908 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1909 _event_selection_notify, obj);
1910 wd->sel_clear_handler =
1911 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1912 _event_selection_clear, obj);
1916 entries = eina_list_prepend(entries, obj);
1918 // module - find module for entry
1919 wd->api = _module(obj);
1920 // if found - hook in
1921 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1923 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1924 // TODO: and save some bytes, making descriptions per-class and not instance!
1925 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1929 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
1931 ELM_CHECK_WIDTYPE(obj, widtype);
1932 Widget_Data *wd = elm_widget_data_get(obj);
1934 ext_mod->cancel = _cancel;
1935 ext_mod->copy = _copy;
1936 ext_mod->cut = _cut;
1937 ext_mod->paste = _paste;
1938 ext_mod->select = _select;
1939 ext_mod->selectall = NULL; /* to be implemented*/
1940 ext_mod->ent = wd->ent;
1941 ext_mod->items = wd->items;
1942 ext_mod->longpress_timer = wd->longpress_timer;
1943 ext_mod->editable = wd->editable;
1944 ext_mod->have_selection = wd->have_selection;
1945 ext_mod->password = wd->password;
1946 ext_mod->selmode = wd->selmode;
1947 ext_mod->context_menu = wd->context_menu;
1951 * This sets the entry object not to line wrap. All input will
1952 * be on a single line, and the entry box will extend with user input.
1954 * @param obj The entry object
1955 * @param single_line If true, the text in the entry
1956 * will be on a single line.
1961 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1963 ELM_CHECK_WIDTYPE(obj, widtype);
1964 Widget_Data *wd = elm_widget_data_get(obj);
1966 Ecore_IMF_Context *ic;
1968 if (wd->single_line == single_line) return;
1969 wd->single_line = single_line;
1970 wd->linewrap = EINA_FALSE;
1971 wd->char_linewrap = EINA_FALSE;
1972 t = eina_stringshare_add(elm_entry_entry_get(obj));
1973 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1974 elm_entry_entry_set(obj, t);
1975 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
1976 // edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
1977 ic = elm_entry_imf_context_get(obj);
1980 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
1983 eina_stringshare_del(t);
1988 * This returns true if the entry has been set to single line mode.
1989 * See also elm_entry_single_line_set().
1991 * @param obj The entry object
1992 * @return single_line If true, the text in the entry is set to display
1998 elm_entry_single_line_get(const Evas_Object *obj)
2000 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2001 Widget_Data *wd = elm_widget_data_get(obj);
2002 if (!wd) return EINA_FALSE;
2003 return wd->single_line;
2007 * This set's the maximum bytes that can be added in entry.
2009 * @param obj The entry object
2010 * @param max_no_of_bytes Maximum number of bytes entry can have.
2015 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2017 Widget_Data *wd = elm_widget_data_get(obj);
2019 wd->max_no_of_bytes = max_no_of_bytes;
2020 edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2021 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2026 * This sets the entry object to password mode. All text entered
2027 * and/or displayed within the widget will be replaced with asterisks (*).
2029 * @param obj The entry object
2030 * @param password If true, password mode is enabled.
2035 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2037 ELM_CHECK_WIDTYPE(obj, widtype);
2038 Widget_Data *wd = elm_widget_data_get(obj);
2039 Ecore_IMF_Context *ic;
2042 if (wd->password == password) return;
2043 wd->password = password;
2044 wd->show_last_character = EINA_FALSE;
2045 wd->single_line = EINA_TRUE;
2046 wd->linewrap = EINA_FALSE;
2047 wd->char_linewrap = EINA_FALSE;
2048 t = eina_stringshare_add(elm_entry_entry_get(obj));
2049 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2050 elm_entry_entry_set(obj, t);
2052 ic = elm_entry_imf_context_get(obj);
2055 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2058 eina_stringshare_del(t);
2063 * This set's the entry in password mode with out masking the last character entered by user,
2064 * and later masking the character after 2 seconds.
2066 * @param obj The entry object
2067 * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character"
2073 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2075 Widget_Data *wd = elm_widget_data_get(obj);
2078 if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character)) return;
2079 wd->show_last_character = show_last_character;
2080 wd->password = show_last_character;
2081 wd->single_line = EINA_TRUE;
2082 wd->linewrap = EINA_FALSE;
2083 wd->char_linewrap = EINA_FALSE;
2084 t = eina_stringshare_add(elm_entry_entry_get(obj));
2085 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2086 elm_entry_entry_set(obj, t);
2087 eina_stringshare_del(t);
2092 * This returns whether password mode is enabled.
2093 * See also elm_entry_password_set().
2095 * @param obj The entry object
2096 * @return If true, the entry is set to display all characters
2102 elm_entry_password_get(const Evas_Object *obj)
2104 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2105 Widget_Data *wd = elm_widget_data_get(obj);
2106 if (!wd) return EINA_FALSE;
2107 return wd->password;
2111 * This sets the text displayed within the entry to @p entry.
2113 * @param obj The entry object
2114 * @param entry The text to be displayed
2119 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2121 ELM_CHECK_WIDTYPE(obj, widtype);
2122 Widget_Data *wd = elm_widget_data_get(obj);
2124 if (!entry) entry = "";
2125 if(wd->max_no_of_bytes)
2127 int len = strlen(entry);
2128 if(len > wd->max_no_of_bytes)
2130 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2134 edje_object_part_text_set(wd->ent, "elm.text", entry);
2135 if (wd->text) eina_stringshare_del(wd->text);
2137 wd->changed = EINA_TRUE;
2142 * This returns the text currently shown in object @p entry.
2143 * See also elm_entry_entry_set().
2145 * @param obj The entry object
2146 * @return The currently displayed text or NULL on failure
2151 elm_entry_entry_get(const Evas_Object *obj)
2153 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2154 Widget_Data *wd = elm_widget_data_get(obj);
2156 if (!wd) return NULL;
2157 if (wd->text) return wd->text;
2158 text = edje_object_part_text_get(wd->ent, "elm.text");
2161 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2164 eina_stringshare_replace(&wd->text, text);
2169 * This returns all selected text within the entry.
2171 * @param obj The entry object
2172 * @return The selected text within the entry or NULL on failure
2177 elm_entry_selection_get(const Evas_Object *obj)
2179 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2180 Widget_Data *wd = elm_widget_data_get(obj);
2181 if (!wd) return NULL;
2182 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2186 * This inserts text in @p entry at the beginning of the entry
2189 * @param obj The entry object
2190 * @param entry The text to insert
2195 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2197 ELM_CHECK_WIDTYPE(obj, widtype);
2198 Widget_Data *wd = elm_widget_data_get(obj);
2200 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2201 wd->changed = EINA_TRUE;
2206 * This enables word line wrapping in the entry object. It is the opposite
2207 * of elm_entry_single_line_set(). Additionally, setting this disables
2208 * character line wrapping.
2209 * See also elm_entry_line_char_wrap_set().
2211 * @param obj The entry object
2212 * @param wrap If true, the entry will be wrapped once it reaches the end
2213 * of the object. Wrapping will occur at the end of the word before the end of the
2219 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2221 ELM_CHECK_WIDTYPE(obj, widtype);
2222 Widget_Data *wd = elm_widget_data_get(obj);
2225 if (wd->linewrap == wrap) return;
2226 wd->linewrap = wrap;
2228 wd->char_linewrap = EINA_FALSE;
2229 t = eina_stringshare_add(elm_entry_entry_get(obj));
2230 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2231 elm_entry_entry_set(obj, t);
2232 eina_stringshare_del(t);
2237 * Set wrap width of the entry
2239 * @param obj The entry object
2240 * @param w The wrap width in pixels at a minimum where words need to wrap
2244 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2246 Widget_Data *wd = elm_widget_data_get(obj);
2247 if (wd->wrap_w == w) return;
2253 * get wrap width of the entry
2255 * @param obj The entry object
2256 * @return The wrap width in pixels at a minimum where words need to wrap
2260 elm_entry_wrap_width_get(const Evas_Object *obj)
2262 Widget_Data *wd = elm_widget_data_get(obj);
2267 * This enables character line wrapping in the entry object. It is the opposite
2268 * of elm_entry_single_line_set(). Additionally, setting this disables
2269 * word line wrapping.
2270 * See also elm_entry_line_wrap_set().
2272 * @param obj The entry object
2273 * @param wrap If true, the entry will be wrapped once it reaches the end
2274 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2279 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2281 ELM_CHECK_WIDTYPE(obj, widtype);
2282 Widget_Data *wd = elm_widget_data_get(obj);
2285 if (wd->char_linewrap == wrap) return;
2286 wd->char_linewrap = wrap;
2287 if(wd->char_linewrap)
2288 wd->linewrap = EINA_FALSE;
2289 t = eina_stringshare_add(elm_entry_entry_get(obj));
2290 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2291 elm_entry_entry_set(obj, t);
2292 eina_stringshare_del(t);
2297 * This sets the editable attribute of the entry.
2299 * @param obj The entry object
2300 * @param editable If true, the entry will be editable by the user.
2301 * If false, it will be set to the disabled state.
2306 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2308 ELM_CHECK_WIDTYPE(obj, widtype);
2309 Widget_Data *wd = elm_widget_data_get(obj);
2312 if (wd->editable == editable) return;
2313 wd->editable = editable;
2314 t = eina_stringshare_add(elm_entry_entry_get(obj));
2315 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2316 elm_entry_entry_set(obj, t);
2317 eina_stringshare_del(t);
2322 * This gets the editable attribute of the entry.
2323 * See also elm_entry_editable_set().
2325 * @param obj The entry object
2326 * @return If true, the entry is editable by the user.
2327 * If false, it is not editable by the user
2332 elm_entry_editable_get(const Evas_Object *obj)
2334 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2335 Widget_Data *wd = elm_widget_data_get(obj);
2336 if (!wd) return EINA_FALSE;
2337 return wd->editable;
2341 * This drops any existing text selection within the entry.
2343 * @param obj The entry object
2348 elm_entry_select_none(Evas_Object *obj)
2350 ELM_CHECK_WIDTYPE(obj, widtype);
2351 Widget_Data *wd = elm_widget_data_get(obj);
2355 wd->selmode = EINA_FALSE;
2356 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2357 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2359 wd->have_selection = EINA_FALSE;
2360 edje_object_part_text_select_none(wd->ent, "elm.text");
2364 * This selects all text within the entry.
2366 * @param obj The entry object
2371 elm_entry_select_all(Evas_Object *obj)
2373 ELM_CHECK_WIDTYPE(obj, widtype);
2374 Widget_Data *wd = elm_widget_data_get(obj);
2378 wd->selmode = EINA_FALSE;
2379 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2380 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2382 wd->have_selection = EINA_TRUE;
2383 edje_object_part_text_select_all(wd->ent, "elm.text");
2387 * This moves the cursor one place to the right within the entry.
2389 * @param obj The entry object
2390 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2395 elm_entry_cursor_next(Evas_Object *obj)
2397 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2398 Widget_Data *wd = elm_widget_data_get(obj);
2399 if (!wd) return EINA_FALSE;
2400 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2404 * This moves the cursor one place to the left within the entry.
2406 * @param obj The entry object
2407 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2412 elm_entry_cursor_prev(Evas_Object *obj)
2414 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2415 Widget_Data *wd = elm_widget_data_get(obj);
2416 if (!wd) return EINA_FALSE;
2417 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2421 * This moves the cursor one line up within the entry.
2423 * @param obj The entry object
2424 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2429 elm_entry_cursor_up(Evas_Object *obj)
2431 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2432 Widget_Data *wd = elm_widget_data_get(obj);
2433 if (!wd) return EINA_FALSE;
2434 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2438 * This moves the cursor one line down within the entry.
2440 * @param obj The entry object
2441 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2446 elm_entry_cursor_down(Evas_Object *obj)
2448 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2449 Widget_Data *wd = elm_widget_data_get(obj);
2450 if (!wd) return EINA_FALSE;
2451 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2455 * This moves the cursor to the beginning of the entry.
2457 * @param obj The entry object
2462 elm_entry_cursor_begin_set(Evas_Object *obj)
2464 ELM_CHECK_WIDTYPE(obj, widtype);
2465 Widget_Data *wd = elm_widget_data_get(obj);
2467 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2471 * This moves the cursor to the end of the entry.
2473 * @param obj The entry object
2478 elm_entry_cursor_end_set(Evas_Object *obj)
2480 ELM_CHECK_WIDTYPE(obj, widtype);
2481 Widget_Data *wd = elm_widget_data_get(obj);
2483 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2487 * This moves the cursor to the beginning of the current line.
2489 * @param obj The entry object
2494 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2496 ELM_CHECK_WIDTYPE(obj, widtype);
2497 Widget_Data *wd = elm_widget_data_get(obj);
2499 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2503 * This moves the cursor to the end of the current line.
2505 * @param obj The entry object
2510 elm_entry_cursor_line_end_set(Evas_Object *obj)
2512 ELM_CHECK_WIDTYPE(obj, widtype);
2513 Widget_Data *wd = elm_widget_data_get(obj);
2515 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2519 * This begins a selection within the entry as though
2520 * the user were holding down the mouse button to make a selection.
2522 * @param obj The entry object
2527 elm_entry_cursor_selection_begin(Evas_Object *obj)
2529 ELM_CHECK_WIDTYPE(obj, widtype);
2530 Widget_Data *wd = elm_widget_data_get(obj);
2532 edje_object_part_text_select_begin(wd->ent, "elm.text");
2536 * This ends a selection within the entry as though
2537 * the user had just released the mouse button while making a selection.
2539 * @param obj The entry object
2544 elm_entry_cursor_selection_end(Evas_Object *obj)
2546 ELM_CHECK_WIDTYPE(obj, widtype);
2547 Widget_Data *wd = elm_widget_data_get(obj);
2549 edje_object_part_text_select_extend(wd->ent, "elm.text");
2553 * TODO: fill this in
2555 * @param obj The entry object
2556 * @return TODO: fill this in
2561 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2563 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2564 Widget_Data *wd = elm_widget_data_get(obj);
2565 if (!wd) return EINA_FALSE;
2566 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2570 * This returns whether the cursor is visible.
2572 * @param obj The entry object
2573 * @return If true, the cursor is visible.
2578 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2580 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2581 Widget_Data *wd = elm_widget_data_get(obj);
2582 if (!wd) return EINA_FALSE;
2583 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2587 * TODO: fill this in
2589 * @param obj The entry object
2590 * @return TODO: fill this in
2595 elm_entry_cursor_content_get(const Evas_Object *obj)
2597 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2598 Widget_Data *wd = elm_widget_data_get(obj);
2599 if (!wd) return NULL;
2600 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2604 * This executes a "cut" action on the selected text in the entry.
2606 * @param obj The entry object
2611 elm_entry_selection_cut(Evas_Object *obj)
2613 ELM_CHECK_WIDTYPE(obj, widtype);
2614 Widget_Data *wd = elm_widget_data_get(obj);
2616 _cut(obj, NULL, NULL);
2620 * This executes a "copy" action on the selected text in the entry.
2622 * @param obj The entry object
2627 elm_entry_selection_copy(Evas_Object *obj)
2629 ELM_CHECK_WIDTYPE(obj, widtype);
2630 Widget_Data *wd = elm_widget_data_get(obj);
2632 _copy(obj, NULL, NULL);
2636 * This executes a "paste" action in the entry.
2638 * @param obj The entry object
2643 elm_entry_selection_paste(Evas_Object *obj)
2645 ELM_CHECK_WIDTYPE(obj, widtype);
2646 Widget_Data *wd = elm_widget_data_get(obj);
2648 _paste(obj, NULL, NULL);
2652 * This clears and frees the items in a entry's contextual (right click) menu.
2654 * @param obj The entry object
2659 elm_entry_context_menu_clear(Evas_Object *obj)
2661 ELM_CHECK_WIDTYPE(obj, widtype);
2662 Widget_Data *wd = elm_widget_data_get(obj);
2663 Elm_Entry_Context_Menu_Item *it;
2665 EINA_LIST_FREE(wd->items, it)
2667 eina_stringshare_del(it->label);
2668 eina_stringshare_del(it->icon_file);
2669 eina_stringshare_del(it->icon_group);
2675 * This adds an item to the entry's contextual menu.
2677 * @param obj The entry object
2678 * @param label The item's text label
2679 * @param icon_file The item's icon file
2680 * @param icon_type The item's icon type
2681 * @param func The callback to execute when the item is clicked
2682 * @param data The data to associate with the item for related functions
2687 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)
2689 ELM_CHECK_WIDTYPE(obj, widtype);
2690 Widget_Data *wd = elm_widget_data_get(obj);
2691 Elm_Entry_Context_Menu_Item *it;
2693 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2695 wd->items = eina_list_append(wd->items, it);
2697 it->label = eina_stringshare_add(label);
2698 it->icon_file = eina_stringshare_add(icon_file);
2699 it->icon_type = icon_type;
2701 it->data = (void *)data;
2705 * This disables the entry's contextual (right click) menu.
2707 * @param obj The entry object
2708 * @param disabled If true, the menu is disabled
2713 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2715 ELM_CHECK_WIDTYPE(obj, widtype);
2716 Widget_Data *wd = elm_widget_data_get(obj);
2718 if (wd->context_menu == !disabled) return;
2719 wd->context_menu = !disabled;
2723 * This returns whether the entry's contextual (right click) menu is disabled.
2725 * @param obj The entry object
2726 * @return If true, the menu is disabled
2731 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2733 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2734 Widget_Data *wd = elm_widget_data_get(obj);
2735 if (!wd) return EINA_FALSE;
2736 return !wd->context_menu;
2740 * This appends a custom item provider to the list for that entry
2742 * This appends the given callback. The list is walked from beginning to end
2743 * with each function called given the item href string in the text. If the
2744 * function returns an object handle other than NULL (it should create an
2745 * and object to do this), then this object is used to replace that item. If
2746 * not the next provider is called until one provides an item object, or the
2747 * default provider in entry does.
2749 * @param obj The entry object
2750 * @param func The function called to provide the item object
2751 * @param data The data passed to @p func
2756 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2758 ELM_CHECK_WIDTYPE(obj, widtype);
2759 Widget_Data *wd = elm_widget_data_get(obj);
2762 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2766 wd->item_providers = eina_list_append(wd->item_providers, ip);
2770 * This prepends a custom item provider to the list for that entry
2772 * This prepends the given callback. See elm_entry_item_provider_append() for
2775 * @param obj The entry object
2776 * @param func The function called to provide the item object
2777 * @param data The data passed to @p func
2782 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2784 ELM_CHECK_WIDTYPE(obj, widtype);
2785 Widget_Data *wd = elm_widget_data_get(obj);
2788 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2792 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2796 * This removes a custom item provider to the list for that entry
2798 * This removes the given callback. See elm_entry_item_provider_append() for
2801 * @param obj The entry object
2802 * @param func The function called to provide the item object
2803 * @param data The data passed to @p func
2808 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2810 ELM_CHECK_WIDTYPE(obj, widtype);
2811 Widget_Data *wd = elm_widget_data_get(obj);
2813 Elm_Entry_Item_Provider *ip;
2816 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2818 if ((ip->func == func) && (ip->data == data))
2820 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2828 * This converts a markup (HTML-like) string into UTF-8.
2830 * @param s The string (in markup) to be converted
2831 * @return The converted string (in UTF-8)
2836 elm_entry_markup_to_utf8(const char *s)
2838 char *ss = _mkup_to_text(s);
2839 if (!ss) ss = strdup("");
2844 * This converts a UTF-8 string into markup (HTML-like).
2846 * @param s The string (in UTF-8) to be converted
2847 * @return The converted string (in markup)
2852 elm_entry_utf8_to_markup(const char *s)
2854 char *ss = _text_to_mkup(s);
2855 if (!ss) ss = strdup("");
2860 * Get the input method context in the entry widget
2862 * @param obj The entry object
2863 * @return The input method context
2867 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2869 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2870 Widget_Data *wd = elm_widget_data_get(obj);
2871 if (!wd || !wd->ent) return NULL;
2873 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2877 * Set whether entry should enable the return key on soft keyboard automatically
2879 * @param obj The entry object
2880 * @param on If true, entry enables the return key on soft keyboard automatically.
2885 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
2887 ELM_CHECK_WIDTYPE(obj, widtype);
2888 Widget_Data *wd = elm_widget_data_get(obj);
2891 wd->autoreturnkey = on;
2892 _check_enable_returnkey(obj);
2896 * Set whether entry should support auto capitalization
2898 * @param obj The entry object
2899 * @param on If true, entry suports auto capitalization.
2904 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
2906 ELM_CHECK_WIDTYPE(obj, widtype);
2907 Widget_Data *wd = elm_widget_data_get(obj);
2911 wd->autocapitalize = EINA_FALSE;
2913 wd->autocapitalize = autocap;
2915 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2919 * Set whether entry should support auto period
2921 * @param obj The entry object
2922 * @param on If true, entry suports auto period.
2927 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
2929 ELM_CHECK_WIDTYPE(obj, widtype);
2930 Widget_Data *wd = elm_widget_data_get(obj);
2934 wd->autoperiod = EINA_FALSE;
2936 wd->autoperiod = autoperiod;
2938 // edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2942 * Set the font size on the entry object
2944 * @param obj The entry object
2945 * @param size font size
2950 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
2952 ELM_CHECK_WIDTYPE(obj, widtype);
2953 Widget_Data *wd = elm_widget_data_get(obj);
2954 Eina_Strbuf *fontbuf = NULL;
2959 t = eina_stringshare_add(elm_entry_entry_get(obj));
2960 fontbuf = eina_strbuf_new();
2961 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
2963 if (fontsize == 0) removeflag = 1; // remove fontsize tag
2965 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
2967 elm_entry_entry_set(obj, t);
2971 eina_strbuf_free(fontbuf);
2972 eina_stringshare_del(t);
2976 * Set the text align on the entry object
2978 * @param obj The entry object
2979 * @param align align mode
2984 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
2986 ELM_CHECK_WIDTYPE(obj, widtype);
2987 Widget_Data *wd = elm_widget_data_get(obj);
2992 t = eina_stringshare_add(elm_entry_entry_get(obj));
2994 if (len <= 0) return;
2996 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
2997 elm_entry_entry_set(obj, t);
3001 eina_stringshare_del(t);
3005 * Set the text color on the entry object
3007 * @param obj The entry object
3008 * @param r Red property background color of The entry object
3009 * @param g Green property background color of The entry object
3010 * @param b Blue property background color of The entry object
3011 * @param a Alpha property background alpha of The entry object
3016 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3018 ELM_CHECK_WIDTYPE(obj, widtype);
3019 Widget_Data *wd = elm_widget_data_get(obj);
3020 Eina_Strbuf *colorbuf = NULL;
3025 t = eina_stringshare_add(elm_entry_entry_get(obj));
3027 if (len <= 0) return;
3028 colorbuf = eina_strbuf_new();
3029 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3031 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3033 elm_entry_entry_set(obj, t);
3037 eina_strbuf_free(colorbuf);
3038 eina_stringshare_del(t);
3043 * Set background color of the entry
3045 * @param obj The entry object
3046 * @param r Red property background color of The entry object
3047 * @param g Green property background color of The entry object
3048 * @param b Blue property background color of The entry object
3049 * @param a Alpha property background alpha of The entry object
3053 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3055 ELM_CHECK_WIDTYPE(obj, widtype);
3056 Widget_Data *wd = elm_widget_data_get(obj);
3057 evas_object_color_set(wd->bg, r, g, b, a);
3059 if (wd->bgcolor == EINA_FALSE)
3062 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3067 * Set the ellipsis behavior of the entry
3069 * @param obj The entry object
3070 * @param ellipsis To ellipsis text or not
3074 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3076 ELM_CHECK_WIDTYPE(obj, widtype);
3077 Widget_Data *wd = elm_widget_data_get(obj);
3078 if (wd->ellipsis == ellipsis) return;
3079 wd->ellipsis = ellipsis;
3085 * This sets the attribute to show the input panel automatically.
3087 * @param obj The entry object
3088 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3093 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3095 ELM_CHECK_WIDTYPE(obj, widtype);
3096 Widget_Data *wd = elm_widget_data_get(obj);
3099 wd->input_panel_enable = enabled;
3100 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3104 * Set the input panel layout of the entry
3106 * @param obj The entry object
3107 * @param layout the layout to set
3112 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3114 ELM_CHECK_WIDTYPE(obj, widtype);
3115 Widget_Data *wd = elm_widget_data_get(obj);
3118 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3121 wd->input_panel_layout = layout;
3123 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);