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");
407 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
408 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
409 _check_enable_returnkey(obj);
413 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
414 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", "");
415 evas_object_focus_set(wd->ent, 0);
416 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
417 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
422 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
424 Widget_Data *wd = elm_widget_data_get(obj);
426 edje_object_signal_emit(wd->ent, emission, source);
430 _hoversel_position(Evas_Object *obj)
432 Widget_Data *wd = elm_widget_data_get(obj);
433 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
435 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
436 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
438 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
449 evas_object_move(wd->hoversel, x + cx, y + cy);
450 evas_object_resize(wd->hoversel, cw, ch);
454 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
456 Widget_Data *wd = elm_widget_data_get(data);
458 if (wd->hoversel) _hoversel_position(data);
462 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
464 Widget_Data *wd = elm_widget_data_get(data);
466 if (wd->linewrap || wd->char_linewrap)
470 if (wd->hoversel) _hoversel_position(data);
471 // Evas_Coord ww, hh;
472 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
476 _hover_del(void *data)
478 Widget_Data *wd = elm_widget_data_get(data);
483 evas_object_del(wd->hoversel);
486 wd->hovdeljob = NULL;
490 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
492 Widget_Data *wd = elm_widget_data_get(data);
494 if (wd->hoversel) evas_object_hide(wd->hoversel);
498 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
500 elm_widget_scroll_freeze_pop(data);
501 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
502 wd->hovdeljob = ecore_job_add(_hover_del, data);
506 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
508 Widget_Data *wd = elm_widget_data_get(data);
510 wd->selmode = EINA_TRUE;
511 edje_object_part_text_select_none(wd->ent, "elm.text");
513 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
514 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
515 elm_widget_scroll_hold_push(data);
519 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
521 Widget_Data *wd = elm_widget_data_get(data);
523 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
524 if (wd->sel_notify_handler)
526 #ifdef HAVE_ELEMENTARY_X
527 wd->selection_asked = EINA_TRUE;
528 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_MARKUP, data);
534 _store_selection(enum _elm_sel_type seltype, Evas_Object *obj)
536 Widget_Data *wd = elm_widget_data_get(obj);
540 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
541 elm_selection_set(seltype, obj, ELM_SEL_MARKUP, sel);
542 if (seltype == ELM_SEL_CLIPBOARD)
543 eina_stringshare_replace(&wd->cut_sel, sel);
547 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
549 Widget_Data *wd = elm_widget_data_get(data);
552 wd->selmode = EINA_FALSE;
553 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
554 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
555 elm_widget_scroll_hold_pop(data);
556 _store_selection(ELM_SEL_CLIPBOARD, data);
557 edje_object_part_text_insert(wd->ent, "elm.text", "");
558 edje_object_part_text_select_none(wd->ent, "elm.text");
562 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
564 Widget_Data *wd = elm_widget_data_get(data);
566 wd->selmode = EINA_FALSE;
567 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
568 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
569 elm_widget_scroll_hold_pop(data);
570 _store_selection(ELM_SEL_CLIPBOARD, data);
571 // edje_object_part_text_select_none(wd->ent, "elm.text");
575 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
577 Widget_Data *wd = elm_widget_data_get(data);
579 wd->selmode = EINA_FALSE;
580 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
581 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
582 elm_widget_scroll_hold_pop(data);
583 edje_object_part_text_select_none(wd->ent, "elm.text");
587 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
589 Elm_Entry_Context_Menu_Item *it = data;
590 Evas_Object *obj2 = it->obj;
591 if (it->func) it->func(it->data, obj2, NULL);
595 _long_press(void *data)
597 Widget_Data *wd = elm_widget_data_get(data);
600 const Elm_Entry_Context_Menu_Item *it;
601 if (!wd) return ECORE_CALLBACK_CANCEL;
602 if ((wd->api) && (wd->api->obj_longpress))
604 wd->api->obj_longpress(data);
606 else if (wd->context_menu)
608 const char *context_menu_orientation;
610 if (wd->hoversel) evas_object_del(wd->hoversel);
611 else elm_widget_scroll_freeze_push(data);
612 wd->hoversel = elm_hoversel_add(data);
613 context_menu_orientation = edje_object_data_get
614 (wd->ent, "context_menu_orientation");
615 if ((context_menu_orientation) &&
616 (!strcmp(context_menu_orientation, "horizontal")))
617 elm_hoversel_horizontal_set(wd->hoversel, 1);
618 elm_object_style_set(wd->hoversel, "entry");
619 elm_widget_sub_object_add(data, wd->hoversel);
620 elm_hoversel_label_set(wd->hoversel, "Text");
621 top = elm_widget_top_get(data);
622 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
623 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
627 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
629 if (1) // need way to detect if someone has a selection
632 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
640 if (wd->have_selection)
642 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
645 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
648 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
652 EINA_LIST_FOREACH(wd->items, l, it)
654 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
655 it->icon_type, _item_clicked, it);
659 _hoversel_position(data);
660 evas_object_show(wd->hoversel);
661 elm_hoversel_hover_begin(wd->hoversel);
663 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
664 edje_object_part_text_select_abort(wd->ent, "elm.text");
666 wd->longpress_timer = NULL;
667 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
668 return ECORE_CALLBACK_CANCEL;
672 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
674 Widget_Data *wd = elm_widget_data_get(data);
675 Evas_Event_Mouse_Down *ev = event_info;
677 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
678 if (ev->button != 1) return;
679 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
680 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
681 wd->longpress_timer = ecore_timer_add(1.0, _long_press, data);
682 wd->downx = ev->canvas.x;
683 wd->downy = ev->canvas.y;
687 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
689 Widget_Data *wd = elm_widget_data_get(data);
690 Evas_Event_Mouse_Up *ev = event_info;
692 if (ev->button != 1) return;
693 if ((wd->api) && (wd->api->obj_mouseup))
695 wd->api->obj_mouseup(data);
697 if (wd->longpress_timer)
699 ecore_timer_del(wd->longpress_timer);
700 wd->longpress_timer = NULL;
705 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
707 Widget_Data *wd = elm_widget_data_get(data);
708 Evas_Event_Mouse_Move *ev = event_info;
712 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
714 if (wd->longpress_timer)
716 ecore_timer_del(wd->longpress_timer);
717 wd->longpress_timer = NULL;
720 else if (wd->longpress_timer)
724 dx = wd->downx - ev->cur.canvas.x;
726 dy = wd->downy - ev->cur.canvas.y;
729 ((_elm_config->finger_size / 2) *
730 (_elm_config->finger_size / 2)))
732 ecore_timer_del(wd->longpress_timer);
733 wd->longpress_timer = NULL;
737 else if (wd->longpress_timer)
741 dx = wd->downx - ev->cur.canvas.x;
743 dy = wd->downy - ev->cur.canvas.y;
746 ((_elm_config->finger_size / 2) *
747 (_elm_config->finger_size / 2)))
749 ecore_timer_del(wd->longpress_timer);
750 wd->longpress_timer = NULL;
756 _getbase(Evas_Object *obj)
758 Widget_Data *wd = elm_widget_data_get(obj);
759 if (!wd) return "base";
762 if((wd->password)&&(wd->show_last_character)) return "custom-password";
763 else if(wd->password) return "base-password";
766 if (wd->single_line) return "base-single";
769 if (wd->linewrap) return "base";
770 else if (wd->char_linewrap) return "base-charwrap";
771 else return "base-nowrap";
777 if((wd->password)&&(wd->show_last_character)) return "custom-password";
778 else if(wd->password) return "base-password";
781 if (wd->single_line) return "base-single-noedit";
784 if (wd->linewrap) return "base-noedit";
785 else if (wd->char_linewrap) return "base-noedit-charwrap";
786 else return "base-nowrap-noedit";
794 _str_append(char *str, const char *txt, int *len, int *alloc)
796 int txt_len = strlen(txt);
798 if (txt_len <= 0) return str;
799 if ((*len + txt_len) >= *alloc)
804 alloc2 = *alloc + txt_len + 128;
805 str2 = realloc(str, alloc2);
806 if (!str2) return str;
810 strcpy(str + *len, txt);
815 /*FIXME: Sholud be implemented somewhere else, it really depends on the context
816 * because some markups can be implemented otherwise according to style.
817 * probably doing it in textblock and making it translate according to it's
818 * style is correct. */
820 _strncpy(char* dest, const char* src, size_t count)
824 ERR( "dest is NULL" );
829 ERR( "src is NULL" );
834 ERR( "count is smaller than 0" );
838 return strncpy( dest, src, count );
842 _mkup_to_text(const char *mkup)
845 int str_len = 0, str_alloc = 0;
847 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
849 if (!mkup) return NULL;
851 tag_start = tag_end = esc_start = esc_end = NULL;
856 if (((p!=NULL)&&(*p == 0)) ||
857 (tag_end) || (esc_end) ||
858 (tag_start) || (esc_start))
864 ttag = malloc(tag_end - tag_start);
867 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
868 ttag[tag_end - tag_start - 1] = 0;
869 if (!strcmp(ttag, "br"))
870 str = _str_append(str, "\n", &str_len, &str_alloc);
871 else if (!strcmp(ttag, "\n"))
872 str = _str_append(str, "\n", &str_len, &str_alloc);
873 else if (!strcmp(ttag, "\\n"))
874 str = _str_append(str, "\n", &str_len, &str_alloc);
875 else if (!strcmp(ttag, "\t"))
876 str = _str_append(str, "\t", &str_len, &str_alloc);
877 else if (!strcmp(ttag, "\\t"))
878 str = _str_append(str, "\t", &str_len, &str_alloc);
879 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
880 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
883 tag_start = tag_end = NULL;
887 ts = malloc(esc_end - esc_start + 1);
891 _strncpy(ts, esc_start, esc_end - esc_start);
892 ts[esc_end - esc_start] = 0;
893 esc = evas_textblock_escape_string_get(ts);
895 str = _str_append(str, esc, &str_len, &str_alloc);
898 esc_start = esc_end = NULL;
900 else if ((p!=NULL)&&(*p == 0))
902 ts = malloc(p - s + 1);
905 _strncpy(ts, s, p - s);
907 str = _str_append(str, ts, &str_len, &str_alloc);
913 if ((p!=NULL)&&(*p == '<'))
919 ts = malloc(p - s + 1);
922 _strncpy(ts, s, p - s);
924 str = _str_append(str, ts, &str_len, &str_alloc);
930 else if ((p!=NULL)&&(*p == '>'))
938 else if ((p!=NULL)&&(*p == '&'))
944 ts = malloc(p - s + 1);
947 _strncpy(ts, s, p - s);
949 str = _str_append(str, ts, &str_len, &str_alloc);
955 else if ((p!=NULL)&&(*p == ';'))
969 _entry_length_get(Evas_Object *obj)
972 const char *str = elm_entry_entry_get(obj);
975 char *plain_str = _mkup_to_text(str);
976 if (!plain_str) return 0;
978 len = strlen(plain_str);
985 _text_to_mkup(const char *text)
988 int str_len = 0, str_alloc = 0;
989 int ch, pos = 0, pos2 = 0;
991 if (!text) return NULL;
995 pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
996 if ((ch <= 0) || (pos2 <= 0)) break;
998 str = _str_append(str, "<br>", &str_len, &str_alloc);
1000 str = _str_append(str, "<\t>", &str_len, &str_alloc);
1002 str = _str_append(str, "<", &str_len, &str_alloc);
1004 str = _str_append(str, ">", &str_len, &str_alloc);
1006 str = _str_append(str, "&", &str_len, &str_alloc);
1011 _strncpy(tstr, text + pos, pos2 - pos);
1012 tstr[pos2 - pos] = 0;
1013 str = _str_append(str, tstr, &str_len, &str_alloc);
1020 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1022 Widget_Data *wd = elm_widget_data_get(data);
1024 wd->changed = EINA_TRUE;
1026 if (wd->text) eina_stringshare_del(wd->text);
1028 _check_enable_returnkey(data);
1029 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1033 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1035 Widget_Data *wd = elm_widget_data_get(data);
1039 EINA_LIST_FOREACH(entries, l, entry)
1041 if (entry != data) elm_entry_select_none(entry);
1043 wd->have_selection = EINA_TRUE;
1044 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1045 #ifdef HAVE_ELEMENTARY_X
1046 if (wd->sel_notify_handler)
1048 const char *txt = elm_entry_selection_get(data);
1051 top = elm_widget_top_get(data);
1052 if ((top) && (elm_win_xwindow_get(top)))
1053 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP, txt);
1059 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1061 Widget_Data *wd = elm_widget_data_get(data);
1063 wd->have_selection = EINA_TRUE;
1064 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1065 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_MARKUP,
1066 elm_entry_selection_get(data));
1070 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1072 Widget_Data *wd = elm_widget_data_get(data);
1074 if (!wd->have_selection) return;
1075 wd->have_selection = EINA_FALSE;
1076 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1077 if (wd->sel_notify_handler)
1081 #ifdef HAVE_ELEMENTARY_X
1084 top = elm_widget_top_get(data);
1085 if ((top) && (elm_win_xwindow_get(top)))
1086 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP,
1089 eina_stringshare_del(wd->cut_sel);
1094 #ifdef HAVE_ELEMENTARY_X
1097 top = elm_widget_top_get(data);
1098 if ((top) && (elm_win_xwindow_get(top)))
1099 elm_selection_clear(ELM_SEL_PRIMARY, data);
1106 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1108 Widget_Data *wd = elm_widget_data_get(data);
1110 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1111 if (wd->sel_notify_handler)
1113 #ifdef HAVE_ELEMENTARY_X
1116 top = elm_widget_top_get(data);
1117 if ((top) && (elm_win_xwindow_get(top)))
1119 wd->selection_asked = EINA_TRUE;
1120 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_MARKUP, data);
1127 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1129 Widget_Data *wd = elm_widget_data_get(data);
1131 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1132 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1133 elm_entry_selection_get(data));
1137 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1139 Widget_Data *wd = elm_widget_data_get(data);
1141 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1142 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1143 elm_entry_selection_get(data));
1144 edje_object_part_text_insert(wd->ent, "elm.text", "");
1145 wd->changed = EINA_TRUE;
1150 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1152 Widget_Data *wd = elm_widget_data_get(data);
1153 Evas_Coord cx, cy, cw, ch;
1155 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1156 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1157 &cx, &cy, &cw, &ch);
1158 if (!wd->deferred_recalc_job)
1159 elm_widget_show_region_set(data, cx, cy, cw, ch);
1162 wd->deferred_cur = EINA_TRUE;
1171 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1173 Widget_Data *wd = elm_widget_data_get(data);
1178 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1180 Widget_Data *wd = elm_widget_data_get(data);
1181 Elm_Entry_Anchor_Info ei;
1182 char *buf2, *p, *p2, *n;
1184 p = strrchr(emission, ',');
1187 const Eina_List *geoms;
1191 while (p2 >= emission)
1193 if (*p2 == ',') break;
1197 buf2 = alloca(5 + p - p2);
1198 strncpy(buf2, p2, p - p2);
1201 ei.button = atoi(buf2);
1202 ei.x = ei.y = ei.w = ei.h = 0;
1204 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1207 Evas_Textblock_Rectangle *r;
1209 Evas_Coord px, py, x, y;
1211 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1212 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1213 EINA_LIST_FOREACH(geoms, l, r)
1215 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1216 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1227 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1232 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1234 Widget_Data *wd = elm_widget_data_get(data);
1239 _signal_anchor_in(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_out(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_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1255 Widget_Data *wd = elm_widget_data_get(data);
1257 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1261 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1263 Widget_Data *wd = elm_widget_data_get(data);
1265 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1269 _signal_mouse_up(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_CLICKED, NULL);
1277 _signal_mouse_double(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_CLICKED_DOUBLE, NULL);
1284 #ifdef HAVE_ELEMENTARY_X
1286 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1288 Widget_Data *wd = elm_widget_data_get(data);
1289 Ecore_X_Event_Selection_Notify *ev = event;
1290 if (!wd) return ECORE_CALLBACK_PASS_ON;
1291 if (!wd->selection_asked) return ECORE_CALLBACK_PASS_ON;
1293 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1294 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1296 Ecore_X_Selection_Data_Text *text_data;
1298 text_data = ev->data;
1299 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1301 if (text_data->text)
1303 char *txt = _text_to_mkup(text_data->text);
1307 elm_entry_entry_insert(data, txt);
1312 wd->selection_asked = EINA_FALSE;
1314 return ECORE_CALLBACK_PASS_ON;
1318 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1321 Widget_Data *wd = elm_widget_data_get(data);
1322 Ecore_X_Event_Selection_Clear *ev = event;
1324 if (!wd->have_selection) return 1;
1325 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1326 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1328 elm_entry_select_none(data);
1331 return ECORE_CALLBACK_PASS_ON;
1335 static Evas_Object *
1336 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1338 Widget_Data *wd = elm_widget_data_get(data);
1341 Elm_Entry_Item_Provider *ip;
1344 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1346 o = ip->func(ip->data, data, item);
1349 o = edje_object_add(evas_object_evas_get(data));
1350 if (!strncmp(item, "emoticon/", 9))
1351 ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1353 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1358 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1360 char *curlocater, *starttag, *endtag;
1361 int firstindex = 0, foundflag = -1;
1363 curlocater = strstr(oldstring, key);
1366 starttag = curlocater;
1367 endtag = curlocater + strlen(key);
1368 if (endtag == NULL || *endtag != '=')
1374 firstindex = abs(oldstring - curlocater);
1375 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1376 *value = (char*)oldstring + firstindex;
1378 while (oldstring != starttag)
1380 if (*starttag == '>')
1385 if (*starttag == '<')
1389 if (starttag == NULL) break;
1392 while (NULL != endtag)
1403 if (endtag == NULL) break;
1406 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1416 if (foundflag == 1) return 0;
1422 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1424 const char *srcstring = NULL;
1425 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1426 char *curlocater, *replocater;
1427 char *starttag, *endtag;
1428 int tagtxtlen = 0, insertflag = 0;
1430 srcstring = eina_strbuf_string_get(srcbuf);
1431 curlocater = strstr(srcstring, key);
1433 if (curlocater == NULL)
1441 starttag = strchr(srcstring, '<');
1442 endtag = strchr(srcstring, '>');
1443 tagtxtlen = endtag - starttag;
1444 if (tagtxtlen <= 0) tagtxtlen = 0;
1445 if (starttag < curlocater && curlocater < endtag) break;
1446 if (endtag != NULL && endtag+1 != NULL)
1447 srcstring = endtag+1;
1450 } while (strlen(srcstring) > 1);
1452 if (starttag && endtag && tagtxtlen > strlen(key))
1454 repbuf = eina_strbuf_new();
1455 diffbuf = eina_strbuf_new();
1456 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1457 srcstring = eina_strbuf_string_get(repbuf);
1458 curlocater = strstr(srcstring, key);
1460 if (curlocater != NULL)
1462 replocater = curlocater + strlen(key) + 1;
1464 while (*replocater == ' ' || *replocater == '=')
1469 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1472 if (replocater-curlocater > strlen(key)+1)
1475 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1484 eina_strbuf_reset(repbuf);
1492 if (repbuf == NULL) repbuf = eina_strbuf_new();
1493 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1497 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1498 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1504 eina_strbuf_prepend(diffbuf, "<");
1505 eina_strbuf_append(diffbuf, ">");
1506 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1510 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1511 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1515 if (repbuf) eina_strbuf_free(repbuf);
1516 if (diffbuf) eina_strbuf_free(diffbuf);
1522 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1524 Eina_Strbuf *sharebuf = NULL;
1526 sharebuf = eina_strbuf_new();
1527 eina_strbuf_append(sharebuf, *srcstring);
1528 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1529 eina_stringshare_del(*srcstring);
1530 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1531 eina_strbuf_free(sharebuf);
1537 _is_width_over(Evas_Object *obj)
1539 Evas_Coord x, y, w, h;
1540 Evas_Coord vx, vy, vw, vh;
1541 Widget_Data *wd = elm_widget_data_get(obj);
1545 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1547 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1549 if (x >= 0 && y >= 0)
1552 if (4 < wd->wrap_w && w > wd->wrap_w)
1559 _reverse_ellipsis_entry(Evas_Object *obj)
1561 Widget_Data *wd = elm_widget_data_get(obj);
1562 int cur_fontsize = 0;
1563 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1564 char **kvalue = NULL;
1565 const char *minfont, *deffont, *maxfont;
1566 const char *ellipsis_string = "...";
1567 int minfontsize, maxfontsize, minshowcount;
1569 minshowcount = strlen(ellipsis_string) + 1;
1570 minfont = edje_object_data_get(wd->ent, "min_font_size");
1571 if (minfont) minfontsize = atoi(minfont);
1572 else minfontsize = 1;
1573 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1574 if (maxfont) maxfontsize = atoi(maxfont);
1575 else maxfontsize = 1;
1576 deffont = edje_object_data_get(wd->ent, "default_font_size");
1577 if (deffont) cur_fontsize = atoi(deffont);
1578 else cur_fontsize = 1;
1579 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1580 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1582 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1584 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1587 txtbuf = eina_strbuf_new();
1588 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1590 if (cur_fontsize >= atoi(deffont))
1592 if (txtbuf) eina_strbuf_free(txtbuf);
1596 if (_is_width_over(obj) != 1)
1598 int rev_fontsize = cur_fontsize;
1602 if (rev_fontsize > atoi(deffont))
1605 if (fontbuf != NULL)
1607 eina_strbuf_free(fontbuf);
1610 fontbuf = eina_strbuf_new();
1611 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1612 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1613 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1615 eina_strbuf_free(fontbuf);
1617 } while (_is_width_over(obj) != 1);
1619 while (_is_width_over(obj))
1622 if (rev_fontsize < atoi(deffont))
1625 if (fontbuf != NULL)
1627 eina_strbuf_free(fontbuf);
1630 fontbuf = eina_strbuf_new();
1631 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1632 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1633 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1634 eina_strbuf_free(fontbuf);
1639 if (txtbuf) eina_strbuf_free(txtbuf);
1645 _ellipsis_entry_to_width(Evas_Object *obj)
1647 Widget_Data *wd = elm_widget_data_get(obj);
1648 int cur_fontsize = 0, len, jumpcount;
1649 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1650 char **kvalue = NULL;
1651 const char *minfont, *deffont, *maxfont;
1652 const char *ellipsis_string = "...";
1653 int minfontsize, maxfontsize, minshowcount;
1654 int i, tagend, cur_len;
1657 minshowcount = strlen(ellipsis_string) + 1;
1658 minfont = edje_object_data_get(wd->ent, "min_font_size");
1659 if (minfont) minfontsize = atoi(minfont);
1660 else minfontsize = 1;
1661 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1662 if (maxfont) maxfontsize = atoi(maxfont);
1663 else maxfontsize = 1;
1664 deffont = edje_object_data_get(wd->ent, "default_font_size");
1665 if (deffont) cur_fontsize = atoi(deffont);
1666 else cur_fontsize = 1;
1667 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1668 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1670 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1672 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1675 txtbuf = eina_strbuf_new();
1676 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1678 while (_is_width_over(obj))
1680 if (wd->ellipsis_threshold == 0)
1681 wd->ellipsis_threshold = _entry_length_get(obj);
1682 if (cur_fontsize > minfontsize)
1685 if (fontbuf != NULL)
1687 eina_strbuf_free(fontbuf);
1690 fontbuf = eina_strbuf_new();
1691 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1692 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1693 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1694 eina_strbuf_free(fontbuf);
1696 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1700 len = _entry_length_get(obj);
1701 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1702 cur_len = strlen(cur_str);
1704 for (i = 0; i < len; i++)
1706 if(cur_str[i] == '>' && cur_str[i+1] != NULL &&
1707 cur_str[i+1] != '<')
1714 while (jumpcount < len-strlen(ellipsis_string))
1716 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1720 eina_strbuf_free(txtbuf);
1723 txtbuf = eina_strbuf_new();
1724 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1725 eina_strbuf_append(txtbuf, ellipsis_string);
1726 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1727 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1728 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1730 if (_is_width_over(obj))
1738 if (txtbuf) eina_strbuf_free(txtbuf);
1743 static int _textinput_control_function(void *data,void *input_data)
1745 /*calculate character count*/
1746 Evas_Object *entry = (Evas_Object *)data;
1747 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1750 size_t insert_text_len=0;
1751 char *text = edje_object_part_text_get(wd->ent, "elm.text");
1753 size_t remain_bytes;
1756 byte_len = strlen(text);/*no of bytes*/
1757 remain_bytes = wd->max_no_of_bytes-byte_len;
1758 sprintf(buf,"%d",remain_bytes);
1759 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1762 insert_text = (char *)input_data;
1763 insert_text_len = strlen(insert_text);
1764 if(remain_bytes<insert_text_len)
1766 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1769 if(byte_len>=wd->max_no_of_bytes)
1771 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1780 * This adds an entry to @p parent object.
1782 * @param parent The parent object
1783 * @return The new object or NULL if it cannot be created
1788 elm_entry_add(Evas_Object *parent)
1790 Evas_Object *obj, *top;
1794 wd = ELM_NEW(Widget_Data);
1795 e = evas_object_evas_get(parent);
1796 wd->bgcolor = EINA_FALSE;
1797 wd->bg = evas_object_rectangle_add(e);
1798 evas_object_color_set(wd->bg, 0, 0, 0, 0);
1799 obj = elm_widget_add(e);
1800 ELM_SET_WIDTYPE(widtype, "entry");
1801 elm_widget_type_set(obj, "entry");
1802 elm_widget_sub_object_add(parent, obj);
1803 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1804 elm_widget_data_set(obj, wd);
1805 elm_widget_del_hook_set(obj, _del_hook);
1806 elm_widget_theme_hook_set(obj, _theme_hook);
1807 elm_widget_disable_hook_set(obj, _disable_hook);
1808 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1809 elm_widget_can_focus_set(obj, 1);
1811 wd->linewrap = EINA_TRUE;
1812 wd->ellipsis = EINA_FALSE;
1813 wd->char_linewrap= EINA_FALSE;
1814 wd->editable = EINA_TRUE;
1815 wd->disabled = EINA_FALSE;
1816 wd->context_menu = EINA_TRUE;
1818 wd->ellipsis_threshold = 0;
1820 wd->ent = edje_object_add(e);
1821 edje_object_item_provider_set(wd->ent, _get_item, obj);
1822 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1823 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1824 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1826 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1828 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1831 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1832 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1833 _signal_entry_changed, obj);
1834 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1835 _signal_selection_start, obj);
1836 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1837 _signal_selection_changed, obj);
1838 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1839 _signal_selection_cleared, obj);
1840 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1841 _signal_entry_paste_request, obj);
1842 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1843 _signal_entry_copy_notify, obj);
1844 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1845 _signal_entry_cut_notify, obj);
1846 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1847 _signal_cursor_changed, obj);
1848 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1849 _signal_anchor_down, obj);
1850 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1851 _signal_anchor_up, obj);
1852 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1853 _signal_anchor_move, obj);
1854 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1855 _signal_anchor_in, obj);
1856 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1857 _signal_anchor_out, obj);
1858 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1859 _signal_key_enter, obj);
1860 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1861 _signal_mouse_down, obj);
1862 edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
1863 _signal_mouse_up, obj);
1864 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1865 _signal_mouse_double, obj);
1866 edje_object_part_text_set(wd->ent, "elm.text", "");
1867 elm_widget_resize_object_set(obj, wd->ent);
1870 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
1872 #ifdef HAVE_ELEMENTARY_X
1873 top = elm_widget_top_get(obj);
1874 if ((top) && (elm_win_xwindow_get(top)))
1876 wd->sel_notify_handler =
1877 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1878 _event_selection_notify, obj);
1879 wd->sel_clear_handler =
1880 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1881 _event_selection_clear, obj);
1885 entries = eina_list_prepend(entries, obj);
1887 // module - find module for entry
1888 wd->api = _module(obj);
1889 // if found - hook in
1890 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1892 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1893 // TODO: and save some bytes, making descriptions per-class and not instance!
1894 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1898 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
1900 ELM_CHECK_WIDTYPE(obj, widtype);
1901 Widget_Data *wd = elm_widget_data_get(obj);
1903 ext_mod->cancel = _cancel;
1904 ext_mod->copy = _copy;
1905 ext_mod->cut = _cut;
1906 ext_mod->paste = _paste;
1907 ext_mod->select = _select;
1908 ext_mod->selectall = NULL; /* to be implemented*/
1909 ext_mod->ent = wd->ent;
1910 ext_mod->items = wd->items;
1911 ext_mod->longpress_timer = wd->longpress_timer;
1912 ext_mod->editable = wd->editable;
1913 ext_mod->have_selection = wd->have_selection;
1914 ext_mod->password = wd->password;
1915 ext_mod->selmode = wd->selmode;
1919 * This sets the entry object not to line wrap. All input will
1920 * be on a single line, and the entry box will extend with user input.
1922 * @param obj The entry object
1923 * @param single_line If true, the text in the entry
1924 * will be on a single line.
1929 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1931 ELM_CHECK_WIDTYPE(obj, widtype);
1932 Widget_Data *wd = elm_widget_data_get(obj);
1934 Ecore_IMF_Context *ic;
1936 if (wd->single_line == single_line) return;
1937 wd->single_line = single_line;
1938 wd->linewrap = EINA_FALSE;
1939 wd->char_linewrap = EINA_FALSE;
1940 t = eina_stringshare_add(elm_entry_entry_get(obj));
1941 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1942 elm_entry_entry_set(obj, t);
1943 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
1944 // edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
1945 ic = elm_entry_imf_context_get(obj);
1948 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
1951 eina_stringshare_del(t);
1956 * This returns true if the entry has been set to single line mode.
1957 * See also elm_entry_single_line_set().
1959 * @param obj The entry object
1960 * @return single_line If true, the text in the entry is set to display
1966 elm_entry_single_line_get(const Evas_Object *obj)
1968 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1969 Widget_Data *wd = elm_widget_data_get(obj);
1970 if (!wd) return EINA_FALSE;
1971 return wd->single_line;
1975 * This set's the maximum bytes that can be added in entry.
1977 * @param obj The entry object
1978 * @param max_no_of_bytes Maximum number of bytes entry can have.
1983 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
1985 Widget_Data *wd = elm_widget_data_get(obj);
1987 wd->max_no_of_bytes = max_no_of_bytes;
1988 edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
1989 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
1994 * This sets the entry object to password mode. All text entered
1995 * and/or displayed within the widget will be replaced with asterisks (*).
1997 * @param obj The entry object
1998 * @param password If true, password mode is enabled.
2003 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2005 ELM_CHECK_WIDTYPE(obj, widtype);
2006 Widget_Data *wd = elm_widget_data_get(obj);
2007 Ecore_IMF_Context *ic;
2010 if (wd->password == password) return;
2011 wd->password = password;
2012 wd->show_last_character = EINA_FALSE;
2013 wd->single_line = EINA_TRUE;
2014 wd->linewrap = EINA_FALSE;
2015 wd->char_linewrap = EINA_FALSE;
2016 t = eina_stringshare_add(elm_entry_entry_get(obj));
2017 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2018 elm_entry_entry_set(obj, t);
2020 ic = elm_entry_imf_context_get(obj);
2023 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2026 eina_stringshare_del(t);
2031 * This set's the entry in password mode with out masking the last character entered by user,
2032 * and later masking the character after 2 seconds.
2034 * @param obj The entry object
2035 * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character"
2041 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2043 Widget_Data *wd = elm_widget_data_get(obj);
2046 if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character)) return;
2047 wd->show_last_character = show_last_character;
2048 wd->password = show_last_character;
2049 wd->single_line = EINA_TRUE;
2050 wd->linewrap = EINA_FALSE;
2051 wd->char_linewrap = EINA_FALSE;
2052 t = eina_stringshare_add(elm_entry_entry_get(obj));
2053 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2054 elm_entry_entry_set(obj, t);
2055 eina_stringshare_del(t);
2060 * This returns whether password mode is enabled.
2061 * See also elm_entry_password_set().
2063 * @param obj The entry object
2064 * @return If true, the entry is set to display all characters
2070 elm_entry_password_get(const Evas_Object *obj)
2072 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2073 Widget_Data *wd = elm_widget_data_get(obj);
2074 if (!wd) return EINA_FALSE;
2075 return wd->password;
2079 * This sets the text displayed within the entry to @p entry.
2081 * @param obj The entry object
2082 * @param entry The text to be displayed
2087 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2089 ELM_CHECK_WIDTYPE(obj, widtype);
2090 Widget_Data *wd = elm_widget_data_get(obj);
2092 if (!entry) entry = "";
2093 if(wd->max_no_of_bytes)
2095 int len = strlen(entry);
2096 if(len > wd->max_no_of_bytes)
2098 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2102 edje_object_part_text_set(wd->ent, "elm.text", entry);
2103 if (wd->text) eina_stringshare_del(wd->text);
2105 wd->changed = EINA_TRUE;
2110 * This returns the text currently shown in object @p entry.
2111 * See also elm_entry_entry_set().
2113 * @param obj The entry object
2114 * @return The currently displayed text or NULL on failure
2119 elm_entry_entry_get(const Evas_Object *obj)
2121 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2122 Widget_Data *wd = elm_widget_data_get(obj);
2124 if (!wd) return NULL;
2125 if (wd->text) return wd->text;
2126 text = edje_object_part_text_get(wd->ent, "elm.text");
2129 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2132 eina_stringshare_replace(&wd->text, text);
2137 * This returns all selected text within the entry.
2139 * @param obj The entry object
2140 * @return The selected text within the entry or NULL on failure
2145 elm_entry_selection_get(const Evas_Object *obj)
2147 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2148 Widget_Data *wd = elm_widget_data_get(obj);
2149 if (!wd) return NULL;
2150 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2154 * This inserts text in @p entry at the beginning of the entry
2157 * @param obj The entry object
2158 * @param entry The text to insert
2163 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2165 ELM_CHECK_WIDTYPE(obj, widtype);
2166 Widget_Data *wd = elm_widget_data_get(obj);
2168 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2169 wd->changed = EINA_TRUE;
2174 * This enables word line wrapping in the entry object. It is the opposite
2175 * of elm_entry_single_line_set(). Additionally, setting this disables
2176 * character line wrapping.
2177 * See also elm_entry_line_char_wrap_set().
2179 * @param obj The entry object
2180 * @param wrap If true, the entry will be wrapped once it reaches the end
2181 * of the object. Wrapping will occur at the end of the word before the end of the
2187 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2189 ELM_CHECK_WIDTYPE(obj, widtype);
2190 Widget_Data *wd = elm_widget_data_get(obj);
2193 if (wd->linewrap == wrap) return;
2194 wd->linewrap = wrap;
2196 wd->char_linewrap = EINA_FALSE;
2197 t = eina_stringshare_add(elm_entry_entry_get(obj));
2198 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2199 elm_entry_entry_set(obj, t);
2200 eina_stringshare_del(t);
2205 * Set wrap width of the entry
2207 * @param obj The entry object
2208 * @param w The wrap width in pixels at a minimum where words need to wrap
2212 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2214 Widget_Data *wd = elm_widget_data_get(obj);
2215 if (wd->wrap_w == w) return;
2221 * get wrap width of the entry
2223 * @param obj The entry object
2224 * @return The wrap width in pixels at a minimum where words need to wrap
2228 elm_entry_wrap_width_get(const Evas_Object *obj)
2230 Widget_Data *wd = elm_widget_data_get(obj);
2235 * This enables character line wrapping in the entry object. It is the opposite
2236 * of elm_entry_single_line_set(). Additionally, setting this disables
2237 * word line wrapping.
2238 * See also elm_entry_line_wrap_set().
2240 * @param obj The entry object
2241 * @param wrap If true, the entry will be wrapped once it reaches the end
2242 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2247 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2249 ELM_CHECK_WIDTYPE(obj, widtype);
2250 Widget_Data *wd = elm_widget_data_get(obj);
2253 if (wd->char_linewrap == wrap) return;
2254 wd->char_linewrap = wrap;
2255 if(wd->char_linewrap)
2256 wd->linewrap = EINA_FALSE;
2257 t = eina_stringshare_add(elm_entry_entry_get(obj));
2258 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2259 elm_entry_entry_set(obj, t);
2260 eina_stringshare_del(t);
2265 * This sets the editable attribute of the entry.
2267 * @param obj The entry object
2268 * @param editable If true, the entry will be editable by the user.
2269 * If false, it will be set to the disabled state.
2274 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2276 ELM_CHECK_WIDTYPE(obj, widtype);
2277 Widget_Data *wd = elm_widget_data_get(obj);
2280 if (wd->editable == editable) return;
2281 wd->editable = editable;
2282 t = eina_stringshare_add(elm_entry_entry_get(obj));
2283 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2284 elm_entry_entry_set(obj, t);
2285 eina_stringshare_del(t);
2290 * This gets the editable attribute of the entry.
2291 * See also elm_entry_editable_set().
2293 * @param obj The entry object
2294 * @return If true, the entry is editable by the user.
2295 * If false, it is not editable by the user
2300 elm_entry_editable_get(const Evas_Object *obj)
2302 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2303 Widget_Data *wd = elm_widget_data_get(obj);
2304 if (!wd) return EINA_FALSE;
2305 return wd->editable;
2309 * This drops any existing text selection within the entry.
2311 * @param obj The entry object
2316 elm_entry_select_none(Evas_Object *obj)
2318 ELM_CHECK_WIDTYPE(obj, widtype);
2319 Widget_Data *wd = elm_widget_data_get(obj);
2323 wd->selmode = EINA_FALSE;
2324 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2325 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2327 wd->have_selection = EINA_FALSE;
2328 edje_object_part_text_select_none(wd->ent, "elm.text");
2332 * This selects all text within the entry.
2334 * @param obj The entry object
2339 elm_entry_select_all(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_TRUE;
2351 edje_object_part_text_select_all(wd->ent, "elm.text");
2355 * This moves the cursor one place to the right within the entry.
2357 * @param obj The entry object
2358 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2363 elm_entry_cursor_next(Evas_Object *obj)
2365 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2366 Widget_Data *wd = elm_widget_data_get(obj);
2367 if (!wd) return EINA_FALSE;
2368 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2372 * This moves the cursor one place to the left within the entry.
2374 * @param obj The entry object
2375 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2380 elm_entry_cursor_prev(Evas_Object *obj)
2382 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2383 Widget_Data *wd = elm_widget_data_get(obj);
2384 if (!wd) return EINA_FALSE;
2385 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2389 * This moves the cursor one line up within the entry.
2391 * @param obj The entry object
2392 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2397 elm_entry_cursor_up(Evas_Object *obj)
2399 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2400 Widget_Data *wd = elm_widget_data_get(obj);
2401 if (!wd) return EINA_FALSE;
2402 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2406 * This moves the cursor one line down within the entry.
2408 * @param obj The entry object
2409 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2414 elm_entry_cursor_down(Evas_Object *obj)
2416 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2417 Widget_Data *wd = elm_widget_data_get(obj);
2418 if (!wd) return EINA_FALSE;
2419 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2423 * This moves the cursor to the beginning of the entry.
2425 * @param obj The entry object
2430 elm_entry_cursor_begin_set(Evas_Object *obj)
2432 ELM_CHECK_WIDTYPE(obj, widtype);
2433 Widget_Data *wd = elm_widget_data_get(obj);
2435 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2439 * This moves the cursor to the end of the entry.
2441 * @param obj The entry object
2446 elm_entry_cursor_end_set(Evas_Object *obj)
2448 ELM_CHECK_WIDTYPE(obj, widtype);
2449 Widget_Data *wd = elm_widget_data_get(obj);
2451 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2455 * This moves the cursor to the beginning of the current line.
2457 * @param obj The entry object
2462 elm_entry_cursor_line_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_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2471 * This moves the cursor to the end of the current line.
2473 * @param obj The entry object
2478 elm_entry_cursor_line_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_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2487 * This begins a selection within the entry as though
2488 * the user were holding down the mouse button to make a selection.
2490 * @param obj The entry object
2495 elm_entry_cursor_selection_begin(Evas_Object *obj)
2497 ELM_CHECK_WIDTYPE(obj, widtype);
2498 Widget_Data *wd = elm_widget_data_get(obj);
2500 edje_object_part_text_select_begin(wd->ent, "elm.text");
2504 * This ends a selection within the entry as though
2505 * the user had just released the mouse button while making a selection.
2507 * @param obj The entry object
2512 elm_entry_cursor_selection_end(Evas_Object *obj)
2514 ELM_CHECK_WIDTYPE(obj, widtype);
2515 Widget_Data *wd = elm_widget_data_get(obj);
2517 edje_object_part_text_select_extend(wd->ent, "elm.text");
2521 * TODO: fill this in
2523 * @param obj The entry object
2524 * @return TODO: fill this in
2529 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2531 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2532 Widget_Data *wd = elm_widget_data_get(obj);
2533 if (!wd) return EINA_FALSE;
2534 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2538 * This returns whether the cursor is visible.
2540 * @param obj The entry object
2541 * @return If true, the cursor is visible.
2546 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2548 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2549 Widget_Data *wd = elm_widget_data_get(obj);
2550 if (!wd) return EINA_FALSE;
2551 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2555 * TODO: fill this in
2557 * @param obj The entry object
2558 * @return TODO: fill this in
2563 elm_entry_cursor_content_get(const Evas_Object *obj)
2565 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2566 Widget_Data *wd = elm_widget_data_get(obj);
2567 if (!wd) return NULL;
2568 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2572 * This executes a "cut" action on the selected text in the entry.
2574 * @param obj The entry object
2579 elm_entry_selection_cut(Evas_Object *obj)
2581 ELM_CHECK_WIDTYPE(obj, widtype);
2582 Widget_Data *wd = elm_widget_data_get(obj);
2584 _cut(obj, NULL, NULL);
2588 * This executes a "copy" action on the selected text in the entry.
2590 * @param obj The entry object
2595 elm_entry_selection_copy(Evas_Object *obj)
2597 ELM_CHECK_WIDTYPE(obj, widtype);
2598 Widget_Data *wd = elm_widget_data_get(obj);
2600 _copy(obj, NULL, NULL);
2604 * This executes a "paste" action in the entry.
2606 * @param obj The entry object
2611 elm_entry_selection_paste(Evas_Object *obj)
2613 ELM_CHECK_WIDTYPE(obj, widtype);
2614 Widget_Data *wd = elm_widget_data_get(obj);
2616 _paste(obj, NULL, NULL);
2620 * This clears and frees the items in a entry's contextual (right click) menu.
2622 * @param obj The entry object
2627 elm_entry_context_menu_clear(Evas_Object *obj)
2629 ELM_CHECK_WIDTYPE(obj, widtype);
2630 Widget_Data *wd = elm_widget_data_get(obj);
2631 Elm_Entry_Context_Menu_Item *it;
2633 EINA_LIST_FREE(wd->items, it)
2635 eina_stringshare_del(it->label);
2636 eina_stringshare_del(it->icon_file);
2637 eina_stringshare_del(it->icon_group);
2643 * This adds an item to the entry's contextual menu.
2645 * @param obj The entry object
2646 * @param label The item's text label
2647 * @param icon_file The item's icon file
2648 * @param icon_type The item's icon type
2649 * @param func The callback to execute when the item is clicked
2650 * @param data The data to associate with the item for related functions
2655 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)
2657 ELM_CHECK_WIDTYPE(obj, widtype);
2658 Widget_Data *wd = elm_widget_data_get(obj);
2659 Elm_Entry_Context_Menu_Item *it;
2661 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2663 wd->items = eina_list_append(wd->items, it);
2665 it->label = eina_stringshare_add(label);
2666 it->icon_file = eina_stringshare_add(icon_file);
2667 it->icon_type = icon_type;
2669 it->data = (void *)data;
2673 * This disables the entry's contextual (right click) menu.
2675 * @param obj The entry object
2676 * @param disabled If true, the menu is disabled
2681 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2683 ELM_CHECK_WIDTYPE(obj, widtype);
2684 Widget_Data *wd = elm_widget_data_get(obj);
2686 if (wd->context_menu == !disabled) return;
2687 wd->context_menu = !disabled;
2691 * This returns whether the entry's contextual (right click) menu is disabled.
2693 * @param obj The entry object
2694 * @return If true, the menu is disabled
2699 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2701 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2702 Widget_Data *wd = elm_widget_data_get(obj);
2703 if (!wd) return EINA_FALSE;
2704 return !wd->context_menu;
2708 * This appends a custom item provider to the list for that entry
2710 * This appends the given callback. The list is walked from beginning to end
2711 * with each function called given the item href string in the text. If the
2712 * function returns an object handle other than NULL (it should create an
2713 * and object to do this), then this object is used to replace that item. If
2714 * not the next provider is called until one provides an item object, or the
2715 * default provider in entry does.
2717 * @param obj The entry object
2718 * @param func The function called to provide the item object
2719 * @param data The data passed to @p func
2724 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2726 ELM_CHECK_WIDTYPE(obj, widtype);
2727 Widget_Data *wd = elm_widget_data_get(obj);
2730 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2734 wd->item_providers = eina_list_append(wd->item_providers, ip);
2738 * This prepends a custom item provider to the list for that entry
2740 * This prepends the given callback. See elm_entry_item_provider_append() for
2743 * @param obj The entry object
2744 * @param func The function called to provide the item object
2745 * @param data The data passed to @p func
2750 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2752 ELM_CHECK_WIDTYPE(obj, widtype);
2753 Widget_Data *wd = elm_widget_data_get(obj);
2756 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2760 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2764 * This removes a custom item provider to the list for that entry
2766 * This removes the given callback. See elm_entry_item_provider_append() for
2769 * @param obj The entry object
2770 * @param func The function called to provide the item object
2771 * @param data The data passed to @p func
2776 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2778 ELM_CHECK_WIDTYPE(obj, widtype);
2779 Widget_Data *wd = elm_widget_data_get(obj);
2781 Elm_Entry_Item_Provider *ip;
2784 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2786 if ((ip->func == func) && (ip->data == data))
2788 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2796 * This converts a markup (HTML-like) string into UTF-8.
2798 * @param s The string (in markup) to be converted
2799 * @return The converted string (in UTF-8)
2804 elm_entry_markup_to_utf8(const char *s)
2806 char *ss = _mkup_to_text(s);
2807 if (!ss) ss = strdup("");
2812 * This converts a UTF-8 string into markup (HTML-like).
2814 * @param s The string (in UTF-8) to be converted
2815 * @return The converted string (in markup)
2820 elm_entry_utf8_to_markup(const char *s)
2822 char *ss = _text_to_mkup(s);
2823 if (!ss) ss = strdup("");
2828 * Get the input method context in the entry widget
2830 * @param obj The entry object
2831 * @return The input method context
2835 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2837 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2838 Widget_Data *wd = elm_widget_data_get(obj);
2839 if (!wd || !wd->ent) return NULL;
2841 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2845 * Set whether entry should enable the return key on soft keyboard automatically
2847 * @param obj The entry object
2848 * @param on If true, entry enables the return key on soft keyboard automatically.
2853 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
2855 ELM_CHECK_WIDTYPE(obj, widtype);
2856 Widget_Data *wd = elm_widget_data_get(obj);
2859 wd->autoreturnkey = on;
2860 _check_enable_returnkey(obj);
2864 * Set whether entry should support auto capitalization
2866 * @param obj The entry object
2867 * @param on If true, entry suports auto capitalization.
2872 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
2874 ELM_CHECK_WIDTYPE(obj, widtype);
2875 Widget_Data *wd = elm_widget_data_get(obj);
2879 wd->autocapitalize = EINA_FALSE;
2881 wd->autocapitalize = autocap;
2883 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2887 * Set whether entry should support auto period
2889 * @param obj The entry object
2890 * @param on If true, entry suports auto period.
2895 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
2897 ELM_CHECK_WIDTYPE(obj, widtype);
2898 Widget_Data *wd = elm_widget_data_get(obj);
2902 wd->autoperiod = EINA_FALSE;
2904 wd->autoperiod = autoperiod;
2906 // edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2910 * Set the font size on the entry object
2912 * @param obj The entry object
2913 * @param size font size
2918 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
2920 ELM_CHECK_WIDTYPE(obj, widtype);
2921 Widget_Data *wd = elm_widget_data_get(obj);
2922 Eina_Strbuf *fontbuf = NULL;
2927 t = eina_stringshare_add(elm_entry_entry_get(obj));
2928 fontbuf = eina_strbuf_new();
2929 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
2931 if (fontsize == 0) removeflag = 1; // remove fontsize tag
2933 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
2935 elm_entry_entry_set(obj, t);
2939 eina_strbuf_free(fontbuf);
2940 eina_stringshare_del(t);
2944 * Set the text align on the entry object
2946 * @param obj The entry object
2947 * @param align align mode
2952 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
2954 ELM_CHECK_WIDTYPE(obj, widtype);
2955 Widget_Data *wd = elm_widget_data_get(obj);
2960 t = eina_stringshare_add(elm_entry_entry_get(obj));
2962 if (len <= 0) return;
2964 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
2965 elm_entry_entry_set(obj, t);
2969 eina_stringshare_del(t);
2973 * Set the text color on the entry object
2975 * @param obj The entry object
2976 * @param r Red property background color of The entry object
2977 * @param g Green property background color of The entry object
2978 * @param b Blue property background color of The entry object
2979 * @param a Alpha property background alpha of The entry object
2984 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
2986 ELM_CHECK_WIDTYPE(obj, widtype);
2987 Widget_Data *wd = elm_widget_data_get(obj);
2988 Eina_Strbuf *colorbuf = NULL;
2993 t = eina_stringshare_add(elm_entry_entry_get(obj));
2995 if (len <= 0) return;
2996 colorbuf = eina_strbuf_new();
2997 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
2999 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3001 elm_entry_entry_set(obj, t);
3005 eina_strbuf_free(colorbuf);
3006 eina_stringshare_del(t);
3011 * Set background color of the entry
3013 * @param obj The entry object
3014 * @param r Red property background color of The entry object
3015 * @param g Green property background color of The entry object
3016 * @param b Blue property background color of The entry object
3017 * @param a Alpha property background alpha of The entry object
3021 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3023 ELM_CHECK_WIDTYPE(obj, widtype);
3024 Widget_Data *wd = elm_widget_data_get(obj);
3025 evas_object_color_set(wd->bg, r, g, b, a);
3027 if (wd->bgcolor == EINA_FALSE)
3030 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3035 * Set the ellipsis behavior of the entry
3037 * @param obj The entry object
3038 * @param ellipsis To ellipsis text or not
3042 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3044 ELM_CHECK_WIDTYPE(obj, widtype);
3045 Widget_Data *wd = elm_widget_data_get(obj);
3046 if (wd->ellipsis == ellipsis) return;
3047 wd->ellipsis = ellipsis;
3053 * This sets the attribute to show the input panel automatically.
3055 * @param obj The entry object
3056 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3061 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3063 ELM_CHECK_WIDTYPE(obj, widtype);
3064 Widget_Data *wd = elm_widget_data_get(obj);
3067 wd->input_panel_enable = enabled;
3068 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3072 * Set the input panel layout of the entry
3074 * @param obj The entry object
3075 * @param layout the layout to set
3080 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3082 ELM_CHECK_WIDTYPE(obj, widtype);
3083 Widget_Data *wd = elm_widget_data_get(obj);
3086 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3089 wd->input_panel_layout = layout;
3091 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);