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 wd->selmode = EINA_TRUE;
1114 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1115 #ifdef HAVE_ELEMENTARY_X
1116 if (wd->sel_notify_handler)
1118 const char *txt = elm_entry_selection_get(data);
1121 top = elm_widget_top_get(data);
1122 if ((top) && (elm_win_xwindow_get(top)))
1123 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1129 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1131 Widget_Data *wd = elm_widget_data_get(data);
1133 wd->have_selection = EINA_TRUE;
1134 wd->selmode = EINA_TRUE;
1135 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1136 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1137 elm_entry_selection_get(data));
1141 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1143 Widget_Data *wd = elm_widget_data_get(data);
1145 if (!wd->have_selection) return;
1146 wd->have_selection = EINA_FALSE;
1147 wd->selmode = EINA_FALSE;
1148 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1149 if (wd->sel_notify_handler)
1153 #ifdef HAVE_ELEMENTARY_X
1156 top = elm_widget_top_get(data);
1157 if ((top) && (elm_win_xwindow_get(top)))
1158 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1161 eina_stringshare_del(wd->cut_sel);
1166 #ifdef HAVE_ELEMENTARY_X
1169 top = elm_widget_top_get(data);
1170 if ((top) && (elm_win_xwindow_get(top)))
1171 elm_selection_clear(ELM_SEL_PRIMARY, data);
1178 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1180 Widget_Data *wd = elm_widget_data_get(data);
1182 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1183 if (wd->sel_notify_handler)
1185 #ifdef HAVE_ELEMENTARY_X
1188 top = elm_widget_top_get(data);
1189 if ((top) && (elm_win_xwindow_get(top)))
1191 wd->selection_asked = EINA_TRUE;
1192 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data);
1199 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1201 Widget_Data *wd = elm_widget_data_get(data);
1203 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1204 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1205 elm_entry_selection_get(data));
1209 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1211 Widget_Data *wd = elm_widget_data_get(data);
1213 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1214 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1215 elm_entry_selection_get(data));
1216 edje_object_part_text_insert(wd->ent, "elm.text", "");
1217 wd->changed = EINA_TRUE;
1222 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1224 Widget_Data *wd = elm_widget_data_get(data);
1225 Evas_Coord cx, cy, cw, ch;
1227 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1228 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1229 &cx, &cy, &cw, &ch);
1230 if (!wd->deferred_recalc_job)
1231 elm_widget_show_region_set(data, cx, cy, cw, ch);
1234 wd->deferred_cur = EINA_TRUE;
1240 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1241 evas_object_smart_callback_call(data, SIG_IMPREGION_CHANGED, NULL);
1246 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1248 Widget_Data *wd = elm_widget_data_get(data);
1253 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1255 Widget_Data *wd = elm_widget_data_get(data);
1256 Elm_Entry_Anchor_Info ei;
1257 char *buf2, *p, *p2, *n;
1259 p = strrchr(emission, ',');
1262 const Eina_List *geoms;
1266 while (p2 >= emission)
1268 if (*p2 == ',') break;
1272 buf2 = alloca(5 + p - p2);
1273 strncpy(buf2, p2, p - p2);
1276 ei.button = atoi(buf2);
1277 ei.x = ei.y = ei.w = ei.h = 0;
1279 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1282 Evas_Textblock_Rectangle *r;
1284 Evas_Coord px, py, x, y;
1286 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1287 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1288 EINA_LIST_FOREACH(geoms, l, r)
1290 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1291 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1302 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1307 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1309 Widget_Data *wd = elm_widget_data_get(data);
1314 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1316 Widget_Data *wd = elm_widget_data_get(data);
1321 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1323 Widget_Data *wd = elm_widget_data_get(data);
1328 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1330 Widget_Data *wd = elm_widget_data_get(data);
1332 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1336 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1338 Widget_Data *wd = elm_widget_data_get(data);
1340 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1344 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1346 Widget_Data *wd = elm_widget_data_get(data);
1348 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1352 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1354 Widget_Data *wd = elm_widget_data_get(data);
1356 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1359 #ifdef HAVE_ELEMENTARY_X
1361 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1363 Widget_Data *wd = elm_widget_data_get(data);
1364 Ecore_X_Event_Selection_Notify *ev = event;
1365 if (!wd) return ECORE_CALLBACK_PASS_ON;
1366 if (!wd->selection_asked && !wd->drag_selection_asked)
1367 return ECORE_CALLBACK_PASS_ON;
1369 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1370 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1372 Ecore_X_Selection_Data_Text *text_data;
1374 text_data = ev->data;
1375 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1377 if (text_data->text)
1379 char *txt = _text_to_mkup(text_data->text);
1383 elm_entry_entry_insert(data, txt);
1388 wd->selection_asked = EINA_FALSE;
1390 else if (ev->selection == ECORE_X_SELECTION_XDND)
1392 Ecore_X_Selection_Data_Text *text_data;
1394 text_data = ev->data;
1395 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1397 if (text_data->text)
1399 char *txt = _text_to_mkup(text_data->text);
1403 /* Massive FIXME: this should be at the drag point */
1404 elm_entry_entry_insert(data, txt);
1409 wd->drag_selection_asked = EINA_FALSE;
1411 ecore_x_dnd_send_finished();
1414 return ECORE_CALLBACK_PASS_ON;
1418 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1421 Widget_Data *wd = elm_widget_data_get(data);
1422 Ecore_X_Event_Selection_Clear *ev = event;
1424 if (!wd->have_selection) return 1;
1425 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1426 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1428 elm_entry_select_none(data);
1433 Evas_Object *top = elm_widget_top_get(data);
1434 Ecore_X_Event_Selection_Clear *ev = event;
1437 return ECORE_CALLBACK_PASS_ON;
1439 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1441 return ECORE_CALLBACK_PASS_ON;
1444 elm_selection_get(1/*ELM_SEL_SECONDARY*/,0x1/*ELM_SEL_FORMAT_TEXT*/,data);
1446 return ECORE_CALLBACK_PASS_ON;
1451 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Drop_Data *drop)
1456 wd = elm_widget_data_get(obj);
1458 if (!wd) return EINA_FALSE;
1459 //printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1461 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1462 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1463 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1464 EDJE_CURSOR_MAIN,drop->x,drop->y);
1465 // if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1466 elm_entry_entry_insert(obj, drop->data);
1467 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1468 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1474 static Evas_Object *
1475 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1477 Widget_Data *wd = elm_widget_data_get(data);
1480 Elm_Entry_Item_Provider *ip;
1483 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1485 o = ip->func(ip->data, data, item);
1488 o = edje_object_add(evas_object_evas_get(data));
1489 if (!strncmp(item, "emoticon/", 9))
1490 ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1492 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1497 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1499 char *curlocater, *starttag, *endtag;
1500 int firstindex = 0, foundflag = -1;
1502 curlocater = strstr(oldstring, key);
1505 starttag = curlocater;
1506 endtag = curlocater + strlen(key);
1507 if (endtag == NULL || *endtag != '=')
1513 firstindex = abs(oldstring - curlocater);
1514 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1515 *value = (char*)oldstring + firstindex;
1517 while (oldstring != starttag)
1519 if (*starttag == '>')
1524 if (*starttag == '<')
1528 if (starttag == NULL) break;
1531 while (NULL != endtag)
1542 if (endtag == NULL) break;
1545 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1555 if (foundflag == 1) return 0;
1561 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1563 const char *srcstring = NULL;
1564 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1565 char *curlocater, *replocater;
1566 char *starttag, *endtag;
1567 int tagtxtlen = 0, insertflag = 0;
1569 srcstring = eina_strbuf_string_get(srcbuf);
1570 curlocater = strstr(srcstring, key);
1572 if (curlocater == NULL)
1580 starttag = strchr(srcstring, '<');
1581 endtag = strchr(srcstring, '>');
1582 tagtxtlen = endtag - starttag;
1583 if (tagtxtlen <= 0) tagtxtlen = 0;
1584 if (starttag < curlocater && curlocater < endtag) break;
1585 if (endtag != NULL && endtag+1 != NULL)
1586 srcstring = endtag+1;
1589 } while (strlen(srcstring) > 1);
1591 if (starttag && endtag && tagtxtlen > strlen(key))
1593 repbuf = eina_strbuf_new();
1594 diffbuf = eina_strbuf_new();
1595 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1596 srcstring = eina_strbuf_string_get(repbuf);
1597 curlocater = strstr(srcstring, key);
1599 if (curlocater != NULL)
1601 replocater = curlocater + strlen(key) + 1;
1603 while (*replocater == ' ' || *replocater == '=')
1608 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1611 if (replocater-curlocater > strlen(key)+1)
1614 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1623 eina_strbuf_reset(repbuf);
1631 if (repbuf == NULL) repbuf = eina_strbuf_new();
1632 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1636 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1637 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1643 eina_strbuf_prepend(diffbuf, "<");
1644 eina_strbuf_append(diffbuf, ">");
1645 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1649 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1650 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1654 if (repbuf) eina_strbuf_free(repbuf);
1655 if (diffbuf) eina_strbuf_free(diffbuf);
1661 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1663 Eina_Strbuf *sharebuf = NULL;
1665 sharebuf = eina_strbuf_new();
1666 eina_strbuf_append(sharebuf, *srcstring);
1667 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1668 eina_stringshare_del(*srcstring);
1669 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1670 eina_strbuf_free(sharebuf);
1676 _is_width_over(Evas_Object *obj)
1678 Evas_Coord x, y, w, h;
1679 Evas_Coord vx, vy, vw, vh;
1680 Widget_Data *wd = elm_widget_data_get(obj);
1684 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1686 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1688 if (x >= 0 && y >= 0)
1691 if (4 < wd->wrap_w && w > wd->wrap_w)
1698 _reverse_ellipsis_entry(Evas_Object *obj)
1700 Widget_Data *wd = elm_widget_data_get(obj);
1701 int cur_fontsize = 0;
1702 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1703 char **kvalue = NULL;
1704 const char *minfont, *deffont, *maxfont;
1705 const char *ellipsis_string = "...";
1706 int minfontsize, maxfontsize, minshowcount;
1708 minshowcount = strlen(ellipsis_string) + 1;
1709 minfont = edje_object_data_get(wd->ent, "min_font_size");
1710 if (minfont) minfontsize = atoi(minfont);
1711 else minfontsize = 1;
1712 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1713 if (maxfont) maxfontsize = atoi(maxfont);
1714 else maxfontsize = 1;
1715 deffont = edje_object_data_get(wd->ent, "default_font_size");
1716 if (deffont) cur_fontsize = atoi(deffont);
1717 else cur_fontsize = 1;
1718 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1719 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1721 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1723 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1726 txtbuf = eina_strbuf_new();
1727 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1729 if (cur_fontsize >= atoi(deffont))
1731 if (txtbuf) eina_strbuf_free(txtbuf);
1735 if (_is_width_over(obj) != 1)
1737 int rev_fontsize = cur_fontsize;
1741 if (rev_fontsize > atoi(deffont))
1744 if (fontbuf != NULL)
1746 eina_strbuf_free(fontbuf);
1749 fontbuf = eina_strbuf_new();
1750 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1751 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1752 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1754 eina_strbuf_free(fontbuf);
1756 } while (_is_width_over(obj) != 1);
1758 while (_is_width_over(obj))
1761 if (rev_fontsize < atoi(deffont))
1764 if (fontbuf != NULL)
1766 eina_strbuf_free(fontbuf);
1769 fontbuf = eina_strbuf_new();
1770 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1771 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1772 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1773 eina_strbuf_free(fontbuf);
1778 if (txtbuf) eina_strbuf_free(txtbuf);
1784 _ellipsis_entry_to_width(Evas_Object *obj)
1786 Widget_Data *wd = elm_widget_data_get(obj);
1787 int cur_fontsize = 0, len, jumpcount;
1788 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1789 char **kvalue = NULL;
1790 const char *minfont, *deffont, *maxfont;
1791 const char *ellipsis_string = "...";
1792 int minfontsize, maxfontsize, minshowcount;
1793 int i, tagend, cur_len;
1796 minshowcount = strlen(ellipsis_string) + 1;
1797 minfont = edje_object_data_get(wd->ent, "min_font_size");
1798 if (minfont) minfontsize = atoi(minfont);
1799 else minfontsize = 1;
1800 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1801 if (maxfont) maxfontsize = atoi(maxfont);
1802 else maxfontsize = 1;
1803 deffont = edje_object_data_get(wd->ent, "default_font_size");
1804 if (deffont) cur_fontsize = atoi(deffont);
1805 else cur_fontsize = 1;
1806 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1807 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1809 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1811 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1814 txtbuf = eina_strbuf_new();
1815 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1817 while (_is_width_over(obj))
1819 if (wd->ellipsis_threshold == 0)
1820 wd->ellipsis_threshold = _entry_length_get(obj);
1821 if (cur_fontsize > minfontsize)
1824 if (fontbuf != NULL)
1826 eina_strbuf_free(fontbuf);
1829 fontbuf = eina_strbuf_new();
1830 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1831 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1832 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1833 eina_strbuf_free(fontbuf);
1835 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1839 len = _entry_length_get(obj);
1840 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1841 cur_len = strlen(cur_str);
1843 for (i = 0; i < len; i++)
1845 if(cur_str[i] == '>' && cur_str[i+1] != NULL &&
1846 cur_str[i+1] != '<')
1853 while (jumpcount < len-strlen(ellipsis_string))
1855 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1859 eina_strbuf_free(txtbuf);
1862 txtbuf = eina_strbuf_new();
1863 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1864 eina_strbuf_append(txtbuf, ellipsis_string);
1865 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1866 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1867 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1869 if (_is_width_over(obj))
1877 if (txtbuf) eina_strbuf_free(txtbuf);
1882 static int _textinput_control_function(void *data,void *input_data)
1884 /*calculate character count*/
1885 Evas_Object *entry = (Evas_Object *)data;
1886 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1889 size_t insert_text_len=0;
1890 char *text = edje_object_part_text_get(wd->ent, "elm.text");
1892 size_t remain_bytes;
1895 byte_len = strlen(text);/*no of bytes*/
1896 remain_bytes = wd->max_no_of_bytes-byte_len;
1897 sprintf(buf,"%d",remain_bytes);
1898 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1901 insert_text = (char *)input_data;
1902 insert_text_len = strlen(insert_text);
1903 if(remain_bytes<insert_text_len)
1905 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1908 if(byte_len>=wd->max_no_of_bytes)
1910 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1919 * This adds an entry to @p parent object.
1921 * @param parent The parent object
1922 * @return The new object or NULL if it cannot be created
1927 elm_entry_add(Evas_Object *parent)
1929 Evas_Object *obj, *top;
1933 wd = ELM_NEW(Widget_Data);
1934 e = evas_object_evas_get(parent);
1935 wd->bgcolor = EINA_FALSE;
1936 wd->bg = evas_object_rectangle_add(e);
1937 evas_object_color_set(wd->bg, 0, 0, 0, 0);
1938 obj = elm_widget_add(e);
1939 ELM_SET_WIDTYPE(widtype, "entry");
1940 elm_widget_type_set(obj, "entry");
1941 elm_widget_sub_object_add(parent, obj);
1942 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1943 elm_widget_data_set(obj, wd);
1944 elm_widget_del_hook_set(obj, _del_hook);
1945 elm_widget_theme_hook_set(obj, _theme_hook);
1946 elm_widget_disable_hook_set(obj, _disable_hook);
1947 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1948 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1949 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1950 elm_widget_can_focus_set(obj, 1);
1951 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1952 elm_widget_imp_region_get_hook_set(obj, _imp_region_get_hook, NULL);
1955 wd->linewrap = EINA_TRUE;
1956 wd->ellipsis = EINA_FALSE;
1957 wd->char_linewrap= EINA_FALSE;
1958 wd->editable = EINA_TRUE;
1959 wd->disabled = EINA_FALSE;
1960 wd->context_menu = EINA_TRUE;
1962 wd->ellipsis_threshold = 0;
1964 wd->ent = edje_object_add(e);
1965 edje_object_item_provider_set(wd->ent, _get_item, obj);
1966 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1967 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1968 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1970 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1972 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1975 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1976 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1977 _signal_entry_changed, obj);
1978 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1979 _signal_selection_start, obj);
1980 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1981 _signal_selection_changed, obj);
1982 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1983 _signal_selection_cleared, obj);
1984 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1985 _signal_entry_paste_request, obj);
1986 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1987 _signal_entry_copy_notify, obj);
1988 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1989 _signal_entry_cut_notify, obj);
1990 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1991 _signal_cursor_changed, obj);
1992 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1993 _signal_anchor_down, obj);
1994 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1995 _signal_anchor_up, obj);
1996 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1997 _signal_anchor_move, obj);
1998 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1999 _signal_anchor_in, obj);
2000 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2001 _signal_anchor_out, obj);
2002 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2003 _signal_key_enter, obj);
2004 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2005 _signal_mouse_down, obj);
2006 edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
2007 _signal_mouse_up, obj);
2008 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2009 _signal_mouse_double, obj);
2010 edje_object_part_text_set(wd->ent, "elm.text", "");
2011 elm_widget_resize_object_set(obj, wd->ent);
2014 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2016 #ifdef HAVE_ELEMENTARY_X
2017 top = elm_widget_top_get(obj);
2018 if ((top) && (elm_win_xwindow_get(top)))
2020 wd->sel_notify_handler =
2021 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2022 _event_selection_notify, obj);
2023 wd->sel_clear_handler =
2024 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2025 _event_selection_clear, obj);
2028 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2031 entries = eina_list_prepend(entries, obj);
2033 // module - find module for entry
2034 wd->api = _module(obj);
2035 // if found - hook in
2036 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2038 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2039 // TODO: and save some bytes, making descriptions per-class and not instance!
2040 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2044 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2046 ELM_CHECK_WIDTYPE(obj, widtype);
2047 Widget_Data *wd = elm_widget_data_get(obj);
2049 ext_mod->cancel = _cancel;
2050 ext_mod->copy = _copy;
2051 ext_mod->cut = _cut;
2052 ext_mod->paste = _paste;
2053 ext_mod->select = _select;
2054 ext_mod->selectall = NULL; /* to be implemented*/
2055 ext_mod->ent = wd->ent;
2056 ext_mod->items = wd->items;
2057 ext_mod->longpress_timer = wd->longpress_timer;
2058 ext_mod->editable = wd->editable;
2059 ext_mod->have_selection = wd->have_selection;
2060 ext_mod->password = wd->password;
2061 ext_mod->selmode = wd->selmode;
2062 ext_mod->context_menu = wd->context_menu;
2066 * This sets the entry object not to line wrap. All input will
2067 * be on a single line, and the entry box will extend with user input.
2069 * @param obj The entry object
2070 * @param single_line If true, the text in the entry
2071 * will be on a single line.
2076 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2078 ELM_CHECK_WIDTYPE(obj, widtype);
2079 Widget_Data *wd = elm_widget_data_get(obj);
2081 Ecore_IMF_Context *ic;
2083 if (wd->single_line == single_line) return;
2084 wd->single_line = single_line;
2085 wd->linewrap = EINA_FALSE;
2086 wd->char_linewrap = EINA_FALSE;
2087 t = eina_stringshare_add(elm_entry_entry_get(obj));
2088 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2089 elm_entry_entry_set(obj, t);
2090 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2091 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2092 ic = elm_entry_imf_context_get(obj);
2095 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2098 eina_stringshare_del(t);
2103 * This returns true if the entry has been set to single line mode.
2104 * See also elm_entry_single_line_set().
2106 * @param obj The entry object
2107 * @return single_line If true, the text in the entry is set to display
2113 elm_entry_single_line_get(const Evas_Object *obj)
2115 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2116 Widget_Data *wd = elm_widget_data_get(obj);
2117 if (!wd) return EINA_FALSE;
2118 return wd->single_line;
2122 * This set's the maximum bytes that can be added in entry.
2124 * @param obj The entry object
2125 * @param max_no_of_bytes Maximum number of bytes entry can have.
2130 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2132 Widget_Data *wd = elm_widget_data_get(obj);
2134 wd->max_no_of_bytes = max_no_of_bytes;
2135 edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2136 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2141 * This sets the entry object to password mode. All text entered
2142 * and/or displayed within the widget will be replaced with asterisks (*).
2144 * @param obj The entry object
2145 * @param password If true, password mode is enabled.
2150 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2152 ELM_CHECK_WIDTYPE(obj, widtype);
2153 Widget_Data *wd = elm_widget_data_get(obj);
2154 Ecore_IMF_Context *ic;
2157 if (wd->password == password) return;
2158 wd->password = password;
2159 wd->show_last_character = EINA_FALSE;
2160 wd->single_line = EINA_TRUE;
2161 wd->linewrap = EINA_FALSE;
2162 wd->char_linewrap = EINA_FALSE;
2163 t = eina_stringshare_add(elm_entry_entry_get(obj));
2164 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2165 elm_entry_entry_set(obj, t);
2167 ic = elm_entry_imf_context_get(obj);
2170 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2173 eina_stringshare_del(t);
2178 * This set's the entry in password mode with out masking the last character entered by user,
2179 * and later masking the character after 2 seconds.
2181 * @param obj The entry object
2182 * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character"
2188 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2190 Widget_Data *wd = elm_widget_data_get(obj);
2193 if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character)) return;
2194 wd->show_last_character = show_last_character;
2195 wd->password = show_last_character;
2196 wd->single_line = EINA_TRUE;
2197 wd->linewrap = EINA_FALSE;
2198 wd->char_linewrap = EINA_FALSE;
2199 t = eina_stringshare_add(elm_entry_entry_get(obj));
2200 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2201 elm_entry_entry_set(obj, t);
2202 eina_stringshare_del(t);
2207 * This returns whether password mode is enabled.
2208 * See also elm_entry_password_set().
2210 * @param obj The entry object
2211 * @return If true, the entry is set to display all characters
2217 elm_entry_password_get(const Evas_Object *obj)
2219 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2220 Widget_Data *wd = elm_widget_data_get(obj);
2221 if (!wd) return EINA_FALSE;
2222 return wd->password;
2226 * This sets the text displayed within the entry to @p entry.
2228 * @param obj The entry object
2229 * @param entry The text to be displayed
2234 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2236 ELM_CHECK_WIDTYPE(obj, widtype);
2237 Widget_Data *wd = elm_widget_data_get(obj);
2239 if (!entry) entry = "";
2240 if(wd->max_no_of_bytes)
2242 int len = strlen(entry);
2243 if(len > wd->max_no_of_bytes)
2245 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2249 edje_object_part_text_set(wd->ent, "elm.text", entry);
2250 if (wd->text) eina_stringshare_del(wd->text);
2252 wd->changed = EINA_TRUE;
2257 * This returns the text currently shown in object @p entry.
2258 * See also elm_entry_entry_set().
2260 * @param obj The entry object
2261 * @return The currently displayed text or NULL on failure
2266 elm_entry_entry_get(const Evas_Object *obj)
2268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2269 Widget_Data *wd = elm_widget_data_get(obj);
2271 if (!wd) return NULL;
2272 if (wd->text) return wd->text;
2273 text = edje_object_part_text_get(wd->ent, "elm.text");
2276 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2279 eina_stringshare_replace(&wd->text, text);
2284 * This returns all selected text within the entry.
2286 * @param obj The entry object
2287 * @return The selected text within the entry or NULL on failure
2292 elm_entry_selection_get(const Evas_Object *obj)
2294 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2295 Widget_Data *wd = elm_widget_data_get(obj);
2296 if (!wd) return NULL;
2297 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2301 * This inserts text in @p entry at the beginning of the entry
2304 * @param obj The entry object
2305 * @param entry The text to insert
2310 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2312 ELM_CHECK_WIDTYPE(obj, widtype);
2313 Widget_Data *wd = elm_widget_data_get(obj);
2315 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2316 wd->changed = EINA_TRUE;
2321 * This enables word line wrapping in the entry object. It is the opposite
2322 * of elm_entry_single_line_set(). Additionally, setting this disables
2323 * character line wrapping.
2324 * See also elm_entry_line_char_wrap_set().
2326 * @param obj The entry object
2327 * @param wrap If true, the entry will be wrapped once it reaches the end
2328 * of the object. Wrapping will occur at the end of the word before the end of the
2334 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2336 ELM_CHECK_WIDTYPE(obj, widtype);
2337 Widget_Data *wd = elm_widget_data_get(obj);
2340 if (wd->linewrap == wrap) return;
2341 wd->linewrap = wrap;
2343 wd->char_linewrap = EINA_FALSE;
2344 t = eina_stringshare_add(elm_entry_entry_get(obj));
2345 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2346 elm_entry_entry_set(obj, t);
2347 eina_stringshare_del(t);
2352 * Set wrap width of the entry
2354 * @param obj The entry object
2355 * @param w The wrap width in pixels at a minimum where words need to wrap
2359 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2361 Widget_Data *wd = elm_widget_data_get(obj);
2362 if (wd->wrap_w == w) return;
2368 * get wrap width of the entry
2370 * @param obj The entry object
2371 * @return The wrap width in pixels at a minimum where words need to wrap
2375 elm_entry_wrap_width_get(const Evas_Object *obj)
2377 Widget_Data *wd = elm_widget_data_get(obj);
2382 * This enables character line wrapping in the entry object. It is the opposite
2383 * of elm_entry_single_line_set(). Additionally, setting this disables
2384 * word line wrapping.
2385 * See also elm_entry_line_wrap_set().
2387 * @param obj The entry object
2388 * @param wrap If true, the entry will be wrapped once it reaches the end
2389 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2394 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2396 ELM_CHECK_WIDTYPE(obj, widtype);
2397 Widget_Data *wd = elm_widget_data_get(obj);
2400 if (wd->char_linewrap == wrap) return;
2401 wd->char_linewrap = wrap;
2402 if(wd->char_linewrap)
2403 wd->linewrap = EINA_FALSE;
2404 t = eina_stringshare_add(elm_entry_entry_get(obj));
2405 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2406 elm_entry_entry_set(obj, t);
2407 eina_stringshare_del(t);
2412 * This sets the editable attribute of the entry.
2414 * @param obj The entry object
2415 * @param editable If true, the entry will be editable by the user.
2416 * If false, it will be set to the disabled state.
2421 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2423 ELM_CHECK_WIDTYPE(obj, widtype);
2424 Widget_Data *wd = elm_widget_data_get(obj);
2427 if (wd->editable == editable) return;
2428 wd->editable = editable;
2429 t = eina_stringshare_add(elm_entry_entry_get(obj));
2430 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2431 elm_entry_entry_set(obj, t);
2432 eina_stringshare_del(t);
2435 #ifdef HAVE_ELEMENTARY_X
2437 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2439 elm_drop_target_del(obj);
2444 * This gets the editable attribute of the entry.
2445 * See also elm_entry_editable_set().
2447 * @param obj The entry object
2448 * @return If true, the entry is editable by the user.
2449 * If false, it is not editable by the user
2454 elm_entry_editable_get(const Evas_Object *obj)
2456 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2457 Widget_Data *wd = elm_widget_data_get(obj);
2458 if (!wd) return EINA_FALSE;
2459 return wd->editable;
2463 * This drops any existing text selection within the entry.
2465 * @param obj The entry object
2470 elm_entry_select_none(Evas_Object *obj)
2472 ELM_CHECK_WIDTYPE(obj, widtype);
2473 Widget_Data *wd = elm_widget_data_get(obj);
2477 wd->selmode = EINA_FALSE;
2478 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2479 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2481 wd->have_selection = EINA_FALSE;
2482 edje_object_part_text_select_none(wd->ent, "elm.text");
2486 * This selects all text within the entry.
2488 * @param obj The entry object
2493 elm_entry_select_all(Evas_Object *obj)
2495 ELM_CHECK_WIDTYPE(obj, widtype);
2496 Widget_Data *wd = elm_widget_data_get(obj);
2500 wd->selmode = EINA_FALSE;
2501 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2502 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2504 wd->have_selection = EINA_TRUE;
2505 edje_object_part_text_select_all(wd->ent, "elm.text");
2509 * This moves the cursor one place to the right within the entry.
2511 * @param obj The entry object
2512 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2517 elm_entry_cursor_next(Evas_Object *obj)
2519 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2520 Widget_Data *wd = elm_widget_data_get(obj);
2521 if (!wd) return EINA_FALSE;
2522 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2526 * This moves the cursor one place to the left within the entry.
2528 * @param obj The entry object
2529 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2534 elm_entry_cursor_prev(Evas_Object *obj)
2536 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2537 Widget_Data *wd = elm_widget_data_get(obj);
2538 if (!wd) return EINA_FALSE;
2539 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2543 * This moves the cursor one line up within the entry.
2545 * @param obj The entry object
2546 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2551 elm_entry_cursor_up(Evas_Object *obj)
2553 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2554 Widget_Data *wd = elm_widget_data_get(obj);
2555 if (!wd) return EINA_FALSE;
2556 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2560 * This moves the cursor one line down within the entry.
2562 * @param obj The entry object
2563 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2568 elm_entry_cursor_down(Evas_Object *obj)
2570 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2571 Widget_Data *wd = elm_widget_data_get(obj);
2572 if (!wd) return EINA_FALSE;
2573 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2577 * This moves the cursor to the beginning of the entry.
2579 * @param obj The entry object
2584 elm_entry_cursor_begin_set(Evas_Object *obj)
2586 ELM_CHECK_WIDTYPE(obj, widtype);
2587 Widget_Data *wd = elm_widget_data_get(obj);
2589 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2593 * This moves the cursor to the end of the entry.
2595 * @param obj The entry object
2600 elm_entry_cursor_end_set(Evas_Object *obj)
2602 ELM_CHECK_WIDTYPE(obj, widtype);
2603 Widget_Data *wd = elm_widget_data_get(obj);
2605 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2609 * This moves the cursor to the beginning of the current line.
2611 * @param obj The entry object
2616 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2618 ELM_CHECK_WIDTYPE(obj, widtype);
2619 Widget_Data *wd = elm_widget_data_get(obj);
2621 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2625 * This moves the cursor to the end of the current line.
2627 * @param obj The entry object
2632 elm_entry_cursor_line_end_set(Evas_Object *obj)
2634 ELM_CHECK_WIDTYPE(obj, widtype);
2635 Widget_Data *wd = elm_widget_data_get(obj);
2637 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2641 * This begins a selection within the entry as though
2642 * the user were holding down the mouse button to make a selection.
2644 * @param obj The entry object
2649 elm_entry_cursor_selection_begin(Evas_Object *obj)
2651 ELM_CHECK_WIDTYPE(obj, widtype);
2652 Widget_Data *wd = elm_widget_data_get(obj);
2654 edje_object_part_text_select_begin(wd->ent, "elm.text");
2658 * This ends a selection within the entry as though
2659 * the user had just released the mouse button while making a selection.
2661 * @param obj The entry object
2666 elm_entry_cursor_selection_end(Evas_Object *obj)
2668 ELM_CHECK_WIDTYPE(obj, widtype);
2669 Widget_Data *wd = elm_widget_data_get(obj);
2671 edje_object_part_text_select_extend(wd->ent, "elm.text");
2675 * TODO: fill this in
2677 * @param obj The entry object
2678 * @return TODO: fill this in
2683 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2685 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2686 Widget_Data *wd = elm_widget_data_get(obj);
2687 if (!wd) return EINA_FALSE;
2688 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2692 * This returns whether the cursor is visible.
2694 * @param obj The entry object
2695 * @return If true, the cursor is visible.
2700 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2702 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2703 Widget_Data *wd = elm_widget_data_get(obj);
2704 if (!wd) return EINA_FALSE;
2705 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2709 * TODO: fill this in
2711 * @param obj The entry object
2712 * @return TODO: fill this in
2717 elm_entry_cursor_content_get(const Evas_Object *obj)
2719 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2720 Widget_Data *wd = elm_widget_data_get(obj);
2721 if (!wd) return NULL;
2722 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2726 * This executes a "cut" action on the selected text in the entry.
2728 * @param obj The entry object
2733 elm_entry_selection_cut(Evas_Object *obj)
2735 ELM_CHECK_WIDTYPE(obj, widtype);
2736 Widget_Data *wd = elm_widget_data_get(obj);
2738 _cut(obj, NULL, NULL);
2742 * This executes a "copy" action on the selected text in the entry.
2744 * @param obj The entry object
2749 elm_entry_selection_copy(Evas_Object *obj)
2751 ELM_CHECK_WIDTYPE(obj, widtype);
2752 Widget_Data *wd = elm_widget_data_get(obj);
2754 _copy(obj, NULL, NULL);
2758 * This executes a "paste" action in the entry.
2760 * @param obj The entry object
2765 elm_entry_selection_paste(Evas_Object *obj)
2767 ELM_CHECK_WIDTYPE(obj, widtype);
2768 Widget_Data *wd = elm_widget_data_get(obj);
2770 _paste(obj, NULL, NULL);
2774 * This clears and frees the items in a entry's contextual (right click) menu.
2776 * @param obj The entry object
2781 elm_entry_context_menu_clear(Evas_Object *obj)
2783 ELM_CHECK_WIDTYPE(obj, widtype);
2784 Widget_Data *wd = elm_widget_data_get(obj);
2785 Elm_Entry_Context_Menu_Item *it;
2787 EINA_LIST_FREE(wd->items, it)
2789 eina_stringshare_del(it->label);
2790 eina_stringshare_del(it->icon_file);
2791 eina_stringshare_del(it->icon_group);
2797 * This adds an item to the entry's contextual menu.
2799 * @param obj The entry object
2800 * @param label The item's text label
2801 * @param icon_file The item's icon file
2802 * @param icon_type The item's icon type
2803 * @param func The callback to execute when the item is clicked
2804 * @param data The data to associate with the item for related functions
2809 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)
2811 ELM_CHECK_WIDTYPE(obj, widtype);
2812 Widget_Data *wd = elm_widget_data_get(obj);
2813 Elm_Entry_Context_Menu_Item *it;
2815 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2817 wd->items = eina_list_append(wd->items, it);
2819 it->label = eina_stringshare_add(label);
2820 it->icon_file = eina_stringshare_add(icon_file);
2821 it->icon_type = icon_type;
2823 it->data = (void *)data;
2827 * This disables the entry's contextual (right click) menu.
2829 * @param obj The entry object
2830 * @param disabled If true, the menu is disabled
2835 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2837 ELM_CHECK_WIDTYPE(obj, widtype);
2838 Widget_Data *wd = elm_widget_data_get(obj);
2840 if (wd->context_menu == !disabled) return;
2841 wd->context_menu = !disabled;
2845 * This returns whether the entry's contextual (right click) menu is disabled.
2847 * @param obj The entry object
2848 * @return If true, the menu is disabled
2853 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2855 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2856 Widget_Data *wd = elm_widget_data_get(obj);
2857 if (!wd) return EINA_FALSE;
2858 return !wd->context_menu;
2862 * This appends a custom item provider to the list for that entry
2864 * This appends the given callback. The list is walked from beginning to end
2865 * with each function called given the item href string in the text. If the
2866 * function returns an object handle other than NULL (it should create an
2867 * and object to do this), then this object is used to replace that item. If
2868 * not the next provider is called until one provides an item object, or the
2869 * default provider in entry does.
2871 * @param obj The entry object
2872 * @param func The function called to provide the item object
2873 * @param data The data passed to @p func
2878 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2880 ELM_CHECK_WIDTYPE(obj, widtype);
2881 Widget_Data *wd = elm_widget_data_get(obj);
2884 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2888 wd->item_providers = eina_list_append(wd->item_providers, ip);
2892 * This prepends a custom item provider to the list for that entry
2894 * This prepends the given callback. See elm_entry_item_provider_append() for
2897 * @param obj The entry object
2898 * @param func The function called to provide the item object
2899 * @param data The data passed to @p func
2904 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2906 ELM_CHECK_WIDTYPE(obj, widtype);
2907 Widget_Data *wd = elm_widget_data_get(obj);
2910 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2914 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2918 * This removes a custom item provider to the list for that entry
2920 * This removes the given callback. See elm_entry_item_provider_append() for
2923 * @param obj The entry object
2924 * @param func The function called to provide the item object
2925 * @param data The data passed to @p func
2930 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2932 ELM_CHECK_WIDTYPE(obj, widtype);
2933 Widget_Data *wd = elm_widget_data_get(obj);
2935 Elm_Entry_Item_Provider *ip;
2938 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2940 if ((ip->func == func) && (ip->data == data))
2942 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2950 * This converts a markup (HTML-like) string into UTF-8.
2952 * @param s The string (in markup) to be converted
2953 * @return The converted string (in UTF-8)
2958 elm_entry_markup_to_utf8(const char *s)
2960 char *ss = _mkup_to_text(s);
2961 if (!ss) ss = strdup("");
2966 * This converts a UTF-8 string into markup (HTML-like).
2968 * @param s The string (in UTF-8) to be converted
2969 * @return The converted string (in markup)
2974 elm_entry_utf8_to_markup(const char *s)
2976 char *ss = _text_to_mkup(s);
2977 if (!ss) ss = strdup("");
2982 * Get the input method context in the entry widget
2984 * @param obj The entry object
2985 * @return The input method context
2989 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2991 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2992 Widget_Data *wd = elm_widget_data_get(obj);
2993 if (!wd || !wd->ent) return NULL;
2995 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2999 * Set whether entry should enable the return key on soft keyboard automatically
3001 * @param obj The entry object
3002 * @param on If true, entry enables the return key on soft keyboard automatically.
3007 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3009 ELM_CHECK_WIDTYPE(obj, widtype);
3010 Widget_Data *wd = elm_widget_data_get(obj);
3013 wd->autoreturnkey = on;
3014 _check_enable_returnkey(obj);
3018 * Set whether entry should support auto capitalization
3020 * @param obj The entry object
3021 * @param on If true, entry suports auto capitalization.
3026 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3028 ELM_CHECK_WIDTYPE(obj, widtype);
3029 Widget_Data *wd = elm_widget_data_get(obj);
3033 wd->autocapitalize = EINA_FALSE;
3035 wd->autocapitalize = autocap;
3037 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
3041 * Set whether entry should support auto period
3043 * @param obj The entry object
3044 * @param on If true, entry suports auto period.
3049 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3051 ELM_CHECK_WIDTYPE(obj, widtype);
3052 Widget_Data *wd = elm_widget_data_get(obj);
3056 wd->autoperiod = EINA_FALSE;
3058 wd->autoperiod = autoperiod;
3060 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3064 * Set the font size on the entry object
3066 * @param obj The entry object
3067 * @param size font size
3072 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3074 ELM_CHECK_WIDTYPE(obj, widtype);
3075 Widget_Data *wd = elm_widget_data_get(obj);
3076 Eina_Strbuf *fontbuf = NULL;
3081 t = eina_stringshare_add(elm_entry_entry_get(obj));
3082 fontbuf = eina_strbuf_new();
3083 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3085 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3087 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3089 elm_entry_entry_set(obj, t);
3093 eina_strbuf_free(fontbuf);
3094 eina_stringshare_del(t);
3098 * Set the text align on the entry object
3100 * @param obj The entry object
3101 * @param align align mode
3106 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3108 ELM_CHECK_WIDTYPE(obj, widtype);
3109 Widget_Data *wd = elm_widget_data_get(obj);
3114 t = eina_stringshare_add(elm_entry_entry_get(obj));
3116 if (len <= 0) return;
3118 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3119 elm_entry_entry_set(obj, t);
3123 eina_stringshare_del(t);
3127 * Set the text color on the entry object
3129 * @param obj The entry object
3130 * @param r Red property background color of The entry object
3131 * @param g Green property background color of The entry object
3132 * @param b Blue property background color of The entry object
3133 * @param a Alpha property background alpha of The entry object
3138 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3140 ELM_CHECK_WIDTYPE(obj, widtype);
3141 Widget_Data *wd = elm_widget_data_get(obj);
3142 Eina_Strbuf *colorbuf = NULL;
3147 t = eina_stringshare_add(elm_entry_entry_get(obj));
3149 if (len <= 0) return;
3150 colorbuf = eina_strbuf_new();
3151 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3153 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3155 elm_entry_entry_set(obj, t);
3159 eina_strbuf_free(colorbuf);
3160 eina_stringshare_del(t);
3165 * Set background color of the entry
3167 * @param obj The entry object
3168 * @param r Red property background color of The entry object
3169 * @param g Green property background color of The entry object
3170 * @param b Blue property background color of The entry object
3171 * @param a Alpha property background alpha of The entry object
3175 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3177 ELM_CHECK_WIDTYPE(obj, widtype);
3178 Widget_Data *wd = elm_widget_data_get(obj);
3179 evas_object_color_set(wd->bg, r, g, b, a);
3181 if (wd->bgcolor == EINA_FALSE)
3184 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3189 * Set the ellipsis behavior of the entry
3191 * @param obj The entry object
3192 * @param ellipsis To ellipsis text or not
3196 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3198 ELM_CHECK_WIDTYPE(obj, widtype);
3199 Widget_Data *wd = elm_widget_data_get(obj);
3200 if (wd->ellipsis == ellipsis) return;
3201 wd->ellipsis = ellipsis;
3207 * This sets the attribute to show the input panel automatically.
3209 * @param obj The entry object
3210 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3215 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3217 ELM_CHECK_WIDTYPE(obj, widtype);
3218 Widget_Data *wd = elm_widget_data_get(obj);
3221 wd->input_panel_enable = enabled;
3222 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3226 * Set the input panel layout of the entry
3228 * @param obj The entry object
3229 * @param layout the layout to set
3234 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3236 ELM_CHECK_WIDTYPE(obj, widtype);
3237 Widget_Data *wd = elm_widget_data_get(obj);
3240 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3243 wd->input_panel_layout = layout;
3245 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3248 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/