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 drag_selection_asked : 1;
135 Eina_Bool bgcolor : 1;
136 Eina_Bool ellipsis : 1;
137 Eina_Bool autoreturnkey : 1;
138 Eina_Bool input_panel_enable : 1;
139 Eina_Bool autocapitalize : 1;
140 Elm_Input_Panel_Layout input_panel_layout;
141 Eina_Bool autoperiod : 1;
144 struct _Elm_Entry_Item_Provider
146 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
150 static const char *widtype = NULL;
152 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Drop_Data *);
153 static void _del_hook(Evas_Object *obj);
154 static void _theme_hook(Evas_Object *obj);
155 static void _disable_hook(Evas_Object *obj);
156 static void _sizing_eval(Evas_Object *obj);
157 static void _on_focus_hook(void *data, Evas_Object *obj);
158 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
159 static const char *_getbase(Evas_Object *obj);
160 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
161 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
162 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
163 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
164 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
165 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
166 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
167 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
168 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
169 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
170 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
171 static int _is_width_over(Evas_Object *obj);
172 static void _ellipsis_entry_to_width(Evas_Object *obj);
173 static void _reverse_ellipsis_entry(Evas_Object *obj);
174 static int _textinput_control_function(void *data,void *input_data);
175 static int _entry_length_get(Evas_Object *obj);
177 static const char SIG_CHANGED[] = "changed";
178 static const char SIG_ACTIVATED[] = "activated";
179 static const char SIG_PRESS[] = "press";
180 static const char SIG_LONGPRESSED[] = "longpressed";
181 static const char SIG_CLICKED[] = "clicked";
182 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
183 static const char SIG_FOCUSED[] = "focused";
184 static const char SIG_UNFOCUSED[] = "unfocused";
185 static const char SIG_SELECTION_PASTE[] = "selection,paste";
186 static const char SIG_SELECTION_COPY[] = "selection,copy";
187 static const char SIG_SELECTION_CUT[] = "selection,cut";
188 static const char SIG_SELECTION_START[] = "selection,start";
189 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
190 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
191 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
192 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
193 #ifdef HAVE_CONFORMANT_AUTOSCROLL
194 static const char SIG_IMPREGION_CHANGED[] = "impregion,changed";
196 static const Evas_Smart_Cb_Description _signals[] = {
200 {SIG_LONGPRESSED, ""},
202 {SIG_CLICKED_DOUBLE, ""},
205 {SIG_SELECTION_PASTE, ""},
206 {SIG_SELECTION_COPY, ""},
207 {SIG_SELECTION_CUT, ""},
208 {SIG_SELECTION_START, ""},
209 {SIG_SELECTION_CHANGED, ""},
210 {SIG_SELECTION_CLEARED, ""},
211 {SIG_CURSOR_CHANGED, ""},
212 {SIG_ANCHOR_CLICKED, ""},
216 static Eina_List *entries = NULL;
220 void (*obj_hook) (Evas_Object *obj);
221 void (*obj_unhook) (Evas_Object *obj);
222 void (*obj_longpress) (Evas_Object *obj);
223 void (*obj_mouseup) (Evas_Object *obj);
227 _module(Evas_Object *obj __UNUSED__)
229 static Elm_Module *m = NULL;
230 if (m) goto ok; // already found - just use
231 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
233 m->api = malloc(sizeof(Mod_Api));
234 if (!m->api) return NULL;
235 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
236 _elm_module_symbol_get(m, "obj_hook");
237 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
238 _elm_module_symbol_get(m, "obj_unhook");
239 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
240 _elm_module_symbol_get(m, "obj_longpress");
241 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
242 _elm_module_symbol_get(m, "obj_mouseup");
243 ok: // ok - return api
248 _del_hook(Evas_Object *obj)
250 Widget_Data *wd = elm_widget_data_get(obj);
251 Elm_Entry_Context_Menu_Item *it;
252 Elm_Entry_Item_Provider *ip;
254 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
255 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
257 entries = eina_list_remove(entries, obj);
258 #ifdef HAVE_ELEMENTARY_X
259 ecore_event_handler_del(wd->sel_notify_handler);
260 ecore_event_handler_del(wd->sel_clear_handler);
262 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
263 if (wd->text) eina_stringshare_del(wd->text);
264 if (wd->bg) evas_object_del(wd->bg);
265 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
266 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
267 EINA_LIST_FREE(wd->items, it)
269 eina_stringshare_del(it->label);
270 eina_stringshare_del(it->icon_file);
271 eina_stringshare_del(it->icon_group);
274 EINA_LIST_FREE(wd->item_providers, ip)
282 _theme_hook(Evas_Object *obj)
284 Widget_Data *wd = elm_widget_data_get(obj);
286 Ecore_IMF_Context *ic;
288 t = eina_stringshare_add(elm_entry_entry_get(obj));
289 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
290 elm_entry_entry_set(obj, t);
291 eina_stringshare_del(t);
292 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
293 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
294 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
295 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
297 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
300 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
307 _disable_hook(Evas_Object *obj)
309 Widget_Data *wd = elm_widget_data_get(obj);
311 if (elm_widget_disabled_get(obj))
313 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
314 wd->disabled = EINA_TRUE;
318 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
319 wd->disabled = EINA_FALSE;
324 _elm_win_recalc_job(void *data)
326 Widget_Data *wd = elm_widget_data_get(data);
327 Evas_Coord minw = -1, minh = -1, maxh = -1;
328 Evas_Coord resw, resh, minminw;
330 wd->deferred_recalc_job = NULL;
331 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
334 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
335 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
337 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
338 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
339 evas_object_size_hint_min_set(data, minminw, minh);
340 if (wd->single_line) maxh = minh;
341 evas_object_size_hint_max_set(data, -1, maxh);
342 if (wd->deferred_cur)
343 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
347 _sizing_eval(Evas_Object *obj)
349 Widget_Data *wd = elm_widget_data_get(obj);
350 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
351 Evas_Coord resw, resh;
353 if (wd->linewrap || wd->char_linewrap)
355 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
356 if ((resw == wd->lastw) && (!wd->changed)) return;
357 wd->changed = EINA_FALSE;
359 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
360 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
364 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
365 edje_object_size_min_calc(wd->ent, &minw, &minh);
366 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
367 evas_object_size_hint_min_set(obj, minw, minh);
368 if (wd->single_line) maxh = minh;
369 evas_object_size_hint_max_set(obj, maxw, maxh);
371 if (wd->ellipsis && wd->single_line)
373 if (_is_width_over(obj))
374 _ellipsis_entry_to_width(obj);
375 else if (wd->ellipsis_threshold > 1 && _entry_length_get(obj) < wd->ellipsis_threshold)
376 _reverse_ellipsis_entry(obj);
382 _check_enable_returnkey(Evas_Object *obj)
384 Widget_Data *wd = elm_widget_data_get(obj);
387 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
390 if (!wd->autoreturnkey) return;
392 if (_entry_length_get(obj) == 0)
394 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
398 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
402 #ifdef HAVE_CONFORMANT_AUTOSCROLL
404 _imp_region_get_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
406 Evas_Coord cx = 0, cy = 0, cw = 0, ch = 0;
407 Widget_Data *wd = elm_widget_data_get(obj);
408 if (!wd) return NULL;
409 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
420 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
422 Widget_Data *wd = elm_widget_data_get(obj);
423 Evas_Object *top = elm_widget_top_get(obj);
425 if (!wd->editable) return;
426 if (elm_widget_focus_get(obj))
428 evas_object_focus_set(wd->ent, 1);
429 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
431 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
435 // ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
438 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
439 _check_enable_returnkey(obj);
443 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
444 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", "");
445 evas_object_focus_set(wd->ent, 0);
446 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
447 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
452 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
454 Widget_Data *wd = elm_widget_data_get(obj);
456 edje_object_signal_emit(wd->ent, emission, source);
460 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
462 Widget_Data *wd = elm_widget_data_get(obj);
464 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
468 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source))
470 Widget_Data *wd = elm_widget_data_get(obj);
471 if (!wd) return NULL;
472 return edje_object_signal_callback_del(wd->ent, emission, source, func_cb);
476 _hoversel_position(Evas_Object *obj)
478 Widget_Data *wd = elm_widget_data_get(obj);
479 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
481 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
482 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
484 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
495 evas_object_move(wd->hoversel, x + cx, y + cy);
496 evas_object_resize(wd->hoversel, cw, ch);
500 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
502 Widget_Data *wd = elm_widget_data_get(data);
504 if (wd->hoversel) _hoversel_position(data);
508 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
510 Widget_Data *wd = elm_widget_data_get(data);
512 if (wd->linewrap || wd->char_linewrap)
516 if (wd->hoversel) _hoversel_position(data);
517 // Evas_Coord ww, hh;
518 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
522 _hover_del(void *data)
524 Widget_Data *wd = elm_widget_data_get(data);
529 evas_object_del(wd->hoversel);
532 wd->hovdeljob = NULL;
536 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
538 Widget_Data *wd = elm_widget_data_get(data);
540 if (wd->hoversel) evas_object_hide(wd->hoversel);
544 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
546 elm_widget_scroll_freeze_pop(data);
547 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
548 wd->hovdeljob = ecore_job_add(_hover_del, data);
552 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
554 Widget_Data *wd = elm_widget_data_get(data);
556 wd->selmode = EINA_TRUE;
557 edje_object_part_text_select_none(wd->ent, "elm.text");
559 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
560 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
561 elm_widget_scroll_hold_push(data);
565 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
567 Widget_Data *wd = elm_widget_data_get(data);
569 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
570 if (wd->sel_notify_handler)
572 #ifdef HAVE_ELEMENTARY_X
573 wd->selection_asked = EINA_TRUE;
574 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data);
580 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
582 Widget_Data *wd = elm_widget_data_get(obj);
586 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
587 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
588 if (seltype == ELM_SEL_CLIPBOARD)
589 eina_stringshare_replace(&wd->cut_sel, sel);
593 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
595 Widget_Data *wd = elm_widget_data_get(data);
598 wd->selmode = EINA_FALSE;
599 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
600 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
601 elm_widget_scroll_hold_pop(data);
602 _store_selection(ELM_SEL_CLIPBOARD, data);
603 edje_object_part_text_insert(wd->ent, "elm.text", "");
604 edje_object_part_text_select_none(wd->ent, "elm.text");
608 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
610 Widget_Data *wd = elm_widget_data_get(data);
612 wd->selmode = EINA_FALSE;
613 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
614 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
615 elm_widget_scroll_hold_pop(data);
616 _store_selection(ELM_SEL_CLIPBOARD, data);
617 // edje_object_part_text_select_none(wd->ent, "elm.text");
621 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
623 Widget_Data *wd = elm_widget_data_get(data);
625 wd->selmode = EINA_FALSE;
626 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
627 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
628 elm_widget_scroll_hold_pop(data);
629 edje_object_part_text_select_none(wd->ent, "elm.text");
633 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
635 Widget_Data *wd = elm_widget_data_get(data);
639 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
640 elm_cbhm_helper_init(obj);
641 elm_cbhm_send_raw_data("show");
646 _item_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
648 Elm_Entry_Context_Menu_Item *it = data;
649 Evas_Object *obj2 = it->obj;
651 if (it->func) it->func(it->data, obj2, NULL);
655 _long_press(void *data)
657 Widget_Data *wd = elm_widget_data_get(data);
660 const Elm_Entry_Context_Menu_Item *it;
661 if (!wd) return ECORE_CALLBACK_CANCEL;
662 if ((wd->api) && (wd->api->obj_longpress))
664 wd->api->obj_longpress(data);
666 else if (wd->context_menu)
668 const char *context_menu_orientation;
670 if (wd->hoversel) evas_object_del(wd->hoversel);
671 else elm_widget_scroll_freeze_push(data);
672 wd->hoversel = elm_hoversel_add(data);
673 context_menu_orientation = edje_object_data_get
674 (wd->ent, "context_menu_orientation");
675 if ((context_menu_orientation) &&
676 (!strcmp(context_menu_orientation, "horizontal")))
677 elm_hoversel_horizontal_set(wd->hoversel, 1);
678 elm_object_style_set(wd->hoversel, "entry");
679 elm_widget_sub_object_add(data, wd->hoversel);
680 elm_hoversel_label_set(wd->hoversel, "Text");
681 top = elm_widget_top_get(data);
682 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
683 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
687 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
689 if (1) // need way to detect if someone has a selection
692 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
697 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
698 _clipboard_menu, data);
705 if (wd->have_selection)
707 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
710 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
713 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
716 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
717 _clipboard_menu, data);
721 EINA_LIST_FOREACH(wd->items, l, it)
723 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
724 it->icon_type, _item_clicked, it);
728 _hoversel_position(data);
729 evas_object_show(wd->hoversel);
730 elm_hoversel_hover_begin(wd->hoversel);
732 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
733 edje_object_part_text_select_abort(wd->ent, "elm.text");
735 wd->longpress_timer = NULL;
736 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
737 return ECORE_CALLBACK_CANCEL;
741 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
743 Widget_Data *wd = elm_widget_data_get(data);
744 Evas_Event_Mouse_Down *ev = event_info;
746 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
747 if (ev->button != 1) return;
748 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
749 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
750 wd->longpress_timer = ecore_timer_add(1.0, _long_press, data);
751 wd->downx = ev->canvas.x;
752 wd->downy = ev->canvas.y;
756 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
758 Widget_Data *wd = elm_widget_data_get(data);
759 Evas_Event_Mouse_Up *ev = event_info;
761 if (ev->button != 1) return;
762 if ((wd->api) && (wd->api->obj_mouseup))
764 wd->api->obj_mouseup(data);
766 if (wd->longpress_timer)
768 ecore_timer_del(wd->longpress_timer);
769 wd->longpress_timer = NULL;
774 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
776 Widget_Data *wd = elm_widget_data_get(data);
777 Evas_Event_Mouse_Move *ev = event_info;
781 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
783 if (wd->longpress_timer)
785 ecore_timer_del(wd->longpress_timer);
786 wd->longpress_timer = NULL;
789 else if (wd->longpress_timer)
793 dx = wd->downx - ev->cur.canvas.x;
795 dy = wd->downy - ev->cur.canvas.y;
798 ((_elm_config->finger_size / 2) *
799 (_elm_config->finger_size / 2)))
801 ecore_timer_del(wd->longpress_timer);
802 wd->longpress_timer = NULL;
806 else if (wd->longpress_timer)
810 dx = wd->downx - ev->cur.canvas.x;
812 dy = wd->downy - ev->cur.canvas.y;
815 ((_elm_config->finger_size / 2) *
816 (_elm_config->finger_size / 2)))
818 ecore_timer_del(wd->longpress_timer);
819 wd->longpress_timer = NULL;
825 _getbase(Evas_Object *obj)
827 Widget_Data *wd = elm_widget_data_get(obj);
828 if (!wd) return "base";
831 if((wd->password)&&(wd->show_last_character)) return "custom-password";
832 else if(wd->password) return "base-password";
835 if (wd->single_line) return "base-single";
838 if (wd->linewrap) return "base";
839 else if (wd->char_linewrap) return "base-charwrap";
840 else return "base-nowrap";
846 if((wd->password)&&(wd->show_last_character)) return "custom-password";
847 else if(wd->password) return "base-password";
850 if (wd->single_line) return "base-single-noedit";
853 if (wd->linewrap) return "base-noedit";
854 else if (wd->char_linewrap) return "base-noedit-charwrap";
855 else return "base-nowrap-noedit";
863 _str_append(char *str, const char *txt, int *len, int *alloc)
865 int txt_len = strlen(txt);
867 if (txt_len <= 0) return str;
868 if ((*len + txt_len) >= *alloc)
873 alloc2 = *alloc + txt_len + 128;
874 str2 = realloc(str, alloc2);
875 if (!str2) return str;
879 strcpy(str + *len, txt);
884 /*FIXME: Sholud be implemented somewhere else, it really depends on the context
885 * because some markups can be implemented otherwise according to style.
886 * probably doing it in textblock and making it translate according to it's
887 * style is correct. */
889 _strncpy(char* dest, const char* src, size_t count)
893 ERR( "dest is NULL" );
898 ERR( "src is NULL" );
903 ERR( "count is smaller than 0" );
907 return strncpy( dest, src, count );
911 _mkup_to_text(const char *mkup)
914 int str_len = 0, str_alloc = 0;
916 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
918 if (!mkup) return NULL;
920 tag_start = tag_end = esc_start = esc_end = NULL;
925 if (((p!=NULL)&&(*p == 0)) ||
926 (tag_end) || (esc_end) ||
927 (tag_start) || (esc_start))
933 ttag = malloc(tag_end - tag_start);
936 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
937 ttag[tag_end - tag_start - 1] = 0;
938 if (!strcmp(ttag, "br"))
939 str = _str_append(str, "\n", &str_len, &str_alloc);
940 else if (!strcmp(ttag, "\n"))
941 str = _str_append(str, "\n", &str_len, &str_alloc);
942 else if (!strcmp(ttag, "\\n"))
943 str = _str_append(str, "\n", &str_len, &str_alloc);
944 else if (!strcmp(ttag, "\t"))
945 str = _str_append(str, "\t", &str_len, &str_alloc);
946 else if (!strcmp(ttag, "\\t"))
947 str = _str_append(str, "\t", &str_len, &str_alloc);
948 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
949 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
952 tag_start = tag_end = NULL;
956 ts = malloc(esc_end - esc_start + 1);
960 _strncpy(ts, esc_start, esc_end - esc_start);
961 ts[esc_end - esc_start] = 0;
962 esc = evas_textblock_escape_string_get(ts);
964 str = _str_append(str, esc, &str_len, &str_alloc);
967 esc_start = esc_end = NULL;
969 else if ((p!=NULL)&&(*p == 0))
971 ts = malloc(p - s + 1);
974 _strncpy(ts, s, p - s);
976 str = _str_append(str, ts, &str_len, &str_alloc);
982 if ((p!=NULL)&&(*p == '<'))
988 ts = malloc(p - s + 1);
991 _strncpy(ts, s, p - s);
993 str = _str_append(str, ts, &str_len, &str_alloc);
999 else if ((p!=NULL)&&(*p == '>'))
1007 else if ((p!=NULL)&&(*p == '&'))
1013 ts = malloc(p - s + 1);
1016 _strncpy(ts, s, p - s);
1018 str = _str_append(str, ts, &str_len, &str_alloc);
1024 else if ((p!=NULL)&&(*p == ';'))
1038 _entry_length_get(Evas_Object *obj)
1041 const char *str = elm_entry_entry_get(obj);
1044 char *plain_str = _mkup_to_text(str);
1045 if (!plain_str) return 0;
1047 len = strlen(plain_str);
1054 _text_to_mkup(const char *text)
1057 int str_len = 0, str_alloc = 0;
1058 int ch, pos = 0, pos2 = 0;
1060 if (!text) return NULL;
1064 pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
1065 if ((ch <= 0) || (pos2 <= 0)) break;
1067 str = _str_append(str, "<br>", &str_len, &str_alloc);
1068 else if (ch == '\t')
1069 str = _str_append(str, "<\t>", &str_len, &str_alloc);
1071 str = _str_append(str, "<", &str_len, &str_alloc);
1073 str = _str_append(str, ">", &str_len, &str_alloc);
1075 str = _str_append(str, "&", &str_len, &str_alloc);
1080 _strncpy(tstr, text + pos, pos2 - pos);
1081 tstr[pos2 - pos] = 0;
1082 str = _str_append(str, tstr, &str_len, &str_alloc);
1089 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1091 Widget_Data *wd = elm_widget_data_get(data);
1093 wd->changed = EINA_TRUE;
1095 if (wd->text) eina_stringshare_del(wd->text);
1097 _check_enable_returnkey(data);
1098 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1102 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1104 Widget_Data *wd = elm_widget_data_get(data);
1108 EINA_LIST_FOREACH(entries, l, entry)
1110 if (entry != data) elm_entry_select_none(entry);
1112 wd->have_selection = EINA_TRUE;
1113 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1114 #ifdef HAVE_ELEMENTARY_X
1115 if (wd->sel_notify_handler)
1117 const char *txt = elm_entry_selection_get(data);
1120 top = elm_widget_top_get(data);
1121 if ((top) && (elm_win_xwindow_get(top)))
1122 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1128 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1130 Widget_Data *wd = elm_widget_data_get(data);
1132 wd->have_selection = EINA_TRUE;
1133 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1134 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1135 elm_entry_selection_get(data));
1139 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1141 Widget_Data *wd = elm_widget_data_get(data);
1143 if (!wd->have_selection) return;
1144 wd->have_selection = EINA_FALSE;
1145 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1146 if (wd->sel_notify_handler)
1150 #ifdef HAVE_ELEMENTARY_X
1153 top = elm_widget_top_get(data);
1154 if ((top) && (elm_win_xwindow_get(top)))
1155 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1158 eina_stringshare_del(wd->cut_sel);
1163 #ifdef HAVE_ELEMENTARY_X
1166 top = elm_widget_top_get(data);
1167 if ((top) && (elm_win_xwindow_get(top)))
1168 elm_selection_clear(ELM_SEL_PRIMARY, data);
1175 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1177 Widget_Data *wd = elm_widget_data_get(data);
1179 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1180 if (wd->sel_notify_handler)
1182 #ifdef HAVE_ELEMENTARY_X
1185 top = elm_widget_top_get(data);
1186 if ((top) && (elm_win_xwindow_get(top)))
1188 wd->selection_asked = EINA_TRUE;
1189 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data);
1196 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1198 Widget_Data *wd = elm_widget_data_get(data);
1200 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1201 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1202 elm_entry_selection_get(data));
1206 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1208 Widget_Data *wd = elm_widget_data_get(data);
1210 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1211 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1212 elm_entry_selection_get(data));
1213 edje_object_part_text_insert(wd->ent, "elm.text", "");
1214 wd->changed = EINA_TRUE;
1219 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1221 Widget_Data *wd = elm_widget_data_get(data);
1222 Evas_Coord cx, cy, cw, ch;
1224 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1225 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1226 &cx, &cy, &cw, &ch);
1227 if (!wd->deferred_recalc_job)
1228 elm_widget_show_region_set(data, cx, cy, cw, ch);
1231 wd->deferred_cur = EINA_TRUE;
1237 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1238 evas_object_smart_callback_call(data, SIG_IMPREGION_CHANGED, NULL);
1243 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1245 Widget_Data *wd = elm_widget_data_get(data);
1250 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1252 Widget_Data *wd = elm_widget_data_get(data);
1253 Elm_Entry_Anchor_Info ei;
1254 char *buf2, *p, *p2, *n;
1256 p = strrchr(emission, ',');
1259 const Eina_List *geoms;
1263 while (p2 >= emission)
1265 if (*p2 == ',') break;
1269 buf2 = alloca(5 + p - p2);
1270 strncpy(buf2, p2, p - p2);
1273 ei.button = atoi(buf2);
1274 ei.x = ei.y = ei.w = ei.h = 0;
1276 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1279 Evas_Textblock_Rectangle *r;
1281 Evas_Coord px, py, x, y;
1283 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1284 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1285 EINA_LIST_FOREACH(geoms, l, r)
1287 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1288 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1299 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1304 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1306 Widget_Data *wd = elm_widget_data_get(data);
1311 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1313 Widget_Data *wd = elm_widget_data_get(data);
1318 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1320 Widget_Data *wd = elm_widget_data_get(data);
1325 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1327 Widget_Data *wd = elm_widget_data_get(data);
1329 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1333 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1335 Widget_Data *wd = elm_widget_data_get(data);
1337 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1341 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1343 Widget_Data *wd = elm_widget_data_get(data);
1345 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1349 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1351 Widget_Data *wd = elm_widget_data_get(data);
1353 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1356 #ifdef HAVE_ELEMENTARY_X
1358 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1360 Widget_Data *wd = elm_widget_data_get(data);
1361 Ecore_X_Event_Selection_Notify *ev = event;
1362 if (!wd) return ECORE_CALLBACK_PASS_ON;
1363 if (!wd->selection_asked && !wd->drag_selection_asked)
1364 return ECORE_CALLBACK_PASS_ON;
1366 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1367 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1369 Ecore_X_Selection_Data_Text *text_data;
1371 text_data = ev->data;
1372 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1374 if (text_data->text)
1376 char *txt = _text_to_mkup(text_data->text);
1380 elm_entry_entry_insert(data, txt);
1385 wd->selection_asked = EINA_FALSE;
1387 else if (ev->selection == ECORE_X_SELECTION_XDND)
1389 Ecore_X_Selection_Data_Text *text_data;
1391 text_data = ev->data;
1392 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1394 if (text_data->text)
1396 char *txt = _text_to_mkup(text_data->text);
1400 /* Massive FIXME: this should be at the drag point */
1401 elm_entry_entry_insert(data, txt);
1406 wd->drag_selection_asked = EINA_FALSE;
1408 ecore_x_dnd_send_finished();
1411 return ECORE_CALLBACK_PASS_ON;
1415 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1418 Widget_Data *wd = elm_widget_data_get(data);
1419 Ecore_X_Event_Selection_Clear *ev = event;
1421 if (!wd->have_selection) return 1;
1422 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1423 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1425 elm_entry_select_none(data);
1430 Evas_Object *top = elm_widget_top_get(data);
1431 Ecore_X_Event_Selection_Clear *ev = event;
1434 return ECORE_CALLBACK_PASS_ON;
1436 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1438 return ECORE_CALLBACK_PASS_ON;
1441 elm_selection_get(1/*ELM_SEL_SECONDARY*/,0x1/*ELM_SEL_FORMAT_TEXT*/,data);
1443 return ECORE_CALLBACK_PASS_ON;
1448 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Drop_Data *drop)
1453 wd = elm_widget_data_get(obj);
1455 if (!wd) return EINA_FALSE;
1456 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1458 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1459 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1460 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1461 EDJE_CURSOR_MAIN,drop->x,drop->y);
1462 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1463 elm_entry_entry_insert(obj, drop->data);
1464 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1465 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1471 static Evas_Object *
1472 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1474 Widget_Data *wd = elm_widget_data_get(data);
1477 Elm_Entry_Item_Provider *ip;
1480 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1482 o = ip->func(ip->data, data, item);
1485 o = edje_object_add(evas_object_evas_get(data));
1486 if (!strncmp(item, "emoticon/", 9))
1487 ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1489 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1494 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1496 char *curlocater, *starttag, *endtag;
1497 int firstindex = 0, foundflag = -1;
1499 curlocater = strstr(oldstring, key);
1502 starttag = curlocater;
1503 endtag = curlocater + strlen(key);
1504 if (endtag == NULL || *endtag != '=')
1510 firstindex = abs(oldstring - curlocater);
1511 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1512 *value = (char*)oldstring + firstindex;
1514 while (oldstring != starttag)
1516 if (*starttag == '>')
1521 if (*starttag == '<')
1525 if (starttag == NULL) break;
1528 while (NULL != endtag)
1539 if (endtag == NULL) break;
1542 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1552 if (foundflag == 1) return 0;
1558 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1560 const char *srcstring = NULL;
1561 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1562 char *curlocater, *replocater;
1563 char *starttag, *endtag;
1564 int tagtxtlen = 0, insertflag = 0;
1566 srcstring = eina_strbuf_string_get(srcbuf);
1567 curlocater = strstr(srcstring, key);
1569 if (curlocater == NULL)
1577 starttag = strchr(srcstring, '<');
1578 endtag = strchr(srcstring, '>');
1579 tagtxtlen = endtag - starttag;
1580 if (tagtxtlen <= 0) tagtxtlen = 0;
1581 if (starttag < curlocater && curlocater < endtag) break;
1582 if (endtag != NULL && endtag+1 != NULL)
1583 srcstring = endtag+1;
1586 } while (strlen(srcstring) > 1);
1588 if (starttag && endtag && tagtxtlen > strlen(key))
1590 repbuf = eina_strbuf_new();
1591 diffbuf = eina_strbuf_new();
1592 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1593 srcstring = eina_strbuf_string_get(repbuf);
1594 curlocater = strstr(srcstring, key);
1596 if (curlocater != NULL)
1598 replocater = curlocater + strlen(key) + 1;
1600 while (*replocater == ' ' || *replocater == '=')
1605 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1608 if (replocater-curlocater > strlen(key)+1)
1611 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1620 eina_strbuf_reset(repbuf);
1628 if (repbuf == NULL) repbuf = eina_strbuf_new();
1629 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1633 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1634 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1640 eina_strbuf_prepend(diffbuf, "<");
1641 eina_strbuf_append(diffbuf, ">");
1642 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1646 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1647 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1651 if (repbuf) eina_strbuf_free(repbuf);
1652 if (diffbuf) eina_strbuf_free(diffbuf);
1658 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1660 Eina_Strbuf *sharebuf = NULL;
1662 sharebuf = eina_strbuf_new();
1663 eina_strbuf_append(sharebuf, *srcstring);
1664 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1665 eina_stringshare_del(*srcstring);
1666 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1667 eina_strbuf_free(sharebuf);
1673 _is_width_over(Evas_Object *obj)
1675 Evas_Coord x, y, w, h;
1676 Evas_Coord vx, vy, vw, vh;
1677 Widget_Data *wd = elm_widget_data_get(obj);
1681 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1683 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1685 if (x >= 0 && y >= 0)
1688 if (4 < wd->wrap_w && w > wd->wrap_w)
1695 _reverse_ellipsis_entry(Evas_Object *obj)
1697 Widget_Data *wd = elm_widget_data_get(obj);
1698 int cur_fontsize = 0;
1699 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1700 char **kvalue = NULL;
1701 const char *minfont, *deffont, *maxfont;
1702 const char *ellipsis_string = "...";
1703 int minfontsize, maxfontsize, minshowcount;
1705 minshowcount = strlen(ellipsis_string) + 1;
1706 minfont = edje_object_data_get(wd->ent, "min_font_size");
1707 if (minfont) minfontsize = atoi(minfont);
1708 else minfontsize = 1;
1709 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1710 if (maxfont) maxfontsize = atoi(maxfont);
1711 else maxfontsize = 1;
1712 deffont = edje_object_data_get(wd->ent, "default_font_size");
1713 if (deffont) cur_fontsize = atoi(deffont);
1714 else cur_fontsize = 1;
1715 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1716 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1718 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1720 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1723 txtbuf = eina_strbuf_new();
1724 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1726 if (cur_fontsize >= atoi(deffont))
1728 if (txtbuf) eina_strbuf_free(txtbuf);
1732 if (_is_width_over(obj) != 1)
1734 int rev_fontsize = cur_fontsize;
1738 if (rev_fontsize > atoi(deffont))
1741 if (fontbuf != NULL)
1743 eina_strbuf_free(fontbuf);
1746 fontbuf = eina_strbuf_new();
1747 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1748 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1749 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1751 eina_strbuf_free(fontbuf);
1753 } while (_is_width_over(obj) != 1);
1755 while (_is_width_over(obj))
1758 if (rev_fontsize < atoi(deffont))
1761 if (fontbuf != NULL)
1763 eina_strbuf_free(fontbuf);
1766 fontbuf = eina_strbuf_new();
1767 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1768 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1769 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1770 eina_strbuf_free(fontbuf);
1775 if (txtbuf) eina_strbuf_free(txtbuf);
1781 _ellipsis_entry_to_width(Evas_Object *obj)
1783 Widget_Data *wd = elm_widget_data_get(obj);
1784 int cur_fontsize = 0, len, jumpcount;
1785 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1786 char **kvalue = NULL;
1787 const char *minfont, *deffont, *maxfont;
1788 const char *ellipsis_string = "...";
1789 int minfontsize, maxfontsize, minshowcount;
1790 int i, tagend, cur_len;
1793 minshowcount = strlen(ellipsis_string) + 1;
1794 minfont = edje_object_data_get(wd->ent, "min_font_size");
1795 if (minfont) minfontsize = atoi(minfont);
1796 else minfontsize = 1;
1797 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1798 if (maxfont) maxfontsize = atoi(maxfont);
1799 else maxfontsize = 1;
1800 deffont = edje_object_data_get(wd->ent, "default_font_size");
1801 if (deffont) cur_fontsize = atoi(deffont);
1802 else cur_fontsize = 1;
1803 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1804 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1806 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1808 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1811 txtbuf = eina_strbuf_new();
1812 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1814 while (_is_width_over(obj))
1816 if (wd->ellipsis_threshold == 0)
1817 wd->ellipsis_threshold = _entry_length_get(obj);
1818 if (cur_fontsize > minfontsize)
1821 if (fontbuf != NULL)
1823 eina_strbuf_free(fontbuf);
1826 fontbuf = eina_strbuf_new();
1827 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1828 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1829 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1830 eina_strbuf_free(fontbuf);
1832 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1836 len = _entry_length_get(obj);
1837 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1838 cur_len = strlen(cur_str);
1840 for (i = 0; i < len; i++)
1842 if(cur_str[i] == '>' && cur_str[i+1] != NULL &&
1843 cur_str[i+1] != '<')
1850 while (jumpcount < len-strlen(ellipsis_string))
1852 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1856 eina_strbuf_free(txtbuf);
1859 txtbuf = eina_strbuf_new();
1860 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1861 eina_strbuf_append(txtbuf, ellipsis_string);
1862 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1863 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1864 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1866 if (_is_width_over(obj))
1874 if (txtbuf) eina_strbuf_free(txtbuf);
1879 static int _textinput_control_function(void *data,void *input_data)
1881 /*calculate character count*/
1882 Evas_Object *entry = (Evas_Object *)data;
1883 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1886 size_t insert_text_len=0;
1887 char *text = edje_object_part_text_get(wd->ent, "elm.text");
1889 size_t remain_bytes;
1892 byte_len = strlen(text);/*no of bytes*/
1893 remain_bytes = wd->max_no_of_bytes-byte_len;
1894 sprintf(buf,"%d",remain_bytes);
1895 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1898 insert_text = (char *)input_data;
1899 insert_text_len = strlen(insert_text);
1900 if(remain_bytes<insert_text_len)
1902 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1905 if(byte_len>=wd->max_no_of_bytes)
1907 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1916 * This adds an entry to @p parent object.
1918 * @param parent The parent object
1919 * @return The new object or NULL if it cannot be created
1924 elm_entry_add(Evas_Object *parent)
1926 Evas_Object *obj, *top;
1930 wd = ELM_NEW(Widget_Data);
1931 e = evas_object_evas_get(parent);
1932 wd->bgcolor = EINA_FALSE;
1933 wd->bg = evas_object_rectangle_add(e);
1934 evas_object_color_set(wd->bg, 0, 0, 0, 0);
1935 obj = elm_widget_add(e);
1936 ELM_SET_WIDTYPE(widtype, "entry");
1937 elm_widget_type_set(obj, "entry");
1938 elm_widget_sub_object_add(parent, obj);
1939 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1940 elm_widget_data_set(obj, wd);
1941 elm_widget_del_hook_set(obj, _del_hook);
1942 elm_widget_theme_hook_set(obj, _theme_hook);
1943 elm_widget_disable_hook_set(obj, _disable_hook);
1944 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1945 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1946 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1947 elm_widget_can_focus_set(obj, 1);
1948 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1949 elm_widget_imp_region_get_hook_set(obj, _imp_region_get_hook, NULL);
1952 wd->linewrap = EINA_TRUE;
1953 wd->ellipsis = EINA_FALSE;
1954 wd->char_linewrap= EINA_FALSE;
1955 wd->editable = EINA_TRUE;
1956 wd->disabled = EINA_FALSE;
1957 wd->context_menu = EINA_TRUE;
1959 wd->ellipsis_threshold = 0;
1961 wd->ent = edje_object_add(e);
1962 edje_object_item_provider_set(wd->ent, _get_item, obj);
1963 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1964 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1965 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1967 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1969 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1972 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1973 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1974 _signal_entry_changed, obj);
1975 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1976 _signal_selection_start, obj);
1977 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1978 _signal_selection_changed, obj);
1979 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1980 _signal_selection_cleared, obj);
1981 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1982 _signal_entry_paste_request, obj);
1983 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1984 _signal_entry_copy_notify, obj);
1985 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1986 _signal_entry_cut_notify, obj);
1987 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1988 _signal_cursor_changed, obj);
1989 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1990 _signal_anchor_down, obj);
1991 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1992 _signal_anchor_up, obj);
1993 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1994 _signal_anchor_move, obj);
1995 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1996 _signal_anchor_in, obj);
1997 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1998 _signal_anchor_out, obj);
1999 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2000 _signal_key_enter, obj);
2001 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2002 _signal_mouse_down, obj);
2003 edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
2004 _signal_mouse_up, obj);
2005 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2006 _signal_mouse_double, obj);
2007 edje_object_part_text_set(wd->ent, "elm.text", "");
2008 elm_widget_resize_object_set(obj, wd->ent);
2011 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2013 #ifdef HAVE_ELEMENTARY_X
2014 top = elm_widget_top_get(obj);
2015 if ((top) && (elm_win_xwindow_get(top)))
2017 wd->sel_notify_handler =
2018 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2019 _event_selection_notify, obj);
2020 wd->sel_clear_handler =
2021 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2022 _event_selection_clear, obj);
2025 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2028 entries = eina_list_prepend(entries, obj);
2030 // module - find module for entry
2031 wd->api = _module(obj);
2032 // if found - hook in
2033 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2035 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2036 // TODO: and save some bytes, making descriptions per-class and not instance!
2037 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2041 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2043 ELM_CHECK_WIDTYPE(obj, widtype);
2044 Widget_Data *wd = elm_widget_data_get(obj);
2046 ext_mod->cancel = _cancel;
2047 ext_mod->copy = _copy;
2048 ext_mod->cut = _cut;
2049 ext_mod->paste = _paste;
2050 ext_mod->select = _select;
2051 ext_mod->selectall = NULL; /* to be implemented*/
2052 ext_mod->ent = wd->ent;
2053 ext_mod->items = wd->items;
2054 ext_mod->longpress_timer = wd->longpress_timer;
2055 ext_mod->editable = wd->editable;
2056 ext_mod->have_selection = wd->have_selection;
2057 ext_mod->password = wd->password;
2058 ext_mod->selmode = wd->selmode;
2059 ext_mod->context_menu = wd->context_menu;
2063 * This sets the entry object not to line wrap. All input will
2064 * be on a single line, and the entry box will extend with user input.
2066 * @param obj The entry object
2067 * @param single_line If true, the text in the entry
2068 * will be on a single line.
2073 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2075 ELM_CHECK_WIDTYPE(obj, widtype);
2076 Widget_Data *wd = elm_widget_data_get(obj);
2078 Ecore_IMF_Context *ic;
2080 if (wd->single_line == single_line) return;
2081 wd->single_line = single_line;
2082 wd->linewrap = EINA_FALSE;
2083 wd->char_linewrap = EINA_FALSE;
2084 t = eina_stringshare_add(elm_entry_entry_get(obj));
2085 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2086 elm_entry_entry_set(obj, t);
2087 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2088 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2089 ic = elm_entry_imf_context_get(obj);
2092 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2095 eina_stringshare_del(t);
2100 * This returns true if the entry has been set to single line mode.
2101 * See also elm_entry_single_line_set().
2103 * @param obj The entry object
2104 * @return single_line If true, the text in the entry is set to display
2110 elm_entry_single_line_get(const Evas_Object *obj)
2112 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2113 Widget_Data *wd = elm_widget_data_get(obj);
2114 if (!wd) return EINA_FALSE;
2115 return wd->single_line;
2119 * This set's the maximum bytes that can be added in entry.
2121 * @param obj The entry object
2122 * @param max_no_of_bytes Maximum number of bytes entry can have.
2127 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2129 Widget_Data *wd = elm_widget_data_get(obj);
2131 wd->max_no_of_bytes = max_no_of_bytes;
2132 edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2133 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2138 * This sets the entry object to password mode. All text entered
2139 * and/or displayed within the widget will be replaced with asterisks (*).
2141 * @param obj The entry object
2142 * @param password If true, password mode is enabled.
2147 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2149 ELM_CHECK_WIDTYPE(obj, widtype);
2150 Widget_Data *wd = elm_widget_data_get(obj);
2151 Ecore_IMF_Context *ic;
2154 if (wd->password == password) return;
2155 wd->password = password;
2156 wd->show_last_character = EINA_FALSE;
2157 wd->single_line = EINA_TRUE;
2158 wd->linewrap = EINA_FALSE;
2159 wd->char_linewrap = EINA_FALSE;
2160 t = eina_stringshare_add(elm_entry_entry_get(obj));
2161 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2162 elm_entry_entry_set(obj, t);
2164 ic = elm_entry_imf_context_get(obj);
2167 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2170 eina_stringshare_del(t);
2175 * This set's the entry in password mode with out masking the last character entered by user,
2176 * and later masking the character after 2 seconds.
2178 * @param obj The entry object
2179 * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character"
2185 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2187 Widget_Data *wd = elm_widget_data_get(obj);
2190 if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character)) return;
2191 wd->show_last_character = show_last_character;
2192 wd->password = show_last_character;
2193 wd->single_line = EINA_TRUE;
2194 wd->linewrap = EINA_FALSE;
2195 wd->char_linewrap = EINA_FALSE;
2196 t = eina_stringshare_add(elm_entry_entry_get(obj));
2197 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2198 elm_entry_entry_set(obj, t);
2199 eina_stringshare_del(t);
2204 * This returns whether password mode is enabled.
2205 * See also elm_entry_password_set().
2207 * @param obj The entry object
2208 * @return If true, the entry is set to display all characters
2214 elm_entry_password_get(const Evas_Object *obj)
2216 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2217 Widget_Data *wd = elm_widget_data_get(obj);
2218 if (!wd) return EINA_FALSE;
2219 return wd->password;
2223 * This sets the text displayed within the entry to @p entry.
2225 * @param obj The entry object
2226 * @param entry The text to be displayed
2231 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2233 ELM_CHECK_WIDTYPE(obj, widtype);
2234 Widget_Data *wd = elm_widget_data_get(obj);
2236 if (!entry) entry = "";
2237 if(wd->max_no_of_bytes)
2239 int len = strlen(entry);
2240 if(len > wd->max_no_of_bytes)
2242 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2246 edje_object_part_text_set(wd->ent, "elm.text", entry);
2247 if (wd->text) eina_stringshare_del(wd->text);
2249 wd->changed = EINA_TRUE;
2254 * This returns the text currently shown in object @p entry.
2255 * See also elm_entry_entry_set().
2257 * @param obj The entry object
2258 * @return The currently displayed text or NULL on failure
2263 elm_entry_entry_get(const Evas_Object *obj)
2265 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2266 Widget_Data *wd = elm_widget_data_get(obj);
2268 if (!wd) return NULL;
2269 if (wd->text) return wd->text;
2270 text = edje_object_part_text_get(wd->ent, "elm.text");
2273 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2276 eina_stringshare_replace(&wd->text, text);
2281 * This returns all selected text within the entry.
2283 * @param obj The entry object
2284 * @return The selected text within the entry or NULL on failure
2289 elm_entry_selection_get(const Evas_Object *obj)
2291 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2292 Widget_Data *wd = elm_widget_data_get(obj);
2293 if (!wd) return NULL;
2294 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2298 * This inserts text in @p entry at the beginning of the entry
2301 * @param obj The entry object
2302 * @param entry The text to insert
2307 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2309 ELM_CHECK_WIDTYPE(obj, widtype);
2310 Widget_Data *wd = elm_widget_data_get(obj);
2312 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2313 wd->changed = EINA_TRUE;
2318 * This enables word line wrapping in the entry object. It is the opposite
2319 * of elm_entry_single_line_set(). Additionally, setting this disables
2320 * character line wrapping.
2321 * See also elm_entry_line_char_wrap_set().
2323 * @param obj The entry object
2324 * @param wrap If true, the entry will be wrapped once it reaches the end
2325 * of the object. Wrapping will occur at the end of the word before the end of the
2331 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2333 ELM_CHECK_WIDTYPE(obj, widtype);
2334 Widget_Data *wd = elm_widget_data_get(obj);
2337 if (wd->linewrap == wrap) return;
2338 wd->linewrap = wrap;
2340 wd->char_linewrap = EINA_FALSE;
2341 t = eina_stringshare_add(elm_entry_entry_get(obj));
2342 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2343 elm_entry_entry_set(obj, t);
2344 eina_stringshare_del(t);
2349 * Set wrap width of the entry
2351 * @param obj The entry object
2352 * @param w The wrap width in pixels at a minimum where words need to wrap
2356 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2358 Widget_Data *wd = elm_widget_data_get(obj);
2359 if (wd->wrap_w == w) return;
2365 * get wrap width of the entry
2367 * @param obj The entry object
2368 * @return The wrap width in pixels at a minimum where words need to wrap
2372 elm_entry_wrap_width_get(const Evas_Object *obj)
2374 Widget_Data *wd = elm_widget_data_get(obj);
2379 * This enables character line wrapping in the entry object. It is the opposite
2380 * of elm_entry_single_line_set(). Additionally, setting this disables
2381 * word line wrapping.
2382 * See also elm_entry_line_wrap_set().
2384 * @param obj The entry object
2385 * @param wrap If true, the entry will be wrapped once it reaches the end
2386 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2391 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2393 ELM_CHECK_WIDTYPE(obj, widtype);
2394 Widget_Data *wd = elm_widget_data_get(obj);
2397 if (wd->char_linewrap == wrap) return;
2398 wd->char_linewrap = wrap;
2399 if(wd->char_linewrap)
2400 wd->linewrap = EINA_FALSE;
2401 t = eina_stringshare_add(elm_entry_entry_get(obj));
2402 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2403 elm_entry_entry_set(obj, t);
2404 eina_stringshare_del(t);
2409 * This sets the editable attribute of the entry.
2411 * @param obj The entry object
2412 * @param editable If true, the entry will be editable by the user.
2413 * If false, it will be set to the disabled state.
2418 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2420 ELM_CHECK_WIDTYPE(obj, widtype);
2421 Widget_Data *wd = elm_widget_data_get(obj);
2424 if (wd->editable == editable) return;
2425 wd->editable = editable;
2426 t = eina_stringshare_add(elm_entry_entry_get(obj));
2427 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2428 elm_entry_entry_set(obj, t);
2429 eina_stringshare_del(t);
2432 #ifdef HAVE_ELEMENTARY_X
2434 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2436 elm_drop_target_del(obj);
2441 * This gets the editable attribute of the entry.
2442 * See also elm_entry_editable_set().
2444 * @param obj The entry object
2445 * @return If true, the entry is editable by the user.
2446 * If false, it is not editable by the user
2451 elm_entry_editable_get(const Evas_Object *obj)
2453 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2454 Widget_Data *wd = elm_widget_data_get(obj);
2455 if (!wd) return EINA_FALSE;
2456 return wd->editable;
2460 * This drops any existing text selection within the entry.
2462 * @param obj The entry object
2467 elm_entry_select_none(Evas_Object *obj)
2469 ELM_CHECK_WIDTYPE(obj, widtype);
2470 Widget_Data *wd = elm_widget_data_get(obj);
2474 wd->selmode = EINA_FALSE;
2475 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2476 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2478 wd->have_selection = EINA_FALSE;
2479 edje_object_part_text_select_none(wd->ent, "elm.text");
2483 * This selects all text within the entry.
2485 * @param obj The entry object
2490 elm_entry_select_all(Evas_Object *obj)
2492 ELM_CHECK_WIDTYPE(obj, widtype);
2493 Widget_Data *wd = elm_widget_data_get(obj);
2497 wd->selmode = EINA_FALSE;
2498 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2499 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2501 wd->have_selection = EINA_TRUE;
2502 edje_object_part_text_select_all(wd->ent, "elm.text");
2506 * This moves the cursor one place to the right within the entry.
2508 * @param obj The entry object
2509 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2514 elm_entry_cursor_next(Evas_Object *obj)
2516 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2517 Widget_Data *wd = elm_widget_data_get(obj);
2518 if (!wd) return EINA_FALSE;
2519 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2523 * This moves the cursor one place to the left within the entry.
2525 * @param obj The entry object
2526 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2531 elm_entry_cursor_prev(Evas_Object *obj)
2533 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2534 Widget_Data *wd = elm_widget_data_get(obj);
2535 if (!wd) return EINA_FALSE;
2536 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2540 * This moves the cursor one line up within the entry.
2542 * @param obj The entry object
2543 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2548 elm_entry_cursor_up(Evas_Object *obj)
2550 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2551 Widget_Data *wd = elm_widget_data_get(obj);
2552 if (!wd) return EINA_FALSE;
2553 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2557 * This moves the cursor one line down within the entry.
2559 * @param obj The entry object
2560 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2565 elm_entry_cursor_down(Evas_Object *obj)
2567 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2568 Widget_Data *wd = elm_widget_data_get(obj);
2569 if (!wd) return EINA_FALSE;
2570 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2574 * This moves the cursor to the beginning of the entry.
2576 * @param obj The entry object
2581 elm_entry_cursor_begin_set(Evas_Object *obj)
2583 ELM_CHECK_WIDTYPE(obj, widtype);
2584 Widget_Data *wd = elm_widget_data_get(obj);
2586 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2590 * This moves the cursor to the end of the entry.
2592 * @param obj The entry object
2597 elm_entry_cursor_end_set(Evas_Object *obj)
2599 ELM_CHECK_WIDTYPE(obj, widtype);
2600 Widget_Data *wd = elm_widget_data_get(obj);
2602 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2606 * This moves the cursor to the beginning of the current line.
2608 * @param obj The entry object
2613 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2615 ELM_CHECK_WIDTYPE(obj, widtype);
2616 Widget_Data *wd = elm_widget_data_get(obj);
2618 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2622 * This moves the cursor to the end of the current line.
2624 * @param obj The entry object
2629 elm_entry_cursor_line_end_set(Evas_Object *obj)
2631 ELM_CHECK_WIDTYPE(obj, widtype);
2632 Widget_Data *wd = elm_widget_data_get(obj);
2634 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2638 * This begins a selection within the entry as though
2639 * the user were holding down the mouse button to make a selection.
2641 * @param obj The entry object
2646 elm_entry_cursor_selection_begin(Evas_Object *obj)
2648 ELM_CHECK_WIDTYPE(obj, widtype);
2649 Widget_Data *wd = elm_widget_data_get(obj);
2651 edje_object_part_text_select_begin(wd->ent, "elm.text");
2655 * This ends a selection within the entry as though
2656 * the user had just released the mouse button while making a selection.
2658 * @param obj The entry object
2663 elm_entry_cursor_selection_end(Evas_Object *obj)
2665 ELM_CHECK_WIDTYPE(obj, widtype);
2666 Widget_Data *wd = elm_widget_data_get(obj);
2668 edje_object_part_text_select_extend(wd->ent, "elm.text");
2672 * TODO: fill this in
2674 * @param obj The entry object
2675 * @return TODO: fill this in
2680 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2682 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2683 Widget_Data *wd = elm_widget_data_get(obj);
2684 if (!wd) return EINA_FALSE;
2685 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2689 * This returns whether the cursor is visible.
2691 * @param obj The entry object
2692 * @return If true, the cursor is visible.
2697 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2699 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2700 Widget_Data *wd = elm_widget_data_get(obj);
2701 if (!wd) return EINA_FALSE;
2702 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2706 * TODO: fill this in
2708 * @param obj The entry object
2709 * @return TODO: fill this in
2714 elm_entry_cursor_content_get(const Evas_Object *obj)
2716 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2717 Widget_Data *wd = elm_widget_data_get(obj);
2718 if (!wd) return NULL;
2719 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2723 * This executes a "cut" action on the selected text in the entry.
2725 * @param obj The entry object
2730 elm_entry_selection_cut(Evas_Object *obj)
2732 ELM_CHECK_WIDTYPE(obj, widtype);
2733 Widget_Data *wd = elm_widget_data_get(obj);
2735 _cut(obj, NULL, NULL);
2739 * This executes a "copy" action on the selected text in the entry.
2741 * @param obj The entry object
2746 elm_entry_selection_copy(Evas_Object *obj)
2748 ELM_CHECK_WIDTYPE(obj, widtype);
2749 Widget_Data *wd = elm_widget_data_get(obj);
2751 _copy(obj, NULL, NULL);
2755 * This executes a "paste" action in the entry.
2757 * @param obj The entry object
2762 elm_entry_selection_paste(Evas_Object *obj)
2764 ELM_CHECK_WIDTYPE(obj, widtype);
2765 Widget_Data *wd = elm_widget_data_get(obj);
2767 _paste(obj, NULL, NULL);
2771 * This clears and frees the items in a entry's contextual (right click) menu.
2773 * @param obj The entry object
2778 elm_entry_context_menu_clear(Evas_Object *obj)
2780 ELM_CHECK_WIDTYPE(obj, widtype);
2781 Widget_Data *wd = elm_widget_data_get(obj);
2782 Elm_Entry_Context_Menu_Item *it;
2784 EINA_LIST_FREE(wd->items, it)
2786 eina_stringshare_del(it->label);
2787 eina_stringshare_del(it->icon_file);
2788 eina_stringshare_del(it->icon_group);
2794 * This adds an item to the entry's contextual menu.
2796 * @param obj The entry object
2797 * @param label The item's text label
2798 * @param icon_file The item's icon file
2799 * @param icon_type The item's icon type
2800 * @param func The callback to execute when the item is clicked
2801 * @param data The data to associate with the item for related functions
2806 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)
2808 ELM_CHECK_WIDTYPE(obj, widtype);
2809 Widget_Data *wd = elm_widget_data_get(obj);
2810 Elm_Entry_Context_Menu_Item *it;
2812 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2814 wd->items = eina_list_append(wd->items, it);
2816 it->label = eina_stringshare_add(label);
2817 it->icon_file = eina_stringshare_add(icon_file);
2818 it->icon_type = icon_type;
2820 it->data = (void *)data;
2824 * This disables the entry's contextual (right click) menu.
2826 * @param obj The entry object
2827 * @param disabled If true, the menu is disabled
2832 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2834 ELM_CHECK_WIDTYPE(obj, widtype);
2835 Widget_Data *wd = elm_widget_data_get(obj);
2837 if (wd->context_menu == !disabled) return;
2838 wd->context_menu = !disabled;
2842 * This returns whether the entry's contextual (right click) menu is disabled.
2844 * @param obj The entry object
2845 * @return If true, the menu is disabled
2850 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2852 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2853 Widget_Data *wd = elm_widget_data_get(obj);
2854 if (!wd) return EINA_FALSE;
2855 return !wd->context_menu;
2859 * This appends a custom item provider to the list for that entry
2861 * This appends the given callback. The list is walked from beginning to end
2862 * with each function called given the item href string in the text. If the
2863 * function returns an object handle other than NULL (it should create an
2864 * and object to do this), then this object is used to replace that item. If
2865 * not the next provider is called until one provides an item object, or the
2866 * default provider in entry does.
2868 * @param obj The entry object
2869 * @param func The function called to provide the item object
2870 * @param data The data passed to @p func
2875 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2877 ELM_CHECK_WIDTYPE(obj, widtype);
2878 Widget_Data *wd = elm_widget_data_get(obj);
2881 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2885 wd->item_providers = eina_list_append(wd->item_providers, ip);
2889 * This prepends a custom item provider to the list for that entry
2891 * This prepends the given callback. See elm_entry_item_provider_append() for
2894 * @param obj The entry object
2895 * @param func The function called to provide the item object
2896 * @param data The data passed to @p func
2901 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2903 ELM_CHECK_WIDTYPE(obj, widtype);
2904 Widget_Data *wd = elm_widget_data_get(obj);
2907 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2911 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2915 * This removes a custom item provider to the list for that entry
2917 * This removes the given callback. See elm_entry_item_provider_append() for
2920 * @param obj The entry object
2921 * @param func The function called to provide the item object
2922 * @param data The data passed to @p func
2927 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2929 ELM_CHECK_WIDTYPE(obj, widtype);
2930 Widget_Data *wd = elm_widget_data_get(obj);
2932 Elm_Entry_Item_Provider *ip;
2935 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2937 if ((ip->func == func) && (ip->data == data))
2939 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2947 * This converts a markup (HTML-like) string into UTF-8.
2949 * @param s The string (in markup) to be converted
2950 * @return The converted string (in UTF-8)
2955 elm_entry_markup_to_utf8(const char *s)
2957 char *ss = _mkup_to_text(s);
2958 if (!ss) ss = strdup("");
2963 * This converts a UTF-8 string into markup (HTML-like).
2965 * @param s The string (in UTF-8) to be converted
2966 * @return The converted string (in markup)
2971 elm_entry_utf8_to_markup(const char *s)
2973 char *ss = _text_to_mkup(s);
2974 if (!ss) ss = strdup("");
2979 * Get the input method context in the entry widget
2981 * @param obj The entry object
2982 * @return The input method context
2986 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2988 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2989 Widget_Data *wd = elm_widget_data_get(obj);
2990 if (!wd || !wd->ent) return NULL;
2992 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2996 * Set whether entry should enable the return key on soft keyboard automatically
2998 * @param obj The entry object
2999 * @param on If true, entry enables the return key on soft keyboard automatically.
3004 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3006 ELM_CHECK_WIDTYPE(obj, widtype);
3007 Widget_Data *wd = elm_widget_data_get(obj);
3010 wd->autoreturnkey = on;
3011 _check_enable_returnkey(obj);
3015 * Set whether entry should support auto capitalization
3017 * @param obj The entry object
3018 * @param on If true, entry suports auto capitalization.
3023 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3025 ELM_CHECK_WIDTYPE(obj, widtype);
3026 Widget_Data *wd = elm_widget_data_get(obj);
3030 wd->autocapitalize = EINA_FALSE;
3032 wd->autocapitalize = autocap;
3034 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
3038 * Set whether entry should support auto period
3040 * @param obj The entry object
3041 * @param on If true, entry suports auto period.
3046 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3048 ELM_CHECK_WIDTYPE(obj, widtype);
3049 Widget_Data *wd = elm_widget_data_get(obj);
3053 wd->autoperiod = EINA_FALSE;
3055 wd->autoperiod = autoperiod;
3057 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3061 * Set the font size on the entry object
3063 * @param obj The entry object
3064 * @param size font size
3069 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3071 ELM_CHECK_WIDTYPE(obj, widtype);
3072 Widget_Data *wd = elm_widget_data_get(obj);
3073 Eina_Strbuf *fontbuf = NULL;
3078 t = eina_stringshare_add(elm_entry_entry_get(obj));
3079 fontbuf = eina_strbuf_new();
3080 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3082 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3084 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3086 elm_entry_entry_set(obj, t);
3090 eina_strbuf_free(fontbuf);
3091 eina_stringshare_del(t);
3095 * Set the text align on the entry object
3097 * @param obj The entry object
3098 * @param align align mode
3103 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3105 ELM_CHECK_WIDTYPE(obj, widtype);
3106 Widget_Data *wd = elm_widget_data_get(obj);
3111 t = eina_stringshare_add(elm_entry_entry_get(obj));
3113 if (len <= 0) return;
3115 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3116 elm_entry_entry_set(obj, t);
3120 eina_stringshare_del(t);
3124 * Set the text color on the entry object
3126 * @param obj The entry object
3127 * @param r Red property background color of The entry object
3128 * @param g Green property background color of The entry object
3129 * @param b Blue property background color of The entry object
3130 * @param a Alpha property background alpha of The entry object
3135 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3137 ELM_CHECK_WIDTYPE(obj, widtype);
3138 Widget_Data *wd = elm_widget_data_get(obj);
3139 Eina_Strbuf *colorbuf = NULL;
3144 t = eina_stringshare_add(elm_entry_entry_get(obj));
3146 if (len <= 0) return;
3147 colorbuf = eina_strbuf_new();
3148 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3150 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3152 elm_entry_entry_set(obj, t);
3156 eina_strbuf_free(colorbuf);
3157 eina_stringshare_del(t);
3162 * Set background color of the entry
3164 * @param obj The entry object
3165 * @param r Red property background color of The entry object
3166 * @param g Green property background color of The entry object
3167 * @param b Blue property background color of The entry object
3168 * @param a Alpha property background alpha of The entry object
3172 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3174 ELM_CHECK_WIDTYPE(obj, widtype);
3175 Widget_Data *wd = elm_widget_data_get(obj);
3176 evas_object_color_set(wd->bg, r, g, b, a);
3178 if (wd->bgcolor == EINA_FALSE)
3181 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3186 * Set the ellipsis behavior of the entry
3188 * @param obj The entry object
3189 * @param ellipsis To ellipsis text or not
3193 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3195 ELM_CHECK_WIDTYPE(obj, widtype);
3196 Widget_Data *wd = elm_widget_data_get(obj);
3197 if (wd->ellipsis == ellipsis) return;
3198 wd->ellipsis = ellipsis;
3204 * This sets the attribute to show the input panel automatically.
3206 * @param obj The entry object
3207 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3212 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3214 ELM_CHECK_WIDTYPE(obj, widtype);
3215 Widget_Data *wd = elm_widget_data_get(obj);
3218 wd->input_panel_enable = enabled;
3219 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3223 * Set the input panel layout of the entry
3225 * @param obj The entry object
3226 * @param layout the layout to set
3231 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3233 ELM_CHECK_WIDTYPE(obj, widtype);
3234 Widget_Data *wd = elm_widget_data_get(obj);
3237 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3240 wd->input_panel_layout = layout;
3242 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3245 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/