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;
142 struct _Elm_Entry_Item_Provider
144 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
148 static const char *widtype = NULL;
149 static void _del_hook(Evas_Object *obj);
150 static void _theme_hook(Evas_Object *obj);
151 static void _disable_hook(Evas_Object *obj);
152 static void _sizing_eval(Evas_Object *obj);
153 static void _on_focus_hook(void *data, Evas_Object *obj);
154 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
155 static const char *_getbase(Evas_Object *obj);
156 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
157 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
158 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
159 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
160 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
161 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
162 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
163 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
164 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
165 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
166 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
167 static int _is_width_over(Evas_Object *obj);
168 static void _ellipsis_entry_to_width(Evas_Object *obj);
169 static void _reverse_ellipsis_entry(Evas_Object *obj);
170 static int _textinput_control_function(void *data,void *input_data);
171 static int _entry_length_get(Evas_Object *obj);
173 static const char SIG_CHANGED[] = "changed";
174 static const char SIG_ACTIVATED[] = "activated";
175 static const char SIG_PRESS[] = "press";
176 static const char SIG_LONGPRESSED[] = "longpressed";
177 static const char SIG_CLICKED[] = "clicked";
178 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
179 static const char SIG_FOCUSED[] = "focused";
180 static const char SIG_UNFOCUSED[] = "unfocused";
181 static const char SIG_SELECTION_PASTE[] = "selection,paste";
182 static const char SIG_SELECTION_COPY[] = "selection,copy";
183 static const char SIG_SELECTION_CUT[] = "selection,cut";
184 static const char SIG_SELECTION_START[] = "selection,start";
185 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
186 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
187 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
188 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
189 static const Evas_Smart_Cb_Description _signals[] = {
193 {SIG_LONGPRESSED, ""},
195 {SIG_CLICKED_DOUBLE, ""},
198 {SIG_SELECTION_PASTE, ""},
199 {SIG_SELECTION_COPY, ""},
200 {SIG_SELECTION_CUT, ""},
201 {SIG_SELECTION_START, ""},
202 {SIG_SELECTION_CHANGED, ""},
203 {SIG_SELECTION_CLEARED, ""},
204 {SIG_CURSOR_CHANGED, ""},
205 {SIG_ANCHOR_CLICKED, ""},
209 static Eina_List *entries = NULL;
213 void (*obj_hook) (Evas_Object *obj);
214 void (*obj_unhook) (Evas_Object *obj);
215 void (*obj_longpress) (Evas_Object *obj);
216 void (*obj_mouseup) (Evas_Object *obj);
220 _module(Evas_Object *obj __UNUSED__)
222 static Elm_Module *m = NULL;
223 if (m) goto ok; // already found - just use
224 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
226 m->api = malloc(sizeof(Mod_Api));
227 if (!m->api) return NULL;
228 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
229 _elm_module_symbol_get(m, "obj_hook");
230 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
231 _elm_module_symbol_get(m, "obj_unhook");
232 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
233 _elm_module_symbol_get(m, "obj_longpress");
234 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
235 _elm_module_symbol_get(m, "obj_mouseup");
236 ok: // ok - return api
241 _del_hook(Evas_Object *obj)
243 Widget_Data *wd = elm_widget_data_get(obj);
244 Elm_Entry_Context_Menu_Item *it;
245 Elm_Entry_Item_Provider *ip;
247 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
248 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
250 entries = eina_list_remove(entries, obj);
251 #ifdef HAVE_ELEMENTARY_X
252 ecore_event_handler_del(wd->sel_notify_handler);
253 ecore_event_handler_del(wd->sel_clear_handler);
255 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
256 if (wd->text) eina_stringshare_del(wd->text);
257 if (wd->bg) evas_object_del(wd->bg);
258 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
259 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
260 EINA_LIST_FREE(wd->items, it)
262 eina_stringshare_del(it->label);
263 eina_stringshare_del(it->icon_file);
264 eina_stringshare_del(it->icon_group);
267 EINA_LIST_FREE(wd->item_providers, ip)
275 _theme_hook(Evas_Object *obj)
277 Widget_Data *wd = elm_widget_data_get(obj);
279 Ecore_IMF_Context *ic;
281 t = eina_stringshare_add(elm_entry_entry_get(obj));
282 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
283 elm_entry_entry_set(obj, t);
284 eina_stringshare_del(t);
285 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
286 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
287 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
289 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
292 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
299 _disable_hook(Evas_Object *obj)
301 Widget_Data *wd = elm_widget_data_get(obj);
303 if (elm_widget_disabled_get(obj))
305 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
306 wd->disabled = EINA_TRUE;
310 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
311 wd->disabled = EINA_FALSE;
316 _elm_win_recalc_job(void *data)
318 Widget_Data *wd = elm_widget_data_get(data);
319 Evas_Coord minw = -1, minh = -1, maxh = -1;
320 Evas_Coord resw, resh, minminw;
322 wd->deferred_recalc_job = NULL;
323 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
326 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
327 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
329 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
330 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
331 evas_object_size_hint_min_set(data, minminw, minh);
332 if (wd->single_line) maxh = minh;
333 evas_object_size_hint_max_set(data, -1, maxh);
334 if (wd->deferred_cur)
335 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
339 _sizing_eval(Evas_Object *obj)
341 Widget_Data *wd = elm_widget_data_get(obj);
342 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
343 Evas_Coord resw, resh;
345 if (wd->linewrap || wd->char_linewrap)
347 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
348 if ((resw == wd->lastw) && (!wd->changed)) return;
349 wd->changed = EINA_FALSE;
351 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
352 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
356 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
357 edje_object_size_min_calc(wd->ent, &minw, &minh);
358 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
359 evas_object_size_hint_min_set(obj, minw, minh);
360 if (wd->single_line) maxh = minh;
361 evas_object_size_hint_max_set(obj, maxw, maxh);
363 if (wd->ellipsis && wd->single_line)
365 if (_is_width_over(obj))
366 _ellipsis_entry_to_width(obj);
367 else if (wd->ellipsis_threshold > 1 && _entry_length_get(obj) < wd->ellipsis_threshold)
368 _reverse_ellipsis_entry(obj);
374 _check_enable_returnkey(Evas_Object *obj)
376 Widget_Data *wd = elm_widget_data_get(obj);
379 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
382 if (!wd->autoreturnkey) return;
384 if (_entry_length_get(obj) == 0)
386 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
390 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
395 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
397 Widget_Data *wd = elm_widget_data_get(obj);
398 Evas_Object *top = elm_widget_top_get(obj);
400 if (!wd->editable) return;
401 if (elm_widget_focus_get(obj))
403 evas_object_focus_set(wd->ent, 1);
404 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
405 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
406 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
407 _check_enable_returnkey(obj);
411 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
412 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", "");
413 evas_object_focus_set(wd->ent, 0);
414 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
415 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
420 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
422 Widget_Data *wd = elm_widget_data_get(obj);
424 edje_object_signal_emit(wd->ent, emission, source);
428 _hoversel_position(Evas_Object *obj)
430 Widget_Data *wd = elm_widget_data_get(obj);
431 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
433 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
434 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
436 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
447 evas_object_move(wd->hoversel, x + cx, y + cy);
448 evas_object_resize(wd->hoversel, cw, ch);
452 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
454 Widget_Data *wd = elm_widget_data_get(data);
456 if (wd->hoversel) _hoversel_position(data);
460 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
462 Widget_Data *wd = elm_widget_data_get(data);
464 if (wd->linewrap || wd->char_linewrap)
468 if (wd->hoversel) _hoversel_position(data);
469 // Evas_Coord ww, hh;
470 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
474 _hover_del(void *data)
476 Widget_Data *wd = elm_widget_data_get(data);
481 evas_object_del(wd->hoversel);
484 wd->hovdeljob = NULL;
488 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
490 Widget_Data *wd = elm_widget_data_get(data);
492 if (wd->hoversel) evas_object_hide(wd->hoversel);
496 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
498 elm_widget_scroll_freeze_pop(data);
499 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
500 wd->hovdeljob = ecore_job_add(_hover_del, data);
504 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
506 Widget_Data *wd = elm_widget_data_get(data);
508 wd->selmode = EINA_TRUE;
509 edje_object_part_text_select_none(wd->ent, "elm.text");
511 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
512 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
513 elm_widget_scroll_hold_push(data);
517 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
519 Widget_Data *wd = elm_widget_data_get(data);
521 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
522 if (wd->sel_notify_handler)
524 #ifdef HAVE_ELEMENTARY_X
525 wd->selection_asked = EINA_TRUE;
526 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_MARKUP, data);
532 _store_selection(enum _elm_sel_type seltype, Evas_Object *obj)
534 Widget_Data *wd = elm_widget_data_get(obj);
538 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
539 elm_selection_set(seltype, obj, ELM_SEL_MARKUP, sel);
540 if (seltype == ELM_SEL_CLIPBOARD)
541 eina_stringshare_replace(&wd->cut_sel, sel);
545 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
547 Widget_Data *wd = elm_widget_data_get(data);
550 wd->selmode = EINA_FALSE;
551 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
552 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
553 elm_widget_scroll_hold_pop(data);
554 _store_selection(ELM_SEL_CLIPBOARD, data);
555 edje_object_part_text_insert(wd->ent, "elm.text", "");
556 edje_object_part_text_select_none(wd->ent, "elm.text");
560 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
562 Widget_Data *wd = elm_widget_data_get(data);
564 wd->selmode = EINA_FALSE;
565 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
566 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
567 elm_widget_scroll_hold_pop(data);
568 _store_selection(ELM_SEL_CLIPBOARD, data);
569 // edje_object_part_text_select_none(wd->ent, "elm.text");
573 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
575 Widget_Data *wd = elm_widget_data_get(data);
577 wd->selmode = EINA_FALSE;
578 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
579 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
580 elm_widget_scroll_hold_pop(data);
581 edje_object_part_text_select_none(wd->ent, "elm.text");
585 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
587 Elm_Entry_Context_Menu_Item *it = data;
588 Evas_Object *obj2 = it->obj;
589 if (it->func) it->func(it->data, obj2, NULL);
593 _long_press(void *data)
595 Widget_Data *wd = elm_widget_data_get(data);
598 const Elm_Entry_Context_Menu_Item *it;
599 if (!wd) return ECORE_CALLBACK_CANCEL;
600 if ((wd->api) && (wd->api->obj_longpress))
602 wd->api->obj_longpress(data);
604 else if (wd->context_menu)
606 const char *context_menu_orientation;
608 if (wd->hoversel) evas_object_del(wd->hoversel);
609 else elm_widget_scroll_freeze_push(data);
610 wd->hoversel = elm_hoversel_add(data);
611 context_menu_orientation = edje_object_data_get
612 (wd->ent, "context_menu_orientation");
613 if ((context_menu_orientation) &&
614 (!strcmp(context_menu_orientation, "horizontal")))
615 elm_hoversel_horizontal_set(wd->hoversel, 1);
616 elm_object_style_set(wd->hoversel, "entry");
617 elm_widget_sub_object_add(data, wd->hoversel);
618 elm_hoversel_label_set(wd->hoversel, "Text");
619 top = elm_widget_top_get(data);
620 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
621 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
625 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
627 if (1) // need way to detect if someone has a selection
630 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
638 if (wd->have_selection)
640 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
643 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
646 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
650 EINA_LIST_FOREACH(wd->items, l, it)
652 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
653 it->icon_type, _item_clicked, it);
657 _hoversel_position(data);
658 evas_object_show(wd->hoversel);
659 elm_hoversel_hover_begin(wd->hoversel);
661 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
662 edje_object_part_text_select_abort(wd->ent, "elm.text");
664 wd->longpress_timer = NULL;
665 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
666 return ECORE_CALLBACK_CANCEL;
670 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
672 Widget_Data *wd = elm_widget_data_get(data);
673 Evas_Event_Mouse_Down *ev = event_info;
675 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
676 if (ev->button != 1) return;
677 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
678 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
679 wd->longpress_timer = ecore_timer_add(1.0, _long_press, data);
680 wd->downx = ev->canvas.x;
681 wd->downy = ev->canvas.y;
685 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
687 Widget_Data *wd = elm_widget_data_get(data);
688 Evas_Event_Mouse_Up *ev = event_info;
690 if (ev->button != 1) return;
691 if ((wd->api) && (wd->api->obj_mouseup))
693 wd->api->obj_mouseup(data);
695 if (wd->longpress_timer)
697 ecore_timer_del(wd->longpress_timer);
698 wd->longpress_timer = NULL;
703 _mouse_move(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_Move *ev = event_info;
710 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
712 if (wd->longpress_timer)
714 ecore_timer_del(wd->longpress_timer);
715 wd->longpress_timer = NULL;
718 else if (wd->longpress_timer)
722 dx = wd->downx - ev->cur.canvas.x;
724 dy = wd->downy - ev->cur.canvas.y;
727 ((_elm_config->finger_size / 2) *
728 (_elm_config->finger_size / 2)))
730 ecore_timer_del(wd->longpress_timer);
731 wd->longpress_timer = NULL;
735 else if (wd->longpress_timer)
739 dx = wd->downx - ev->cur.canvas.x;
741 dy = wd->downy - ev->cur.canvas.y;
744 ((_elm_config->finger_size / 2) *
745 (_elm_config->finger_size / 2)))
747 ecore_timer_del(wd->longpress_timer);
748 wd->longpress_timer = NULL;
754 _getbase(Evas_Object *obj)
756 Widget_Data *wd = elm_widget_data_get(obj);
757 if (!wd) return "base";
760 if((wd->password)&&(wd->show_last_character)) return "custom-password";
761 else if(wd->password) return "base-password";
764 if (wd->single_line) return "base-single";
767 if (wd->linewrap) return "base";
768 else if (wd->char_linewrap) return "base-charwrap";
769 else return "base-nowrap";
775 if((wd->password)&&(wd->show_last_character)) return "custom-password";
776 else if(wd->password) return "base-password";
779 if (wd->single_line) return "base-single-noedit";
782 if (wd->linewrap) return "base-noedit";
783 else if (wd->char_linewrap) return "base-noedit-charwrap";
784 else return "base-nowrap-noedit";
792 _str_append(char *str, const char *txt, int *len, int *alloc)
794 int txt_len = strlen(txt);
796 if (txt_len <= 0) return str;
797 if ((*len + txt_len) >= *alloc)
802 alloc2 = *alloc + txt_len + 128;
803 str2 = realloc(str, alloc2);
804 if (!str2) return str;
808 strcpy(str + *len, txt);
813 /*FIXME: Sholud be implemented somewhere else, it really depends on the context
814 * because some markups can be implemented otherwise according to style.
815 * probably doing it in textblock and making it translate according to it's
816 * style is correct. */
818 _strncpy(char* dest, const char* src, size_t count)
822 ERR( "dest is NULL" );
827 ERR( "src is NULL" );
832 ERR( "count is smaller than 0" );
836 return strncpy( dest, src, count );
840 _mkup_to_text(const char *mkup)
843 int str_len = 0, str_alloc = 0;
845 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
847 if (!mkup) return NULL;
849 tag_start = tag_end = esc_start = esc_end = NULL;
854 if (((p!=NULL)&&(*p == 0)) ||
855 (tag_end) || (esc_end) ||
856 (tag_start) || (esc_start))
862 ttag = malloc(tag_end - tag_start);
865 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
866 ttag[tag_end - tag_start - 1] = 0;
867 if (!strcmp(ttag, "br"))
868 str = _str_append(str, "\n", &str_len, &str_alloc);
869 else if (!strcmp(ttag, "\n"))
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, "\t"))
874 str = _str_append(str, "\t", &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, "ps")) /* Unicode paragraph separator */
878 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
881 tag_start = tag_end = NULL;
885 ts = malloc(esc_end - esc_start + 1);
889 _strncpy(ts, esc_start, esc_end - esc_start);
890 ts[esc_end - esc_start] = 0;
891 esc = evas_textblock_escape_string_get(ts);
893 str = _str_append(str, esc, &str_len, &str_alloc);
896 esc_start = esc_end = NULL;
898 else if ((p!=NULL)&&(*p == 0))
900 ts = malloc(p - s + 1);
903 _strncpy(ts, s, p - s);
905 str = _str_append(str, ts, &str_len, &str_alloc);
911 if ((p!=NULL)&&(*p == '<'))
917 ts = malloc(p - s + 1);
920 _strncpy(ts, s, p - s);
922 str = _str_append(str, ts, &str_len, &str_alloc);
928 else if ((p!=NULL)&&(*p == '>'))
936 else if ((p!=NULL)&&(*p == '&'))
942 ts = malloc(p - s + 1);
945 _strncpy(ts, s, p - s);
947 str = _str_append(str, ts, &str_len, &str_alloc);
953 else if ((p!=NULL)&&(*p == ';'))
967 _entry_length_get(Evas_Object *obj)
970 const char *str = elm_entry_entry_get(obj);
973 char *plain_str = _mkup_to_text(str);
974 if (!plain_str) return 0;
976 len = strlen(plain_str);
983 _text_to_mkup(const char *text)
986 int str_len = 0, str_alloc = 0;
987 int ch, pos = 0, pos2 = 0;
989 if (!text) return NULL;
993 pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
994 if ((ch <= 0) || (pos2 <= 0)) break;
996 str = _str_append(str, "<br>", &str_len, &str_alloc);
998 str = _str_append(str, "<\t>", &str_len, &str_alloc);
1000 str = _str_append(str, "<", &str_len, &str_alloc);
1002 str = _str_append(str, ">", &str_len, &str_alloc);
1004 str = _str_append(str, "&", &str_len, &str_alloc);
1009 _strncpy(tstr, text + pos, pos2 - pos);
1010 tstr[pos2 - pos] = 0;
1011 str = _str_append(str, tstr, &str_len, &str_alloc);
1018 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1020 Widget_Data *wd = elm_widget_data_get(data);
1022 wd->changed = EINA_TRUE;
1024 if (wd->text) eina_stringshare_del(wd->text);
1026 _check_enable_returnkey(data);
1027 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1031 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1033 Widget_Data *wd = elm_widget_data_get(data);
1037 EINA_LIST_FOREACH(entries, l, entry)
1039 if (entry != data) elm_entry_select_none(entry);
1041 wd->have_selection = EINA_TRUE;
1042 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1043 #ifdef HAVE_ELEMENTARY_X
1044 if (wd->sel_notify_handler)
1046 const char *txt = elm_entry_selection_get(data);
1049 top = elm_widget_top_get(data);
1050 if ((top) && (elm_win_xwindow_get(top)))
1051 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP, txt);
1057 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1059 Widget_Data *wd = elm_widget_data_get(data);
1061 wd->have_selection = EINA_TRUE;
1062 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1063 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_MARKUP,
1064 elm_entry_selection_get(data));
1068 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1070 Widget_Data *wd = elm_widget_data_get(data);
1072 if (!wd->have_selection) return;
1073 wd->have_selection = EINA_FALSE;
1074 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1075 if (wd->sel_notify_handler)
1079 #ifdef HAVE_ELEMENTARY_X
1082 top = elm_widget_top_get(data);
1083 if ((top) && (elm_win_xwindow_get(top)))
1084 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_MARKUP,
1087 eina_stringshare_del(wd->cut_sel);
1092 #ifdef HAVE_ELEMENTARY_X
1095 top = elm_widget_top_get(data);
1096 if ((top) && (elm_win_xwindow_get(top)))
1097 elm_selection_clear(ELM_SEL_PRIMARY, data);
1104 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1106 Widget_Data *wd = elm_widget_data_get(data);
1108 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1109 if (wd->sel_notify_handler)
1111 #ifdef HAVE_ELEMENTARY_X
1114 top = elm_widget_top_get(data);
1115 if ((top) && (elm_win_xwindow_get(top)))
1117 wd->selection_asked = EINA_TRUE;
1118 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_MARKUP, data);
1125 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1127 Widget_Data *wd = elm_widget_data_get(data);
1129 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1130 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1131 elm_entry_selection_get(data));
1135 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1137 Widget_Data *wd = elm_widget_data_get(data);
1139 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1140 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_MARKUP,
1141 elm_entry_selection_get(data));
1142 edje_object_part_text_insert(wd->ent, "elm.text", "");
1143 wd->changed = EINA_TRUE;
1148 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1150 Widget_Data *wd = elm_widget_data_get(data);
1151 Evas_Coord cx, cy, cw, ch;
1153 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1154 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1155 &cx, &cy, &cw, &ch);
1156 if (!wd->deferred_recalc_job)
1157 elm_widget_show_region_set(data, cx, cy, cw, ch);
1160 wd->deferred_cur = EINA_TRUE;
1169 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1171 Widget_Data *wd = elm_widget_data_get(data);
1176 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1178 Widget_Data *wd = elm_widget_data_get(data);
1179 Elm_Entry_Anchor_Info ei;
1180 char *buf2, *p, *p2, *n;
1182 p = strrchr(emission, ',');
1185 const Eina_List *geoms;
1189 while (p2 >= emission)
1191 if (*p2 == ',') break;
1195 buf2 = alloca(5 + p - p2);
1196 strncpy(buf2, p2, p - p2);
1199 ei.button = atoi(buf2);
1200 ei.x = ei.y = ei.w = ei.h = 0;
1202 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1205 Evas_Textblock_Rectangle *r;
1207 Evas_Coord px, py, x, y;
1209 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1210 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1211 EINA_LIST_FOREACH(geoms, l, r)
1213 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1214 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1225 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1230 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1232 Widget_Data *wd = elm_widget_data_get(data);
1237 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1239 Widget_Data *wd = elm_widget_data_get(data);
1244 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1246 Widget_Data *wd = elm_widget_data_get(data);
1251 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1253 Widget_Data *wd = elm_widget_data_get(data);
1255 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1259 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1261 Widget_Data *wd = elm_widget_data_get(data);
1263 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1267 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1269 Widget_Data *wd = elm_widget_data_get(data);
1271 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1275 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1277 Widget_Data *wd = elm_widget_data_get(data);
1279 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1282 #ifdef HAVE_ELEMENTARY_X
1284 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1286 Widget_Data *wd = elm_widget_data_get(data);
1287 Ecore_X_Event_Selection_Notify *ev = event;
1288 if (!wd) return ECORE_CALLBACK_PASS_ON;
1289 if (!wd->selection_asked) return ECORE_CALLBACK_PASS_ON;
1291 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1292 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1294 Ecore_X_Selection_Data_Text *text_data;
1296 text_data = ev->data;
1297 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1299 if (text_data->text)
1301 char *txt = _text_to_mkup(text_data->text);
1305 elm_entry_entry_insert(data, txt);
1310 wd->selection_asked = EINA_FALSE;
1312 return ECORE_CALLBACK_PASS_ON;
1316 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1319 Widget_Data *wd = elm_widget_data_get(data);
1320 Ecore_X_Event_Selection_Clear *ev = event;
1322 if (!wd->have_selection) return 1;
1323 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1324 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1326 elm_entry_select_none(data);
1329 return ECORE_CALLBACK_PASS_ON;
1333 static Evas_Object *
1334 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1336 Widget_Data *wd = elm_widget_data_get(data);
1339 Elm_Entry_Item_Provider *ip;
1342 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1344 o = ip->func(ip->data, data, item);
1347 o = edje_object_add(evas_object_evas_get(data));
1348 if (!strncmp(item, "emoticon/", 9))
1349 ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1351 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1356 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1358 char *curlocater, *starttag, *endtag;
1359 int firstindex = 0, foundflag = -1;
1361 curlocater = strstr(oldstring, key);
1364 starttag = curlocater;
1365 endtag = curlocater + strlen(key);
1366 if (endtag == NULL || *endtag != '=')
1372 firstindex = abs(oldstring - curlocater);
1373 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1374 *value = (char*)oldstring + firstindex;
1376 while (oldstring != starttag)
1378 if (*starttag == '>')
1383 if (*starttag == '<')
1387 if (starttag == NULL) break;
1390 while (NULL != endtag)
1401 if (endtag == NULL) break;
1404 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1414 if (foundflag == 1) return 0;
1420 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1422 const char *srcstring = NULL;
1423 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1424 char *curlocater, *replocater;
1425 char *starttag, *endtag;
1426 int tagtxtlen = 0, insertflag = 0;
1428 srcstring = eina_strbuf_string_get(srcbuf);
1429 curlocater = strstr(srcstring, key);
1431 if (curlocater == NULL)
1439 starttag = strchr(srcstring, '<');
1440 endtag = strchr(srcstring, '>');
1441 tagtxtlen = endtag - starttag;
1442 if (tagtxtlen <= 0) tagtxtlen = 0;
1443 if (starttag < curlocater && curlocater < endtag) break;
1444 if (endtag != NULL && endtag+1 != NULL)
1445 srcstring = endtag+1;
1448 } while (strlen(srcstring) > 1);
1450 if (starttag && endtag && tagtxtlen > strlen(key))
1452 repbuf = eina_strbuf_new();
1453 diffbuf = eina_strbuf_new();
1454 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1455 srcstring = eina_strbuf_string_get(repbuf);
1456 curlocater = strstr(srcstring, key);
1458 if (curlocater != NULL)
1460 replocater = curlocater + strlen(key) + 1;
1462 while (*replocater == ' ' || *replocater == '=')
1467 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1470 if (replocater-curlocater > strlen(key)+1)
1473 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1482 eina_strbuf_reset(repbuf);
1490 if (repbuf == NULL) repbuf = eina_strbuf_new();
1491 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1495 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1496 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1502 eina_strbuf_prepend(diffbuf, "<");
1503 eina_strbuf_append(diffbuf, ">");
1504 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1508 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1509 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1513 if (repbuf) eina_strbuf_free(repbuf);
1514 if (diffbuf) eina_strbuf_free(diffbuf);
1520 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1522 Eina_Strbuf *sharebuf = NULL;
1524 sharebuf = eina_strbuf_new();
1525 eina_strbuf_append(sharebuf, *srcstring);
1526 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1527 eina_stringshare_del(*srcstring);
1528 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1529 eina_strbuf_free(sharebuf);
1535 _is_width_over(Evas_Object *obj)
1537 Evas_Coord x, y, w, h;
1538 Evas_Coord vx, vy, vw, vh;
1539 Widget_Data *wd = elm_widget_data_get(obj);
1543 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1545 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1547 if (x >= 0 && y >= 0)
1550 if (4 < wd->wrap_w && w > wd->wrap_w)
1557 _reverse_ellipsis_entry(Evas_Object *obj)
1559 Widget_Data *wd = elm_widget_data_get(obj);
1560 int cur_fontsize = 0;
1561 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1562 char **kvalue = NULL;
1563 const char *minfont, *deffont, *maxfont;
1564 const char *ellipsis_string = "...";
1565 int minfontsize, maxfontsize, minshowcount;
1567 minshowcount = strlen(ellipsis_string) + 1;
1568 minfont = edje_object_data_get(wd->ent, "min_font_size");
1569 if (minfont) minfontsize = atoi(minfont);
1570 else minfontsize = 1;
1571 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1572 if (maxfont) maxfontsize = atoi(maxfont);
1573 else maxfontsize = 1;
1574 deffont = edje_object_data_get(wd->ent, "default_font_size");
1575 if (deffont) cur_fontsize = atoi(deffont);
1576 else cur_fontsize = 1;
1577 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1578 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1580 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1582 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1585 txtbuf = eina_strbuf_new();
1586 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1588 if (cur_fontsize >= atoi(deffont))
1590 if (txtbuf) eina_strbuf_free(txtbuf);
1594 if (_is_width_over(obj) != 1)
1596 int rev_fontsize = cur_fontsize;
1600 if (rev_fontsize > atoi(deffont))
1603 if (fontbuf != NULL)
1605 eina_strbuf_free(fontbuf);
1608 fontbuf = eina_strbuf_new();
1609 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1610 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1611 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1613 eina_strbuf_free(fontbuf);
1615 } while (_is_width_over(obj) != 1);
1617 while (_is_width_over(obj))
1620 if (rev_fontsize < atoi(deffont))
1623 if (fontbuf != NULL)
1625 eina_strbuf_free(fontbuf);
1628 fontbuf = eina_strbuf_new();
1629 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1630 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1631 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1632 eina_strbuf_free(fontbuf);
1637 if (txtbuf) eina_strbuf_free(txtbuf);
1643 _ellipsis_entry_to_width(Evas_Object *obj)
1645 Widget_Data *wd = elm_widget_data_get(obj);
1646 int cur_fontsize = 0, len, jumpcount;
1647 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1648 char **kvalue = NULL;
1649 const char *minfont, *deffont, *maxfont;
1650 const char *ellipsis_string = "...";
1651 int minfontsize, maxfontsize, minshowcount;
1652 int i, tagend, cur_len;
1655 minshowcount = strlen(ellipsis_string) + 1;
1656 minfont = edje_object_data_get(wd->ent, "min_font_size");
1657 if (minfont) minfontsize = atoi(minfont);
1658 else minfontsize = 1;
1659 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1660 if (maxfont) maxfontsize = atoi(maxfont);
1661 else maxfontsize = 1;
1662 deffont = edje_object_data_get(wd->ent, "default_font_size");
1663 if (deffont) cur_fontsize = atoi(deffont);
1664 else cur_fontsize = 1;
1665 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1666 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1668 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1670 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1673 txtbuf = eina_strbuf_new();
1674 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1676 while (_is_width_over(obj))
1678 if (wd->ellipsis_threshold == 0)
1679 wd->ellipsis_threshold = _entry_length_get(obj);
1680 if (cur_fontsize > minfontsize)
1683 if (fontbuf != NULL)
1685 eina_strbuf_free(fontbuf);
1688 fontbuf = eina_strbuf_new();
1689 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1690 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1691 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1692 eina_strbuf_free(fontbuf);
1694 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1698 len = _entry_length_get(obj);
1699 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1700 cur_len = strlen(cur_str);
1702 for (i = 0; i < len; i++)
1704 if(cur_str[i] == '>' && cur_str[i+1] != NULL &&
1705 cur_str[i+1] != '<')
1712 while (jumpcount < len-strlen(ellipsis_string))
1714 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1718 eina_strbuf_free(txtbuf);
1721 txtbuf = eina_strbuf_new();
1722 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1723 eina_strbuf_append(txtbuf, ellipsis_string);
1724 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1725 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1726 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1728 if (_is_width_over(obj))
1736 if (txtbuf) eina_strbuf_free(txtbuf);
1741 static int _textinput_control_function(void *data,void *input_data)
1743 /*calculate character count*/
1744 Evas_Object *entry = (Evas_Object *)data;
1745 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1748 size_t insert_text_len=0;
1749 char *text = edje_object_part_text_get(wd->ent, "elm.text");
1751 size_t remain_bytes;
1754 byte_len = strlen(text);/*no of bytes*/
1755 remain_bytes = wd->max_no_of_bytes-byte_len;
1756 sprintf(buf,"%d",remain_bytes);
1757 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1760 insert_text = (char *)input_data;
1761 insert_text_len = strlen(insert_text);
1762 if(remain_bytes<insert_text_len)
1764 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1767 if(byte_len>=wd->max_no_of_bytes)
1769 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1778 * This adds an entry to @p parent object.
1780 * @param parent The parent object
1781 * @return The new object or NULL if it cannot be created
1786 elm_entry_add(Evas_Object *parent)
1788 Evas_Object *obj, *top;
1792 wd = ELM_NEW(Widget_Data);
1793 e = evas_object_evas_get(parent);
1794 wd->bgcolor = EINA_FALSE;
1795 wd->bg = evas_object_rectangle_add(e);
1796 evas_object_color_set(wd->bg, 0, 0, 0, 0);
1797 obj = elm_widget_add(e);
1798 ELM_SET_WIDTYPE(widtype, "entry");
1799 elm_widget_type_set(obj, "entry");
1800 elm_widget_sub_object_add(parent, obj);
1801 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1802 elm_widget_data_set(obj, wd);
1803 elm_widget_del_hook_set(obj, _del_hook);
1804 elm_widget_theme_hook_set(obj, _theme_hook);
1805 elm_widget_disable_hook_set(obj, _disable_hook);
1806 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1807 elm_widget_can_focus_set(obj, 1);
1809 wd->linewrap = EINA_TRUE;
1810 wd->ellipsis = EINA_FALSE;
1811 wd->char_linewrap= EINA_FALSE;
1812 wd->editable = EINA_TRUE;
1813 wd->disabled = EINA_FALSE;
1814 wd->context_menu = EINA_TRUE;
1816 wd->ellipsis_threshold = 0;
1818 wd->ent = edje_object_add(e);
1819 edje_object_item_provider_set(wd->ent, _get_item, obj);
1820 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1821 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1822 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1824 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1826 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1829 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1830 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1831 _signal_entry_changed, obj);
1832 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1833 _signal_selection_start, obj);
1834 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1835 _signal_selection_changed, obj);
1836 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1837 _signal_selection_cleared, obj);
1838 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1839 _signal_entry_paste_request, obj);
1840 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1841 _signal_entry_copy_notify, obj);
1842 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1843 _signal_entry_cut_notify, obj);
1844 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1845 _signal_cursor_changed, obj);
1846 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1847 _signal_anchor_down, obj);
1848 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1849 _signal_anchor_up, obj);
1850 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1851 _signal_anchor_move, obj);
1852 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1853 _signal_anchor_in, obj);
1854 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1855 _signal_anchor_out, obj);
1856 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1857 _signal_key_enter, obj);
1858 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1859 _signal_mouse_down, obj);
1860 edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
1861 _signal_mouse_up, obj);
1862 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1863 _signal_mouse_double, obj);
1864 edje_object_part_text_set(wd->ent, "elm.text", "");
1865 elm_widget_resize_object_set(obj, wd->ent);
1868 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
1870 #ifdef HAVE_ELEMENTARY_X
1871 top = elm_widget_top_get(obj);
1872 if ((top) && (elm_win_xwindow_get(top)))
1874 wd->sel_notify_handler =
1875 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1876 _event_selection_notify, obj);
1877 wd->sel_clear_handler =
1878 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1879 _event_selection_clear, obj);
1883 entries = eina_list_prepend(entries, obj);
1885 // module - find module for entry
1886 wd->api = _module(obj);
1887 // if found - hook in
1888 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1890 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1891 // TODO: and save some bytes, making descriptions per-class and not instance!
1892 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1896 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
1898 ELM_CHECK_WIDTYPE(obj, widtype);
1899 Widget_Data *wd = elm_widget_data_get(obj);
1901 ext_mod->cancel = _cancel;
1902 ext_mod->copy = _copy;
1903 ext_mod->cut = _cut;
1904 ext_mod->paste = _paste;
1905 ext_mod->select = _select;
1906 ext_mod->selectall = NULL; /* to be implemented*/
1907 ext_mod->ent = wd->ent;
1908 ext_mod->items = wd->items;
1909 ext_mod->longpress_timer = wd->longpress_timer;
1910 ext_mod->editable = wd->editable;
1911 ext_mod->have_selection = wd->have_selection;
1912 ext_mod->password = wd->password;
1913 ext_mod->selmode = wd->selmode;
1917 * This sets the entry object not to line wrap. All input will
1918 * be on a single line, and the entry box will extend with user input.
1920 * @param obj The entry object
1921 * @param single_line If true, the text in the entry
1922 * will be on a single line.
1927 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1929 ELM_CHECK_WIDTYPE(obj, widtype);
1930 Widget_Data *wd = elm_widget_data_get(obj);
1932 Ecore_IMF_Context *ic;
1934 if (wd->single_line == single_line) return;
1935 wd->single_line = single_line;
1936 wd->linewrap = EINA_FALSE;
1937 wd->char_linewrap = EINA_FALSE;
1938 t = eina_stringshare_add(elm_entry_entry_get(obj));
1939 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1940 elm_entry_entry_set(obj, t);
1941 ic = elm_entry_imf_context_get(obj);
1944 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
1947 eina_stringshare_del(t);
1952 * This returns true if the entry has been set to single line mode.
1953 * See also elm_entry_single_line_set().
1955 * @param obj The entry object
1956 * @return single_line If true, the text in the entry is set to display
1962 elm_entry_single_line_get(const Evas_Object *obj)
1964 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1965 Widget_Data *wd = elm_widget_data_get(obj);
1966 if (!wd) return EINA_FALSE;
1967 return wd->single_line;
1971 * This set's the maximum bytes that can be added in entry.
1973 * @param obj The entry object
1974 * @param max_no_of_bytes Maximum number of bytes entry can have.
1979 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
1981 Widget_Data *wd = elm_widget_data_get(obj);
1983 wd->max_no_of_bytes = max_no_of_bytes;
1984 edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
1985 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
1990 * This sets the entry object to password mode. All text entered
1991 * and/or displayed within the widget will be replaced with asterisks (*).
1993 * @param obj The entry object
1994 * @param password If true, password mode is enabled.
1999 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2001 ELM_CHECK_WIDTYPE(obj, widtype);
2002 Widget_Data *wd = elm_widget_data_get(obj);
2003 Ecore_IMF_Context *ic;
2006 if (wd->password == password) return;
2007 wd->password = password;
2008 wd->show_last_character = EINA_FALSE;
2009 wd->single_line = EINA_TRUE;
2010 wd->linewrap = EINA_FALSE;
2011 wd->char_linewrap = EINA_FALSE;
2012 t = eina_stringshare_add(elm_entry_entry_get(obj));
2013 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2014 elm_entry_entry_set(obj, t);
2016 ic = elm_entry_imf_context_get(obj);
2019 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2022 eina_stringshare_del(t);
2027 * This set's the entry in password mode with out masking the last character entered by user,
2028 * and later masking the character after 2 seconds.
2030 * @param obj The entry object
2031 * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character"
2037 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2039 Widget_Data *wd = elm_widget_data_get(obj);
2042 if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character)) return;
2043 wd->show_last_character = show_last_character;
2044 wd->password = show_last_character;
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);
2051 eina_stringshare_del(t);
2056 * This returns whether password mode is enabled.
2057 * See also elm_entry_password_set().
2059 * @param obj The entry object
2060 * @return If true, the entry is set to display all characters
2066 elm_entry_password_get(const Evas_Object *obj)
2068 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2069 Widget_Data *wd = elm_widget_data_get(obj);
2070 if (!wd) return EINA_FALSE;
2071 return wd->password;
2075 * This sets the text displayed within the entry to @p entry.
2077 * @param obj The entry object
2078 * @param entry The text to be displayed
2083 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2085 ELM_CHECK_WIDTYPE(obj, widtype);
2086 Widget_Data *wd = elm_widget_data_get(obj);
2088 if (!entry) entry = "";
2089 if(wd->max_no_of_bytes)
2091 int len = strlen(entry);
2092 if(len > wd->max_no_of_bytes)
2094 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2098 edje_object_part_text_set(wd->ent, "elm.text", entry);
2099 if (wd->text) eina_stringshare_del(wd->text);
2101 wd->changed = EINA_TRUE;
2106 * This returns the text currently shown in object @p entry.
2107 * See also elm_entry_entry_set().
2109 * @param obj The entry object
2110 * @return The currently displayed text or NULL on failure
2115 elm_entry_entry_get(const Evas_Object *obj)
2117 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2118 Widget_Data *wd = elm_widget_data_get(obj);
2120 if (!wd) return NULL;
2121 if (wd->text) return wd->text;
2122 text = edje_object_part_text_get(wd->ent, "elm.text");
2125 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2128 eina_stringshare_replace(&wd->text, text);
2133 * This returns all selected text within the entry.
2135 * @param obj The entry object
2136 * @return The selected text within the entry or NULL on failure
2141 elm_entry_selection_get(const Evas_Object *obj)
2143 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2144 Widget_Data *wd = elm_widget_data_get(obj);
2145 if (!wd) return NULL;
2146 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2150 * This inserts text in @p entry at the beginning of the entry
2153 * @param obj The entry object
2154 * @param entry The text to insert
2159 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2161 ELM_CHECK_WIDTYPE(obj, widtype);
2162 Widget_Data *wd = elm_widget_data_get(obj);
2164 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2165 wd->changed = EINA_TRUE;
2170 * This enables word line wrapping in the entry object. It is the opposite
2171 * of elm_entry_single_line_set(). Additionally, setting this disables
2172 * character line wrapping.
2173 * See also elm_entry_line_char_wrap_set().
2175 * @param obj The entry object
2176 * @param wrap If true, the entry will be wrapped once it reaches the end
2177 * of the object. Wrapping will occur at the end of the word before the end of the
2183 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2185 ELM_CHECK_WIDTYPE(obj, widtype);
2186 Widget_Data *wd = elm_widget_data_get(obj);
2189 if (wd->linewrap == wrap) return;
2190 wd->linewrap = wrap;
2192 wd->char_linewrap = EINA_FALSE;
2193 t = eina_stringshare_add(elm_entry_entry_get(obj));
2194 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2195 elm_entry_entry_set(obj, t);
2196 eina_stringshare_del(t);
2201 * Set wrap width of the entry
2203 * @param obj The entry object
2204 * @param w The wrap width in pixels at a minimum where words need to wrap
2208 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2210 Widget_Data *wd = elm_widget_data_get(obj);
2211 if (wd->wrap_w == w) return;
2217 * get wrap width of the entry
2219 * @param obj The entry object
2220 * @return The wrap width in pixels at a minimum where words need to wrap
2224 elm_entry_wrap_width_get(const Evas_Object *obj)
2226 Widget_Data *wd = elm_widget_data_get(obj);
2231 * This enables character line wrapping in the entry object. It is the opposite
2232 * of elm_entry_single_line_set(). Additionally, setting this disables
2233 * word line wrapping.
2234 * See also elm_entry_line_wrap_set().
2236 * @param obj The entry object
2237 * @param wrap If true, the entry will be wrapped once it reaches the end
2238 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2243 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2245 ELM_CHECK_WIDTYPE(obj, widtype);
2246 Widget_Data *wd = elm_widget_data_get(obj);
2249 if (wd->char_linewrap == wrap) return;
2250 wd->char_linewrap = wrap;
2251 if(wd->char_linewrap)
2252 wd->linewrap = EINA_FALSE;
2253 t = eina_stringshare_add(elm_entry_entry_get(obj));
2254 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2255 elm_entry_entry_set(obj, t);
2256 eina_stringshare_del(t);
2261 * This sets the editable attribute of the entry.
2263 * @param obj The entry object
2264 * @param editable If true, the entry will be editable by the user.
2265 * If false, it will be set to the disabled state.
2270 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2272 ELM_CHECK_WIDTYPE(obj, widtype);
2273 Widget_Data *wd = elm_widget_data_get(obj);
2276 if (wd->editable == editable) return;
2277 wd->editable = editable;
2278 t = eina_stringshare_add(elm_entry_entry_get(obj));
2279 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2280 elm_entry_entry_set(obj, t);
2281 eina_stringshare_del(t);
2286 * This gets the editable attribute of the entry.
2287 * See also elm_entry_editable_set().
2289 * @param obj The entry object
2290 * @return If true, the entry is editable by the user.
2291 * If false, it is not editable by the user
2296 elm_entry_editable_get(const Evas_Object *obj)
2298 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2299 Widget_Data *wd = elm_widget_data_get(obj);
2300 if (!wd) return EINA_FALSE;
2301 return wd->editable;
2305 * This drops any existing text selection within the entry.
2307 * @param obj The entry object
2312 elm_entry_select_none(Evas_Object *obj)
2314 ELM_CHECK_WIDTYPE(obj, widtype);
2315 Widget_Data *wd = elm_widget_data_get(obj);
2319 wd->selmode = EINA_FALSE;
2320 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2321 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2323 wd->have_selection = EINA_FALSE;
2324 edje_object_part_text_select_none(wd->ent, "elm.text");
2328 * This selects all text within the entry.
2330 * @param obj The entry object
2335 elm_entry_select_all(Evas_Object *obj)
2337 ELM_CHECK_WIDTYPE(obj, widtype);
2338 Widget_Data *wd = elm_widget_data_get(obj);
2342 wd->selmode = EINA_FALSE;
2343 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2344 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2346 wd->have_selection = EINA_TRUE;
2347 edje_object_part_text_select_all(wd->ent, "elm.text");
2351 * This moves the cursor one place to the right within the entry.
2353 * @param obj The entry object
2354 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2359 elm_entry_cursor_next(Evas_Object *obj)
2361 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2362 Widget_Data *wd = elm_widget_data_get(obj);
2363 if (!wd) return EINA_FALSE;
2364 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2368 * This moves the cursor one place to the left within the entry.
2370 * @param obj The entry object
2371 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2376 elm_entry_cursor_prev(Evas_Object *obj)
2378 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2379 Widget_Data *wd = elm_widget_data_get(obj);
2380 if (!wd) return EINA_FALSE;
2381 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2385 * This moves the cursor one line up within the entry.
2387 * @param obj The entry object
2388 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2393 elm_entry_cursor_up(Evas_Object *obj)
2395 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2396 Widget_Data *wd = elm_widget_data_get(obj);
2397 if (!wd) return EINA_FALSE;
2398 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2402 * This moves the cursor one line down within the entry.
2404 * @param obj The entry object
2405 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2410 elm_entry_cursor_down(Evas_Object *obj)
2412 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2413 Widget_Data *wd = elm_widget_data_get(obj);
2414 if (!wd) return EINA_FALSE;
2415 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2419 * This moves the cursor to the beginning of the entry.
2421 * @param obj The entry object
2426 elm_entry_cursor_begin_set(Evas_Object *obj)
2428 ELM_CHECK_WIDTYPE(obj, widtype);
2429 Widget_Data *wd = elm_widget_data_get(obj);
2431 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2435 * This moves the cursor to the end of the entry.
2437 * @param obj The entry object
2442 elm_entry_cursor_end_set(Evas_Object *obj)
2444 ELM_CHECK_WIDTYPE(obj, widtype);
2445 Widget_Data *wd = elm_widget_data_get(obj);
2447 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2451 * This moves the cursor to the beginning of the current line.
2453 * @param obj The entry object
2458 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2460 ELM_CHECK_WIDTYPE(obj, widtype);
2461 Widget_Data *wd = elm_widget_data_get(obj);
2463 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2467 * This moves the cursor to the end of the current line.
2469 * @param obj The entry object
2474 elm_entry_cursor_line_end_set(Evas_Object *obj)
2476 ELM_CHECK_WIDTYPE(obj, widtype);
2477 Widget_Data *wd = elm_widget_data_get(obj);
2479 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2483 * This begins a selection within the entry as though
2484 * the user were holding down the mouse button to make a selection.
2486 * @param obj The entry object
2491 elm_entry_cursor_selection_begin(Evas_Object *obj)
2493 ELM_CHECK_WIDTYPE(obj, widtype);
2494 Widget_Data *wd = elm_widget_data_get(obj);
2496 edje_object_part_text_select_begin(wd->ent, "elm.text");
2500 * This ends a selection within the entry as though
2501 * the user had just released the mouse button while making a selection.
2503 * @param obj The entry object
2508 elm_entry_cursor_selection_end(Evas_Object *obj)
2510 ELM_CHECK_WIDTYPE(obj, widtype);
2511 Widget_Data *wd = elm_widget_data_get(obj);
2513 edje_object_part_text_select_extend(wd->ent, "elm.text");
2517 * TODO: fill this in
2519 * @param obj The entry object
2520 * @return TODO: fill this in
2525 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2527 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2528 Widget_Data *wd = elm_widget_data_get(obj);
2529 if (!wd) return EINA_FALSE;
2530 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2534 * This returns whether the cursor is visible.
2536 * @param obj The entry object
2537 * @return If true, the cursor is visible.
2542 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2544 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2545 Widget_Data *wd = elm_widget_data_get(obj);
2546 if (!wd) return EINA_FALSE;
2547 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2551 * TODO: fill this in
2553 * @param obj The entry object
2554 * @return TODO: fill this in
2559 elm_entry_cursor_content_get(const Evas_Object *obj)
2561 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2562 Widget_Data *wd = elm_widget_data_get(obj);
2563 if (!wd) return NULL;
2564 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2568 * This executes a "cut" action on the selected text in the entry.
2570 * @param obj The entry object
2575 elm_entry_selection_cut(Evas_Object *obj)
2577 ELM_CHECK_WIDTYPE(obj, widtype);
2578 Widget_Data *wd = elm_widget_data_get(obj);
2580 _cut(obj, NULL, NULL);
2584 * This executes a "copy" action on the selected text in the entry.
2586 * @param obj The entry object
2591 elm_entry_selection_copy(Evas_Object *obj)
2593 ELM_CHECK_WIDTYPE(obj, widtype);
2594 Widget_Data *wd = elm_widget_data_get(obj);
2596 _copy(obj, NULL, NULL);
2600 * This executes a "paste" action in the entry.
2602 * @param obj The entry object
2607 elm_entry_selection_paste(Evas_Object *obj)
2609 ELM_CHECK_WIDTYPE(obj, widtype);
2610 Widget_Data *wd = elm_widget_data_get(obj);
2612 _paste(obj, NULL, NULL);
2616 * This clears and frees the items in a entry's contextual (right click) menu.
2618 * @param obj The entry object
2623 elm_entry_context_menu_clear(Evas_Object *obj)
2625 ELM_CHECK_WIDTYPE(obj, widtype);
2626 Widget_Data *wd = elm_widget_data_get(obj);
2627 Elm_Entry_Context_Menu_Item *it;
2629 EINA_LIST_FREE(wd->items, it)
2631 eina_stringshare_del(it->label);
2632 eina_stringshare_del(it->icon_file);
2633 eina_stringshare_del(it->icon_group);
2639 * This adds an item to the entry's contextual menu.
2641 * @param obj The entry object
2642 * @param label The item's text label
2643 * @param icon_file The item's icon file
2644 * @param icon_type The item's icon type
2645 * @param func The callback to execute when the item is clicked
2646 * @param data The data to associate with the item for related functions
2651 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)
2653 ELM_CHECK_WIDTYPE(obj, widtype);
2654 Widget_Data *wd = elm_widget_data_get(obj);
2655 Elm_Entry_Context_Menu_Item *it;
2657 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2659 wd->items = eina_list_append(wd->items, it);
2661 it->label = eina_stringshare_add(label);
2662 it->icon_file = eina_stringshare_add(icon_file);
2663 it->icon_type = icon_type;
2665 it->data = (void *)data;
2669 * This disables the entry's contextual (right click) menu.
2671 * @param obj The entry object
2672 * @param disabled If true, the menu is disabled
2677 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2679 ELM_CHECK_WIDTYPE(obj, widtype);
2680 Widget_Data *wd = elm_widget_data_get(obj);
2682 if (wd->context_menu == !disabled) return;
2683 wd->context_menu = !disabled;
2687 * This returns whether the entry's contextual (right click) menu is disabled.
2689 * @param obj The entry object
2690 * @return If true, the menu is disabled
2695 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2697 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2698 Widget_Data *wd = elm_widget_data_get(obj);
2699 if (!wd) return EINA_FALSE;
2700 return !wd->context_menu;
2704 * This appends a custom item provider to the list for that entry
2706 * This appends the given callback. The list is walked from beginning to end
2707 * with each function called given the item href string in the text. If the
2708 * function returns an object handle other than NULL (it should create an
2709 * and object to do this), then this object is used to replace that item. If
2710 * not the next provider is called until one provides an item object, or the
2711 * default provider in entry does.
2713 * @param obj The entry object
2714 * @param func The function called to provide the item object
2715 * @param data The data passed to @p func
2720 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2722 ELM_CHECK_WIDTYPE(obj, widtype);
2723 Widget_Data *wd = elm_widget_data_get(obj);
2726 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2730 wd->item_providers = eina_list_append(wd->item_providers, ip);
2734 * This prepends a custom item provider to the list for that entry
2736 * This prepends the given callback. See elm_entry_item_provider_append() for
2739 * @param obj The entry object
2740 * @param func The function called to provide the item object
2741 * @param data The data passed to @p func
2746 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2748 ELM_CHECK_WIDTYPE(obj, widtype);
2749 Widget_Data *wd = elm_widget_data_get(obj);
2752 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2756 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2760 * This removes a custom item provider to the list for that entry
2762 * This removes the given callback. See elm_entry_item_provider_append() for
2765 * @param obj The entry object
2766 * @param func The function called to provide the item object
2767 * @param data The data passed to @p func
2772 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2774 ELM_CHECK_WIDTYPE(obj, widtype);
2775 Widget_Data *wd = elm_widget_data_get(obj);
2777 Elm_Entry_Item_Provider *ip;
2780 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2782 if ((ip->func == func) && (ip->data == data))
2784 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2792 * This converts a markup (HTML-like) string into UTF-8.
2794 * @param s The string (in markup) to be converted
2795 * @return The converted string (in UTF-8)
2800 elm_entry_markup_to_utf8(const char *s)
2802 char *ss = _mkup_to_text(s);
2803 if (!ss) ss = strdup("");
2808 * This converts a UTF-8 string into markup (HTML-like).
2810 * @param s The string (in UTF-8) to be converted
2811 * @return The converted string (in markup)
2816 elm_entry_utf8_to_markup(const char *s)
2818 char *ss = _text_to_mkup(s);
2819 if (!ss) ss = strdup("");
2824 * Get the input method context in the entry widget
2826 * @param obj The entry object
2827 * @return The input method context
2831 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2833 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2834 Widget_Data *wd = elm_widget_data_get(obj);
2835 if (!wd || !wd->ent) return NULL;
2837 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2841 * Set whether entry should enable the return key on soft keyboard automatically
2843 * @param obj The entry object
2844 * @param on If true, entry enables the return key on soft keyboard automatically.
2849 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
2851 ELM_CHECK_WIDTYPE(obj, widtype);
2852 Widget_Data *wd = elm_widget_data_get(obj);
2855 wd->autoreturnkey = on;
2856 _check_enable_returnkey(obj);
2860 * Set whether entry should support auto capitalization
2862 * @param obj The entry object
2863 * @param on If true, entry suports auto capitalization.
2868 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool on)
2870 ELM_CHECK_WIDTYPE(obj, widtype);
2871 Widget_Data *wd = elm_widget_data_get(obj);
2875 wd->autocapitalize = EINA_FALSE;
2877 wd->autocapitalize = on;
2879 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2883 * Set the font size on the entry object
2885 * @param obj The entry object
2886 * @param size font size
2891 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
2893 ELM_CHECK_WIDTYPE(obj, widtype);
2894 Widget_Data *wd = elm_widget_data_get(obj);
2895 Eina_Strbuf *fontbuf = NULL;
2900 t = eina_stringshare_add(elm_entry_entry_get(obj));
2901 fontbuf = eina_strbuf_new();
2902 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
2904 if (fontsize == 0) removeflag = 1; // remove fontsize tag
2906 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
2908 elm_entry_entry_set(obj, t);
2912 eina_strbuf_free(fontbuf);
2913 eina_stringshare_del(t);
2917 * Set the text align on the entry object
2919 * @param obj The entry object
2920 * @param align align mode
2925 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
2927 ELM_CHECK_WIDTYPE(obj, widtype);
2928 Widget_Data *wd = elm_widget_data_get(obj);
2933 t = eina_stringshare_add(elm_entry_entry_get(obj));
2935 if (len <= 0) return;
2937 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
2938 elm_entry_entry_set(obj, t);
2942 eina_stringshare_del(t);
2946 * Set the text color on the entry object
2948 * @param obj The entry object
2949 * @param r Red property background color of The entry object
2950 * @param g Green property background color of The entry object
2951 * @param b Blue property background color of The entry object
2952 * @param a Alpha property background alpha of The entry object
2957 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
2959 ELM_CHECK_WIDTYPE(obj, widtype);
2960 Widget_Data *wd = elm_widget_data_get(obj);
2961 Eina_Strbuf *colorbuf = NULL;
2966 t = eina_stringshare_add(elm_entry_entry_get(obj));
2968 if (len <= 0) return;
2969 colorbuf = eina_strbuf_new();
2970 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
2972 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
2974 elm_entry_entry_set(obj, t);
2978 eina_strbuf_free(colorbuf);
2979 eina_stringshare_del(t);
2984 * Set background color of the entry
2986 * @param obj The entry object
2987 * @param r Red property background color of The entry object
2988 * @param g Green property background color of The entry object
2989 * @param b Blue property background color of The entry object
2990 * @param a Alpha property background alpha of The entry object
2994 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
2996 ELM_CHECK_WIDTYPE(obj, widtype);
2997 Widget_Data *wd = elm_widget_data_get(obj);
2998 evas_object_color_set(wd->bg, r, g, b, a);
3000 if (wd->bgcolor == EINA_FALSE)
3003 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3008 * Set the ellipsis behavior of the entry
3010 * @param obj The entry object
3011 * @param ellipsis To ellipsis text or not
3015 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3017 ELM_CHECK_WIDTYPE(obj, widtype);
3018 Widget_Data *wd = elm_widget_data_get(obj);
3019 if (wd->ellipsis == ellipsis) return;
3020 wd->ellipsis = ellipsis;
3026 * This sets the attribute to show the input panel automatically.
3028 * @param obj The entry object
3029 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3034 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3036 ELM_CHECK_WIDTYPE(obj, widtype);
3037 Widget_Data *wd = elm_widget_data_get(obj);
3040 wd->input_panel_enable = enabled;
3041 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3045 * Set the input panel layout of the entry
3047 * @param obj The entry object
3048 * @param layout the layout to set
3053 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3055 ELM_CHECK_WIDTYPE(obj, widtype);
3056 Widget_Data *wd = elm_widget_data_get(obj);
3059 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3062 wd->input_panel_layout = layout;
3064 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);