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 _item_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
635 Elm_Entry_Context_Menu_Item *it = data;
636 Evas_Object *obj2 = it->obj;
639 if (!strcmp(it->label, "Menu"))
641 elm_cbhm_helper_init(obj);
642 elm_cbhm_send_raw_data("show");
646 if (it->func) it->func(it->data, obj2, NULL);
650 _long_press(void *data)
652 Widget_Data *wd = elm_widget_data_get(data);
655 const Elm_Entry_Context_Menu_Item *it;
656 if (!wd) return ECORE_CALLBACK_CANCEL;
657 if ((wd->api) && (wd->api->obj_longpress))
659 wd->api->obj_longpress(data);
661 else if (wd->context_menu)
663 const char *context_menu_orientation;
665 if (wd->hoversel) evas_object_del(wd->hoversel);
666 else elm_widget_scroll_freeze_push(data);
667 wd->hoversel = elm_hoversel_add(data);
668 context_menu_orientation = edje_object_data_get
669 (wd->ent, "context_menu_orientation");
670 if ((context_menu_orientation) &&
671 (!strcmp(context_menu_orientation, "horizontal")))
672 elm_hoversel_horizontal_set(wd->hoversel, 1);
673 elm_object_style_set(wd->hoversel, "entry");
674 elm_widget_sub_object_add(data, wd->hoversel);
675 elm_hoversel_label_set(wd->hoversel, "Text");
676 top = elm_widget_top_get(data);
677 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
678 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
682 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
684 if (1) // need way to detect if someone has a selection
687 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
695 if (wd->have_selection)
697 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
700 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
703 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
707 EINA_LIST_FOREACH(wd->items, l, it)
709 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
710 it->icon_type, _item_clicked, it);
714 _hoversel_position(data);
715 evas_object_show(wd->hoversel);
716 elm_hoversel_hover_begin(wd->hoversel);
718 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
719 edje_object_part_text_select_abort(wd->ent, "elm.text");
721 wd->longpress_timer = NULL;
722 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
723 return ECORE_CALLBACK_CANCEL;
727 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
729 Widget_Data *wd = elm_widget_data_get(data);
730 Evas_Event_Mouse_Down *ev = event_info;
732 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
733 if (ev->button != 1) return;
734 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
735 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
736 wd->longpress_timer = ecore_timer_add(1.0, _long_press, data);
737 wd->downx = ev->canvas.x;
738 wd->downy = ev->canvas.y;
742 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
744 Widget_Data *wd = elm_widget_data_get(data);
745 Evas_Event_Mouse_Up *ev = event_info;
747 if (ev->button != 1) return;
748 if ((wd->api) && (wd->api->obj_mouseup))
750 wd->api->obj_mouseup(data);
752 if (wd->longpress_timer)
754 ecore_timer_del(wd->longpress_timer);
755 wd->longpress_timer = NULL;
760 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
762 Widget_Data *wd = elm_widget_data_get(data);
763 Evas_Event_Mouse_Move *ev = event_info;
767 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
769 if (wd->longpress_timer)
771 ecore_timer_del(wd->longpress_timer);
772 wd->longpress_timer = NULL;
775 else if (wd->longpress_timer)
779 dx = wd->downx - ev->cur.canvas.x;
781 dy = wd->downy - ev->cur.canvas.y;
784 ((_elm_config->finger_size / 2) *
785 (_elm_config->finger_size / 2)))
787 ecore_timer_del(wd->longpress_timer);
788 wd->longpress_timer = NULL;
792 else if (wd->longpress_timer)
796 dx = wd->downx - ev->cur.canvas.x;
798 dy = wd->downy - ev->cur.canvas.y;
801 ((_elm_config->finger_size / 2) *
802 (_elm_config->finger_size / 2)))
804 ecore_timer_del(wd->longpress_timer);
805 wd->longpress_timer = NULL;
811 _getbase(Evas_Object *obj)
813 Widget_Data *wd = elm_widget_data_get(obj);
814 if (!wd) return "base";
817 if((wd->password)&&(wd->show_last_character)) return "custom-password";
818 else if(wd->password) return "base-password";
821 if (wd->single_line) return "base-single";
824 if (wd->linewrap) return "base";
825 else if (wd->char_linewrap) return "base-charwrap";
826 else return "base-nowrap";
832 if((wd->password)&&(wd->show_last_character)) return "custom-password";
833 else if(wd->password) return "base-password";
836 if (wd->single_line) return "base-single-noedit";
839 if (wd->linewrap) return "base-noedit";
840 else if (wd->char_linewrap) return "base-noedit-charwrap";
841 else return "base-nowrap-noedit";
849 _str_append(char *str, const char *txt, int *len, int *alloc)
851 int txt_len = strlen(txt);
853 if (txt_len <= 0) return str;
854 if ((*len + txt_len) >= *alloc)
859 alloc2 = *alloc + txt_len + 128;
860 str2 = realloc(str, alloc2);
861 if (!str2) return str;
865 strcpy(str + *len, txt);
870 /*FIXME: Sholud be implemented somewhere else, it really depends on the context
871 * because some markups can be implemented otherwise according to style.
872 * probably doing it in textblock and making it translate according to it's
873 * style is correct. */
875 _strncpy(char* dest, const char* src, size_t count)
879 ERR( "dest is NULL" );
884 ERR( "src is NULL" );
889 ERR( "count is smaller than 0" );
893 return strncpy( dest, src, count );
897 _mkup_to_text(const char *mkup)
900 int str_len = 0, str_alloc = 0;
902 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
904 if (!mkup) return NULL;
906 tag_start = tag_end = esc_start = esc_end = NULL;
911 if (((p!=NULL)&&(*p == 0)) ||
912 (tag_end) || (esc_end) ||
913 (tag_start) || (esc_start))
919 ttag = malloc(tag_end - tag_start);
922 _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
923 ttag[tag_end - tag_start - 1] = 0;
924 if (!strcmp(ttag, "br"))
925 str = _str_append(str, "\n", &str_len, &str_alloc);
926 else if (!strcmp(ttag, "\n"))
927 str = _str_append(str, "\n", &str_len, &str_alloc);
928 else if (!strcmp(ttag, "\\n"))
929 str = _str_append(str, "\n", &str_len, &str_alloc);
930 else if (!strcmp(ttag, "\t"))
931 str = _str_append(str, "\t", &str_len, &str_alloc);
932 else if (!strcmp(ttag, "\\t"))
933 str = _str_append(str, "\t", &str_len, &str_alloc);
934 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
935 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
938 tag_start = tag_end = NULL;
942 ts = malloc(esc_end - esc_start + 1);
946 _strncpy(ts, esc_start, esc_end - esc_start);
947 ts[esc_end - esc_start] = 0;
948 esc = evas_textblock_escape_string_get(ts);
950 str = _str_append(str, esc, &str_len, &str_alloc);
953 esc_start = esc_end = NULL;
955 else if ((p!=NULL)&&(*p == 0))
957 ts = malloc(p - s + 1);
960 _strncpy(ts, s, p - s);
962 str = _str_append(str, ts, &str_len, &str_alloc);
968 if ((p!=NULL)&&(*p == '<'))
974 ts = malloc(p - s + 1);
977 _strncpy(ts, s, p - s);
979 str = _str_append(str, ts, &str_len, &str_alloc);
985 else if ((p!=NULL)&&(*p == '>'))
993 else if ((p!=NULL)&&(*p == '&'))
999 ts = malloc(p - s + 1);
1002 _strncpy(ts, s, p - s);
1004 str = _str_append(str, ts, &str_len, &str_alloc);
1010 else if ((p!=NULL)&&(*p == ';'))
1024 _entry_length_get(Evas_Object *obj)
1027 const char *str = elm_entry_entry_get(obj);
1030 char *plain_str = _mkup_to_text(str);
1031 if (!plain_str) return 0;
1033 len = strlen(plain_str);
1040 _text_to_mkup(const char *text)
1043 int str_len = 0, str_alloc = 0;
1044 int ch, pos = 0, pos2 = 0;
1046 if (!text) return NULL;
1050 pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
1051 if ((ch <= 0) || (pos2 <= 0)) break;
1053 str = _str_append(str, "<br>", &str_len, &str_alloc);
1054 else if (ch == '\t')
1055 str = _str_append(str, "<\t>", &str_len, &str_alloc);
1057 str = _str_append(str, "<", &str_len, &str_alloc);
1059 str = _str_append(str, ">", &str_len, &str_alloc);
1061 str = _str_append(str, "&", &str_len, &str_alloc);
1066 _strncpy(tstr, text + pos, pos2 - pos);
1067 tstr[pos2 - pos] = 0;
1068 str = _str_append(str, tstr, &str_len, &str_alloc);
1075 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1077 Widget_Data *wd = elm_widget_data_get(data);
1079 wd->changed = EINA_TRUE;
1081 if (wd->text) eina_stringshare_del(wd->text);
1083 _check_enable_returnkey(data);
1084 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1088 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1090 Widget_Data *wd = elm_widget_data_get(data);
1094 EINA_LIST_FOREACH(entries, l, entry)
1096 if (entry != data) elm_entry_select_none(entry);
1098 wd->have_selection = EINA_TRUE;
1099 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1100 #ifdef HAVE_ELEMENTARY_X
1101 if (wd->sel_notify_handler)
1103 const char *txt = elm_entry_selection_get(data);
1106 top = elm_widget_top_get(data);
1107 if ((top) && (elm_win_xwindow_get(top)))
1108 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1114 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1116 Widget_Data *wd = elm_widget_data_get(data);
1118 wd->have_selection = EINA_TRUE;
1119 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1120 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1121 elm_entry_selection_get(data));
1125 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1127 Widget_Data *wd = elm_widget_data_get(data);
1129 if (!wd->have_selection) return;
1130 wd->have_selection = EINA_FALSE;
1131 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1132 if (wd->sel_notify_handler)
1136 #ifdef HAVE_ELEMENTARY_X
1139 top = elm_widget_top_get(data);
1140 if ((top) && (elm_win_xwindow_get(top)))
1141 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1144 eina_stringshare_del(wd->cut_sel);
1149 #ifdef HAVE_ELEMENTARY_X
1152 top = elm_widget_top_get(data);
1153 if ((top) && (elm_win_xwindow_get(top)))
1154 elm_selection_clear(ELM_SEL_PRIMARY, data);
1161 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1163 Widget_Data *wd = elm_widget_data_get(data);
1165 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1166 if (wd->sel_notify_handler)
1168 #ifdef HAVE_ELEMENTARY_X
1171 top = elm_widget_top_get(data);
1172 if ((top) && (elm_win_xwindow_get(top)))
1174 wd->selection_asked = EINA_TRUE;
1175 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data);
1182 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1184 Widget_Data *wd = elm_widget_data_get(data);
1186 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1187 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1188 elm_entry_selection_get(data));
1192 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1194 Widget_Data *wd = elm_widget_data_get(data);
1196 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1197 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1198 elm_entry_selection_get(data));
1199 edje_object_part_text_insert(wd->ent, "elm.text", "");
1200 wd->changed = EINA_TRUE;
1205 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1207 Widget_Data *wd = elm_widget_data_get(data);
1208 Evas_Coord cx, cy, cw, ch;
1210 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1211 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1212 &cx, &cy, &cw, &ch);
1213 if (!wd->deferred_recalc_job)
1214 elm_widget_show_region_set(data, cx, cy, cw, ch);
1217 wd->deferred_cur = EINA_TRUE;
1223 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1224 evas_object_smart_callback_call(data, SIG_IMPREGION_CHANGED, NULL);
1229 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1231 Widget_Data *wd = elm_widget_data_get(data);
1236 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1238 Widget_Data *wd = elm_widget_data_get(data);
1239 Elm_Entry_Anchor_Info ei;
1240 char *buf2, *p, *p2, *n;
1242 p = strrchr(emission, ',');
1245 const Eina_List *geoms;
1249 while (p2 >= emission)
1251 if (*p2 == ',') break;
1255 buf2 = alloca(5 + p - p2);
1256 strncpy(buf2, p2, p - p2);
1259 ei.button = atoi(buf2);
1260 ei.x = ei.y = ei.w = ei.h = 0;
1262 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1265 Evas_Textblock_Rectangle *r;
1267 Evas_Coord px, py, x, y;
1269 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1270 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1271 EINA_LIST_FOREACH(geoms, l, r)
1273 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1274 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1285 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1290 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1292 Widget_Data *wd = elm_widget_data_get(data);
1297 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1299 Widget_Data *wd = elm_widget_data_get(data);
1304 _signal_anchor_out(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_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1313 Widget_Data *wd = elm_widget_data_get(data);
1315 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1319 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1321 Widget_Data *wd = elm_widget_data_get(data);
1323 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1327 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1329 Widget_Data *wd = elm_widget_data_get(data);
1331 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1335 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1337 Widget_Data *wd = elm_widget_data_get(data);
1339 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1342 #ifdef HAVE_ELEMENTARY_X
1344 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1346 Widget_Data *wd = elm_widget_data_get(data);
1347 Ecore_X_Event_Selection_Notify *ev = event;
1348 if (!wd) return ECORE_CALLBACK_PASS_ON;
1349 if (!wd->selection_asked && !wd->drag_selection_asked)
1350 return ECORE_CALLBACK_PASS_ON;
1352 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1353 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1355 Ecore_X_Selection_Data_Text *text_data;
1357 text_data = ev->data;
1358 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1360 if (text_data->text)
1362 char *txt = _text_to_mkup(text_data->text);
1366 elm_entry_entry_insert(data, txt);
1371 wd->selection_asked = EINA_FALSE;
1373 else if (ev->selection == ECORE_X_SELECTION_XDND)
1375 Ecore_X_Selection_Data_Text *text_data;
1377 text_data = ev->data;
1378 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1380 if (text_data->text)
1382 char *txt = _text_to_mkup(text_data->text);
1386 /* Massive FIXME: this should be at the drag point */
1387 elm_entry_entry_insert(data, txt);
1392 wd->drag_selection_asked = EINA_FALSE;
1394 ecore_x_dnd_send_finished();
1397 return ECORE_CALLBACK_PASS_ON;
1401 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1404 Widget_Data *wd = elm_widget_data_get(data);
1405 Ecore_X_Event_Selection_Clear *ev = event;
1407 if (!wd->have_selection) return 1;
1408 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1409 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1411 elm_entry_select_none(data);
1416 Evas_Object *top = elm_widget_top_get(data);
1417 Ecore_X_Event_Selection_Clear *ev = event;
1420 return ECORE_CALLBACK_PASS_ON;
1422 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1424 return ECORE_CALLBACK_PASS_ON;
1427 elm_selection_get(1/*ELM_SEL_SECONDARY*/,0x1/*Markup */,data);
1429 return ECORE_CALLBACK_PASS_ON;
1434 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Drop_Data *drop)
1439 wd = elm_widget_data_get(obj);
1441 if (!wd) return EINA_FALSE;
1442 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1444 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1445 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1446 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1447 EDJE_CURSOR_MAIN,drop->x,drop->y);
1448 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1449 elm_entry_entry_insert(obj, drop->data);
1450 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1451 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1457 static Evas_Object *
1458 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1460 Widget_Data *wd = elm_widget_data_get(data);
1463 Elm_Entry_Item_Provider *ip;
1466 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1468 o = ip->func(ip->data, data, item);
1471 o = edje_object_add(evas_object_evas_get(data));
1472 if (!strncmp(item, "emoticon/", 9))
1473 ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1475 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1480 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1482 char *curlocater, *starttag, *endtag;
1483 int firstindex = 0, foundflag = -1;
1485 curlocater = strstr(oldstring, key);
1488 starttag = curlocater;
1489 endtag = curlocater + strlen(key);
1490 if (endtag == NULL || *endtag != '=')
1496 firstindex = abs(oldstring - curlocater);
1497 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1498 *value = (char*)oldstring + firstindex;
1500 while (oldstring != starttag)
1502 if (*starttag == '>')
1507 if (*starttag == '<')
1511 if (starttag == NULL) break;
1514 while (NULL != endtag)
1525 if (endtag == NULL) break;
1528 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1538 if (foundflag == 1) return 0;
1544 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1546 const char *srcstring = NULL;
1547 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1548 char *curlocater, *replocater;
1549 char *starttag, *endtag;
1550 int tagtxtlen = 0, insertflag = 0;
1552 srcstring = eina_strbuf_string_get(srcbuf);
1553 curlocater = strstr(srcstring, key);
1555 if (curlocater == NULL)
1563 starttag = strchr(srcstring, '<');
1564 endtag = strchr(srcstring, '>');
1565 tagtxtlen = endtag - starttag;
1566 if (tagtxtlen <= 0) tagtxtlen = 0;
1567 if (starttag < curlocater && curlocater < endtag) break;
1568 if (endtag != NULL && endtag+1 != NULL)
1569 srcstring = endtag+1;
1572 } while (strlen(srcstring) > 1);
1574 if (starttag && endtag && tagtxtlen > strlen(key))
1576 repbuf = eina_strbuf_new();
1577 diffbuf = eina_strbuf_new();
1578 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1579 srcstring = eina_strbuf_string_get(repbuf);
1580 curlocater = strstr(srcstring, key);
1582 if (curlocater != NULL)
1584 replocater = curlocater + strlen(key) + 1;
1586 while (*replocater == ' ' || *replocater == '=')
1591 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1594 if (replocater-curlocater > strlen(key)+1)
1597 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1606 eina_strbuf_reset(repbuf);
1614 if (repbuf == NULL) repbuf = eina_strbuf_new();
1615 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1619 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1620 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1626 eina_strbuf_prepend(diffbuf, "<");
1627 eina_strbuf_append(diffbuf, ">");
1628 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1632 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1633 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1637 if (repbuf) eina_strbuf_free(repbuf);
1638 if (diffbuf) eina_strbuf_free(diffbuf);
1644 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1646 Eina_Strbuf *sharebuf = NULL;
1648 sharebuf = eina_strbuf_new();
1649 eina_strbuf_append(sharebuf, *srcstring);
1650 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1651 eina_stringshare_del(*srcstring);
1652 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1653 eina_strbuf_free(sharebuf);
1659 _is_width_over(Evas_Object *obj)
1661 Evas_Coord x, y, w, h;
1662 Evas_Coord vx, vy, vw, vh;
1663 Widget_Data *wd = elm_widget_data_get(obj);
1667 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1669 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1671 if (x >= 0 && y >= 0)
1674 if (4 < wd->wrap_w && w > wd->wrap_w)
1681 _reverse_ellipsis_entry(Evas_Object *obj)
1683 Widget_Data *wd = elm_widget_data_get(obj);
1684 int cur_fontsize = 0;
1685 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1686 char **kvalue = NULL;
1687 const char *minfont, *deffont, *maxfont;
1688 const char *ellipsis_string = "...";
1689 int minfontsize, maxfontsize, minshowcount;
1691 minshowcount = strlen(ellipsis_string) + 1;
1692 minfont = edje_object_data_get(wd->ent, "min_font_size");
1693 if (minfont) minfontsize = atoi(minfont);
1694 else minfontsize = 1;
1695 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1696 if (maxfont) maxfontsize = atoi(maxfont);
1697 else maxfontsize = 1;
1698 deffont = edje_object_data_get(wd->ent, "default_font_size");
1699 if (deffont) cur_fontsize = atoi(deffont);
1700 else cur_fontsize = 1;
1701 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1702 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1704 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1706 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1709 txtbuf = eina_strbuf_new();
1710 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1712 if (cur_fontsize >= atoi(deffont))
1714 if (txtbuf) eina_strbuf_free(txtbuf);
1718 if (_is_width_over(obj) != 1)
1720 int rev_fontsize = cur_fontsize;
1724 if (rev_fontsize > atoi(deffont))
1727 if (fontbuf != NULL)
1729 eina_strbuf_free(fontbuf);
1732 fontbuf = eina_strbuf_new();
1733 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1734 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1735 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1737 eina_strbuf_free(fontbuf);
1739 } while (_is_width_over(obj) != 1);
1741 while (_is_width_over(obj))
1744 if (rev_fontsize < atoi(deffont))
1747 if (fontbuf != NULL)
1749 eina_strbuf_free(fontbuf);
1752 fontbuf = eina_strbuf_new();
1753 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1754 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1755 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1756 eina_strbuf_free(fontbuf);
1761 if (txtbuf) eina_strbuf_free(txtbuf);
1767 _ellipsis_entry_to_width(Evas_Object *obj)
1769 Widget_Data *wd = elm_widget_data_get(obj);
1770 int cur_fontsize = 0, len, jumpcount;
1771 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1772 char **kvalue = NULL;
1773 const char *minfont, *deffont, *maxfont;
1774 const char *ellipsis_string = "...";
1775 int minfontsize, maxfontsize, minshowcount;
1776 int i, tagend, cur_len;
1779 minshowcount = strlen(ellipsis_string) + 1;
1780 minfont = edje_object_data_get(wd->ent, "min_font_size");
1781 if (minfont) minfontsize = atoi(minfont);
1782 else minfontsize = 1;
1783 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1784 if (maxfont) maxfontsize = atoi(maxfont);
1785 else maxfontsize = 1;
1786 deffont = edje_object_data_get(wd->ent, "default_font_size");
1787 if (deffont) cur_fontsize = atoi(deffont);
1788 else cur_fontsize = 1;
1789 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1790 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1792 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1794 if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1797 txtbuf = eina_strbuf_new();
1798 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1800 while (_is_width_over(obj))
1802 if (wd->ellipsis_threshold == 0)
1803 wd->ellipsis_threshold = _entry_length_get(obj);
1804 if (cur_fontsize > minfontsize)
1807 if (fontbuf != NULL)
1809 eina_strbuf_free(fontbuf);
1812 fontbuf = eina_strbuf_new();
1813 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1814 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1815 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1816 eina_strbuf_free(fontbuf);
1818 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1822 len = _entry_length_get(obj);
1823 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1824 cur_len = strlen(cur_str);
1826 for (i = 0; i < len; i++)
1828 if(cur_str[i] == '>' && cur_str[i+1] != NULL &&
1829 cur_str[i+1] != '<')
1836 while (jumpcount < len-strlen(ellipsis_string))
1838 cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1842 eina_strbuf_free(txtbuf);
1845 txtbuf = eina_strbuf_new();
1846 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1847 eina_strbuf_append(txtbuf, ellipsis_string);
1848 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1849 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1850 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1852 if (_is_width_over(obj))
1860 if (txtbuf) eina_strbuf_free(txtbuf);
1865 static int _textinput_control_function(void *data,void *input_data)
1867 /*calculate character count*/
1868 Evas_Object *entry = (Evas_Object *)data;
1869 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1872 size_t insert_text_len=0;
1873 char *text = edje_object_part_text_get(wd->ent, "elm.text");
1875 size_t remain_bytes;
1878 byte_len = strlen(text);/*no of bytes*/
1879 remain_bytes = wd->max_no_of_bytes-byte_len;
1880 sprintf(buf,"%d",remain_bytes);
1881 edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1884 insert_text = (char *)input_data;
1885 insert_text_len = strlen(insert_text);
1886 if(remain_bytes<insert_text_len)
1888 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1891 if(byte_len>=wd->max_no_of_bytes)
1893 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1902 * This adds an entry to @p parent object.
1904 * @param parent The parent object
1905 * @return The new object or NULL if it cannot be created
1910 elm_entry_add(Evas_Object *parent)
1912 Evas_Object *obj, *top;
1916 wd = ELM_NEW(Widget_Data);
1917 e = evas_object_evas_get(parent);
1918 wd->bgcolor = EINA_FALSE;
1919 wd->bg = evas_object_rectangle_add(e);
1920 evas_object_color_set(wd->bg, 0, 0, 0, 0);
1921 obj = elm_widget_add(e);
1922 ELM_SET_WIDTYPE(widtype, "entry");
1923 elm_widget_type_set(obj, "entry");
1924 elm_widget_sub_object_add(parent, obj);
1925 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1926 elm_widget_data_set(obj, wd);
1927 elm_widget_del_hook_set(obj, _del_hook);
1928 elm_widget_theme_hook_set(obj, _theme_hook);
1929 elm_widget_disable_hook_set(obj, _disable_hook);
1930 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1931 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1932 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1933 elm_widget_can_focus_set(obj, 1);
1934 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1935 elm_widget_imp_region_get_hook_set(obj, _imp_region_get_hook, NULL);
1938 wd->linewrap = EINA_TRUE;
1939 wd->ellipsis = EINA_FALSE;
1940 wd->char_linewrap= EINA_FALSE;
1941 wd->editable = EINA_TRUE;
1942 wd->disabled = EINA_FALSE;
1943 wd->context_menu = EINA_TRUE;
1945 wd->ellipsis_threshold = 0;
1947 wd->ent = edje_object_add(e);
1948 edje_object_item_provider_set(wd->ent, _get_item, obj);
1949 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1950 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1951 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1953 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1955 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1958 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1959 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1960 _signal_entry_changed, obj);
1961 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1962 _signal_selection_start, obj);
1963 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1964 _signal_selection_changed, obj);
1965 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1966 _signal_selection_cleared, obj);
1967 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1968 _signal_entry_paste_request, obj);
1969 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1970 _signal_entry_copy_notify, obj);
1971 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1972 _signal_entry_cut_notify, obj);
1973 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1974 _signal_cursor_changed, obj);
1975 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1976 _signal_anchor_down, obj);
1977 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1978 _signal_anchor_up, obj);
1979 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1980 _signal_anchor_move, obj);
1981 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1982 _signal_anchor_in, obj);
1983 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1984 _signal_anchor_out, obj);
1985 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1986 _signal_key_enter, obj);
1987 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1988 _signal_mouse_down, obj);
1989 edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
1990 _signal_mouse_up, obj);
1991 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1992 _signal_mouse_double, obj);
1993 edje_object_part_text_set(wd->ent, "elm.text", "");
1994 elm_widget_resize_object_set(obj, wd->ent);
1997 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
1999 #ifdef HAVE_ELEMENTARY_X
2000 top = elm_widget_top_get(obj);
2001 if ((top) && (elm_win_xwindow_get(top)))
2003 wd->sel_notify_handler =
2004 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2005 _event_selection_notify, obj);
2006 wd->sel_clear_handler =
2007 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2008 _event_selection_clear, obj);
2011 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2014 entries = eina_list_prepend(entries, obj);
2016 // module - find module for entry
2017 wd->api = _module(obj);
2018 // if found - hook in
2019 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2021 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2022 // TODO: and save some bytes, making descriptions per-class and not instance!
2023 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2027 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2029 ELM_CHECK_WIDTYPE(obj, widtype);
2030 Widget_Data *wd = elm_widget_data_get(obj);
2032 ext_mod->cancel = _cancel;
2033 ext_mod->copy = _copy;
2034 ext_mod->cut = _cut;
2035 ext_mod->paste = _paste;
2036 ext_mod->select = _select;
2037 ext_mod->selectall = NULL; /* to be implemented*/
2038 ext_mod->ent = wd->ent;
2039 ext_mod->items = wd->items;
2040 ext_mod->longpress_timer = wd->longpress_timer;
2041 ext_mod->editable = wd->editable;
2042 ext_mod->have_selection = wd->have_selection;
2043 ext_mod->password = wd->password;
2044 ext_mod->selmode = wd->selmode;
2045 ext_mod->context_menu = wd->context_menu;
2049 * This sets the entry object not to line wrap. All input will
2050 * be on a single line, and the entry box will extend with user input.
2052 * @param obj The entry object
2053 * @param single_line If true, the text in the entry
2054 * will be on a single line.
2059 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2061 ELM_CHECK_WIDTYPE(obj, widtype);
2062 Widget_Data *wd = elm_widget_data_get(obj);
2064 Ecore_IMF_Context *ic;
2066 if (wd->single_line == single_line) return;
2067 wd->single_line = single_line;
2068 wd->linewrap = EINA_FALSE;
2069 wd->char_linewrap = EINA_FALSE;
2070 t = eina_stringshare_add(elm_entry_entry_get(obj));
2071 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2072 elm_entry_entry_set(obj, t);
2073 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2074 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2075 ic = elm_entry_imf_context_get(obj);
2078 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2081 eina_stringshare_del(t);
2086 * This returns true if the entry has been set to single line mode.
2087 * See also elm_entry_single_line_set().
2089 * @param obj The entry object
2090 * @return single_line If true, the text in the entry is set to display
2096 elm_entry_single_line_get(const Evas_Object *obj)
2098 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2099 Widget_Data *wd = elm_widget_data_get(obj);
2100 if (!wd) return EINA_FALSE;
2101 return wd->single_line;
2105 * This set's the maximum bytes that can be added in entry.
2107 * @param obj The entry object
2108 * @param max_no_of_bytes Maximum number of bytes entry can have.
2113 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2115 Widget_Data *wd = elm_widget_data_get(obj);
2117 wd->max_no_of_bytes = max_no_of_bytes;
2118 edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2119 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2124 * This sets the entry object to password mode. All text entered
2125 * and/or displayed within the widget will be replaced with asterisks (*).
2127 * @param obj The entry object
2128 * @param password If true, password mode is enabled.
2133 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2135 ELM_CHECK_WIDTYPE(obj, widtype);
2136 Widget_Data *wd = elm_widget_data_get(obj);
2137 Ecore_IMF_Context *ic;
2140 if (wd->password == password) return;
2141 wd->password = password;
2142 wd->show_last_character = EINA_FALSE;
2143 wd->single_line = EINA_TRUE;
2144 wd->linewrap = EINA_FALSE;
2145 wd->char_linewrap = EINA_FALSE;
2146 t = eina_stringshare_add(elm_entry_entry_get(obj));
2147 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2148 elm_entry_entry_set(obj, t);
2150 ic = elm_entry_imf_context_get(obj);
2153 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2156 eina_stringshare_del(t);
2161 * This set's the entry in password mode with out masking the last character entered by user,
2162 * and later masking the character after 2 seconds.
2164 * @param obj The entry object
2165 * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character"
2171 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2173 Widget_Data *wd = elm_widget_data_get(obj);
2176 if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character)) return;
2177 wd->show_last_character = show_last_character;
2178 wd->password = show_last_character;
2179 wd->single_line = EINA_TRUE;
2180 wd->linewrap = EINA_FALSE;
2181 wd->char_linewrap = EINA_FALSE;
2182 t = eina_stringshare_add(elm_entry_entry_get(obj));
2183 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2184 elm_entry_entry_set(obj, t);
2185 eina_stringshare_del(t);
2190 * This returns whether password mode is enabled.
2191 * See also elm_entry_password_set().
2193 * @param obj The entry object
2194 * @return If true, the entry is set to display all characters
2200 elm_entry_password_get(const Evas_Object *obj)
2202 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2203 Widget_Data *wd = elm_widget_data_get(obj);
2204 if (!wd) return EINA_FALSE;
2205 return wd->password;
2209 * This sets the text displayed within the entry to @p entry.
2211 * @param obj The entry object
2212 * @param entry The text to be displayed
2217 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2219 ELM_CHECK_WIDTYPE(obj, widtype);
2220 Widget_Data *wd = elm_widget_data_get(obj);
2222 if (!entry) entry = "";
2223 if(wd->max_no_of_bytes)
2225 int len = strlen(entry);
2226 if(len > wd->max_no_of_bytes)
2228 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2232 edje_object_part_text_set(wd->ent, "elm.text", entry);
2233 if (wd->text) eina_stringshare_del(wd->text);
2235 wd->changed = EINA_TRUE;
2240 * This returns the text currently shown in object @p entry.
2241 * See also elm_entry_entry_set().
2243 * @param obj The entry object
2244 * @return The currently displayed text or NULL on failure
2249 elm_entry_entry_get(const Evas_Object *obj)
2251 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2252 Widget_Data *wd = elm_widget_data_get(obj);
2254 if (!wd) return NULL;
2255 if (wd->text) return wd->text;
2256 text = edje_object_part_text_get(wd->ent, "elm.text");
2259 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2262 eina_stringshare_replace(&wd->text, text);
2267 * This returns all selected text within the entry.
2269 * @param obj The entry object
2270 * @return The selected text within the entry or NULL on failure
2275 elm_entry_selection_get(const Evas_Object *obj)
2277 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2278 Widget_Data *wd = elm_widget_data_get(obj);
2279 if (!wd) return NULL;
2280 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2284 * This inserts text in @p entry at the beginning of the entry
2287 * @param obj The entry object
2288 * @param entry The text to insert
2293 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2295 ELM_CHECK_WIDTYPE(obj, widtype);
2296 Widget_Data *wd = elm_widget_data_get(obj);
2298 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2299 wd->changed = EINA_TRUE;
2304 * This enables word line wrapping in the entry object. It is the opposite
2305 * of elm_entry_single_line_set(). Additionally, setting this disables
2306 * character line wrapping.
2307 * See also elm_entry_line_char_wrap_set().
2309 * @param obj The entry object
2310 * @param wrap If true, the entry will be wrapped once it reaches the end
2311 * of the object. Wrapping will occur at the end of the word before the end of the
2317 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2319 ELM_CHECK_WIDTYPE(obj, widtype);
2320 Widget_Data *wd = elm_widget_data_get(obj);
2323 if (wd->linewrap == wrap) return;
2324 wd->linewrap = wrap;
2326 wd->char_linewrap = EINA_FALSE;
2327 t = eina_stringshare_add(elm_entry_entry_get(obj));
2328 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2329 elm_entry_entry_set(obj, t);
2330 eina_stringshare_del(t);
2335 * Set wrap width of the entry
2337 * @param obj The entry object
2338 * @param w The wrap width in pixels at a minimum where words need to wrap
2342 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2344 Widget_Data *wd = elm_widget_data_get(obj);
2345 if (wd->wrap_w == w) return;
2351 * get wrap width of the entry
2353 * @param obj The entry object
2354 * @return The wrap width in pixels at a minimum where words need to wrap
2358 elm_entry_wrap_width_get(const Evas_Object *obj)
2360 Widget_Data *wd = elm_widget_data_get(obj);
2365 * This enables character line wrapping in the entry object. It is the opposite
2366 * of elm_entry_single_line_set(). Additionally, setting this disables
2367 * word line wrapping.
2368 * See also elm_entry_line_wrap_set().
2370 * @param obj The entry object
2371 * @param wrap If true, the entry will be wrapped once it reaches the end
2372 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2377 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2379 ELM_CHECK_WIDTYPE(obj, widtype);
2380 Widget_Data *wd = elm_widget_data_get(obj);
2383 if (wd->char_linewrap == wrap) return;
2384 wd->char_linewrap = wrap;
2385 if(wd->char_linewrap)
2386 wd->linewrap = EINA_FALSE;
2387 t = eina_stringshare_add(elm_entry_entry_get(obj));
2388 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2389 elm_entry_entry_set(obj, t);
2390 eina_stringshare_del(t);
2395 * This sets the editable attribute of the entry.
2397 * @param obj The entry object
2398 * @param editable If true, the entry will be editable by the user.
2399 * If false, it will be set to the disabled state.
2404 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2406 ELM_CHECK_WIDTYPE(obj, widtype);
2407 Widget_Data *wd = elm_widget_data_get(obj);
2410 if (wd->editable == editable) return;
2411 wd->editable = editable;
2412 t = eina_stringshare_add(elm_entry_entry_get(obj));
2413 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2414 elm_entry_entry_set(obj, t);
2415 eina_stringshare_del(t);
2418 #ifdef HAVE_ELEMENTARY_X
2420 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2422 elm_drop_target_del(obj);
2427 * This gets the editable attribute of the entry.
2428 * See also elm_entry_editable_set().
2430 * @param obj The entry object
2431 * @return If true, the entry is editable by the user.
2432 * If false, it is not editable by the user
2437 elm_entry_editable_get(const Evas_Object *obj)
2439 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2440 Widget_Data *wd = elm_widget_data_get(obj);
2441 if (!wd) return EINA_FALSE;
2442 return wd->editable;
2446 * This drops any existing text selection within the entry.
2448 * @param obj The entry object
2453 elm_entry_select_none(Evas_Object *obj)
2455 ELM_CHECK_WIDTYPE(obj, widtype);
2456 Widget_Data *wd = elm_widget_data_get(obj);
2460 wd->selmode = EINA_FALSE;
2461 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2462 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2464 wd->have_selection = EINA_FALSE;
2465 edje_object_part_text_select_none(wd->ent, "elm.text");
2469 * This selects all text within the entry.
2471 * @param obj The entry object
2476 elm_entry_select_all(Evas_Object *obj)
2478 ELM_CHECK_WIDTYPE(obj, widtype);
2479 Widget_Data *wd = elm_widget_data_get(obj);
2483 wd->selmode = EINA_FALSE;
2484 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2485 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2487 wd->have_selection = EINA_TRUE;
2488 edje_object_part_text_select_all(wd->ent, "elm.text");
2492 * This moves the cursor one place to the right within the entry.
2494 * @param obj The entry object
2495 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2500 elm_entry_cursor_next(Evas_Object *obj)
2502 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2503 Widget_Data *wd = elm_widget_data_get(obj);
2504 if (!wd) return EINA_FALSE;
2505 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2509 * This moves the cursor one place to the left within the entry.
2511 * @param obj The entry object
2512 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2517 elm_entry_cursor_prev(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_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2526 * This moves the cursor one line up within the entry.
2528 * @param obj The entry object
2529 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2534 elm_entry_cursor_up(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_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2543 * This moves the cursor one line down within the entry.
2545 * @param obj The entry object
2546 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2551 elm_entry_cursor_down(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_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2560 * This moves the cursor to the beginning of the entry.
2562 * @param obj The entry object
2567 elm_entry_cursor_begin_set(Evas_Object *obj)
2569 ELM_CHECK_WIDTYPE(obj, widtype);
2570 Widget_Data *wd = elm_widget_data_get(obj);
2572 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2576 * This moves the cursor to the end of the entry.
2578 * @param obj The entry object
2583 elm_entry_cursor_end_set(Evas_Object *obj)
2585 ELM_CHECK_WIDTYPE(obj, widtype);
2586 Widget_Data *wd = elm_widget_data_get(obj);
2588 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2592 * This moves the cursor to the beginning of the current line.
2594 * @param obj The entry object
2599 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2601 ELM_CHECK_WIDTYPE(obj, widtype);
2602 Widget_Data *wd = elm_widget_data_get(obj);
2604 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2608 * This moves the cursor to the end of the current line.
2610 * @param obj The entry object
2615 elm_entry_cursor_line_end_set(Evas_Object *obj)
2617 ELM_CHECK_WIDTYPE(obj, widtype);
2618 Widget_Data *wd = elm_widget_data_get(obj);
2620 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2624 * This begins a selection within the entry as though
2625 * the user were holding down the mouse button to make a selection.
2627 * @param obj The entry object
2632 elm_entry_cursor_selection_begin(Evas_Object *obj)
2634 ELM_CHECK_WIDTYPE(obj, widtype);
2635 Widget_Data *wd = elm_widget_data_get(obj);
2637 edje_object_part_text_select_begin(wd->ent, "elm.text");
2641 * This ends a selection within the entry as though
2642 * the user had just released the mouse button while making a selection.
2644 * @param obj The entry object
2649 elm_entry_cursor_selection_end(Evas_Object *obj)
2651 ELM_CHECK_WIDTYPE(obj, widtype);
2652 Widget_Data *wd = elm_widget_data_get(obj);
2654 edje_object_part_text_select_extend(wd->ent, "elm.text");
2658 * TODO: fill this in
2660 * @param obj The entry object
2661 * @return TODO: fill this in
2666 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2668 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2669 Widget_Data *wd = elm_widget_data_get(obj);
2670 if (!wd) return EINA_FALSE;
2671 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2675 * This returns whether the cursor is visible.
2677 * @param obj The entry object
2678 * @return If true, the cursor is visible.
2683 elm_entry_cursor_is_visible_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_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2692 * TODO: fill this in
2694 * @param obj The entry object
2695 * @return TODO: fill this in
2700 elm_entry_cursor_content_get(const Evas_Object *obj)
2702 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2703 Widget_Data *wd = elm_widget_data_get(obj);
2704 if (!wd) return NULL;
2705 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2709 * This executes a "cut" action on the selected text in the entry.
2711 * @param obj The entry object
2716 elm_entry_selection_cut(Evas_Object *obj)
2718 ELM_CHECK_WIDTYPE(obj, widtype);
2719 Widget_Data *wd = elm_widget_data_get(obj);
2721 _cut(obj, NULL, NULL);
2725 * This executes a "copy" action on the selected text in the entry.
2727 * @param obj The entry object
2732 elm_entry_selection_copy(Evas_Object *obj)
2734 ELM_CHECK_WIDTYPE(obj, widtype);
2735 Widget_Data *wd = elm_widget_data_get(obj);
2737 _copy(obj, NULL, NULL);
2741 * This executes a "paste" action in the entry.
2743 * @param obj The entry object
2748 elm_entry_selection_paste(Evas_Object *obj)
2750 ELM_CHECK_WIDTYPE(obj, widtype);
2751 Widget_Data *wd = elm_widget_data_get(obj);
2753 _paste(obj, NULL, NULL);
2757 * This clears and frees the items in a entry's contextual (right click) menu.
2759 * @param obj The entry object
2764 elm_entry_context_menu_clear(Evas_Object *obj)
2766 ELM_CHECK_WIDTYPE(obj, widtype);
2767 Widget_Data *wd = elm_widget_data_get(obj);
2768 Elm_Entry_Context_Menu_Item *it;
2770 EINA_LIST_FREE(wd->items, it)
2772 eina_stringshare_del(it->label);
2773 eina_stringshare_del(it->icon_file);
2774 eina_stringshare_del(it->icon_group);
2780 * This adds an item to the entry's contextual menu.
2782 * @param obj The entry object
2783 * @param label The item's text label
2784 * @param icon_file The item's icon file
2785 * @param icon_type The item's icon type
2786 * @param func The callback to execute when the item is clicked
2787 * @param data The data to associate with the item for related functions
2792 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)
2794 ELM_CHECK_WIDTYPE(obj, widtype);
2795 Widget_Data *wd = elm_widget_data_get(obj);
2796 Elm_Entry_Context_Menu_Item *it;
2798 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2800 wd->items = eina_list_append(wd->items, it);
2802 it->label = eina_stringshare_add(label);
2803 it->icon_file = eina_stringshare_add(icon_file);
2804 it->icon_type = icon_type;
2806 it->data = (void *)data;
2810 * This disables the entry's contextual (right click) menu.
2812 * @param obj The entry object
2813 * @param disabled If true, the menu is disabled
2818 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2820 ELM_CHECK_WIDTYPE(obj, widtype);
2821 Widget_Data *wd = elm_widget_data_get(obj);
2823 if (wd->context_menu == !disabled) return;
2824 wd->context_menu = !disabled;
2828 * This returns whether the entry's contextual (right click) menu is disabled.
2830 * @param obj The entry object
2831 * @return If true, the menu is disabled
2836 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2838 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2839 Widget_Data *wd = elm_widget_data_get(obj);
2840 if (!wd) return EINA_FALSE;
2841 return !wd->context_menu;
2845 * This appends a custom item provider to the list for that entry
2847 * This appends the given callback. The list is walked from beginning to end
2848 * with each function called given the item href string in the text. If the
2849 * function returns an object handle other than NULL (it should create an
2850 * and object to do this), then this object is used to replace that item. If
2851 * not the next provider is called until one provides an item object, or the
2852 * default provider in entry does.
2854 * @param obj The entry object
2855 * @param func The function called to provide the item object
2856 * @param data The data passed to @p func
2861 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2863 ELM_CHECK_WIDTYPE(obj, widtype);
2864 Widget_Data *wd = elm_widget_data_get(obj);
2867 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2871 wd->item_providers = eina_list_append(wd->item_providers, ip);
2875 * This prepends a custom item provider to the list for that entry
2877 * This prepends the given callback. See elm_entry_item_provider_append() for
2880 * @param obj The entry object
2881 * @param func The function called to provide the item object
2882 * @param data The data passed to @p func
2887 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2889 ELM_CHECK_WIDTYPE(obj, widtype);
2890 Widget_Data *wd = elm_widget_data_get(obj);
2893 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2897 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2901 * This removes a custom item provider to the list for that entry
2903 * This removes the given callback. See elm_entry_item_provider_append() for
2906 * @param obj The entry object
2907 * @param func The function called to provide the item object
2908 * @param data The data passed to @p func
2913 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2915 ELM_CHECK_WIDTYPE(obj, widtype);
2916 Widget_Data *wd = elm_widget_data_get(obj);
2918 Elm_Entry_Item_Provider *ip;
2921 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2923 if ((ip->func == func) && (ip->data == data))
2925 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2933 * This converts a markup (HTML-like) string into UTF-8.
2935 * @param s The string (in markup) to be converted
2936 * @return The converted string (in UTF-8)
2941 elm_entry_markup_to_utf8(const char *s)
2943 char *ss = _mkup_to_text(s);
2944 if (!ss) ss = strdup("");
2949 * This converts a UTF-8 string into markup (HTML-like).
2951 * @param s The string (in UTF-8) to be converted
2952 * @return The converted string (in markup)
2957 elm_entry_utf8_to_markup(const char *s)
2959 char *ss = _text_to_mkup(s);
2960 if (!ss) ss = strdup("");
2965 * Get the input method context in the entry widget
2967 * @param obj The entry object
2968 * @return The input method context
2972 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2974 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2975 Widget_Data *wd = elm_widget_data_get(obj);
2976 if (!wd || !wd->ent) return NULL;
2978 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2982 * Set whether entry should enable the return key on soft keyboard automatically
2984 * @param obj The entry object
2985 * @param on If true, entry enables the return key on soft keyboard automatically.
2990 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
2992 ELM_CHECK_WIDTYPE(obj, widtype);
2993 Widget_Data *wd = elm_widget_data_get(obj);
2996 wd->autoreturnkey = on;
2997 _check_enable_returnkey(obj);
3001 * Set whether entry should support auto capitalization
3003 * @param obj The entry object
3004 * @param on If true, entry suports auto capitalization.
3009 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3011 ELM_CHECK_WIDTYPE(obj, widtype);
3012 Widget_Data *wd = elm_widget_data_get(obj);
3016 wd->autocapitalize = EINA_FALSE;
3018 wd->autocapitalize = autocap;
3020 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
3024 * Set whether entry should support auto period
3026 * @param obj The entry object
3027 * @param on If true, entry suports auto period.
3032 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3034 ELM_CHECK_WIDTYPE(obj, widtype);
3035 Widget_Data *wd = elm_widget_data_get(obj);
3039 wd->autoperiod = EINA_FALSE;
3041 wd->autoperiod = autoperiod;
3043 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3047 * Set the font size on the entry object
3049 * @param obj The entry object
3050 * @param size font size
3055 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3057 ELM_CHECK_WIDTYPE(obj, widtype);
3058 Widget_Data *wd = elm_widget_data_get(obj);
3059 Eina_Strbuf *fontbuf = NULL;
3064 t = eina_stringshare_add(elm_entry_entry_get(obj));
3065 fontbuf = eina_strbuf_new();
3066 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3068 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3070 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3072 elm_entry_entry_set(obj, t);
3076 eina_strbuf_free(fontbuf);
3077 eina_stringshare_del(t);
3081 * Set the text align on the entry object
3083 * @param obj The entry object
3084 * @param align align mode
3089 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3091 ELM_CHECK_WIDTYPE(obj, widtype);
3092 Widget_Data *wd = elm_widget_data_get(obj);
3097 t = eina_stringshare_add(elm_entry_entry_get(obj));
3099 if (len <= 0) return;
3101 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3102 elm_entry_entry_set(obj, t);
3106 eina_stringshare_del(t);
3110 * Set the text color on the entry object
3112 * @param obj The entry object
3113 * @param r Red property background color of The entry object
3114 * @param g Green property background color of The entry object
3115 * @param b Blue property background color of The entry object
3116 * @param a Alpha property background alpha of The entry object
3121 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3123 ELM_CHECK_WIDTYPE(obj, widtype);
3124 Widget_Data *wd = elm_widget_data_get(obj);
3125 Eina_Strbuf *colorbuf = NULL;
3130 t = eina_stringshare_add(elm_entry_entry_get(obj));
3132 if (len <= 0) return;
3133 colorbuf = eina_strbuf_new();
3134 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3136 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3138 elm_entry_entry_set(obj, t);
3142 eina_strbuf_free(colorbuf);
3143 eina_stringshare_del(t);
3148 * Set background color of the entry
3150 * @param obj The entry object
3151 * @param r Red property background color of The entry object
3152 * @param g Green property background color of The entry object
3153 * @param b Blue property background color of The entry object
3154 * @param a Alpha property background alpha of The entry object
3158 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3160 ELM_CHECK_WIDTYPE(obj, widtype);
3161 Widget_Data *wd = elm_widget_data_get(obj);
3162 evas_object_color_set(wd->bg, r, g, b, a);
3164 if (wd->bgcolor == EINA_FALSE)
3167 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3172 * Set the ellipsis behavior of the entry
3174 * @param obj The entry object
3175 * @param ellipsis To ellipsis text or not
3179 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3181 ELM_CHECK_WIDTYPE(obj, widtype);
3182 Widget_Data *wd = elm_widget_data_get(obj);
3183 if (wd->ellipsis == ellipsis) return;
3184 wd->ellipsis = ellipsis;
3190 * This sets the attribute to show the input panel automatically.
3192 * @param obj The entry object
3193 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3198 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3200 ELM_CHECK_WIDTYPE(obj, widtype);
3201 Widget_Data *wd = elm_widget_data_get(obj);
3204 wd->input_panel_enable = enabled;
3205 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3209 * Set the input panel layout of the entry
3211 * @param obj The entry object
3212 * @param layout the layout to set
3217 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3219 ELM_CHECK_WIDTYPE(obj, widtype);
3220 Widget_Data *wd = elm_widget_data_get(obj);
3223 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3226 wd->input_panel_layout = layout;
3228 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3231 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/