54f808230555107bae6f07bb1b20f952dbb1e1f5
[framework/uifw/elementary.git] / src / lib / elm_entry.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4 #include <Elementary.h>
5 #include "elm_priv.h"
6 #include "elm_module_priv.h"
7 /**
8  * @defgroup Entry Entry
9  * @ingroup Elementary
10  *
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
16  * own length.
17  * 
18  * You can also insert "items" in the entry with:
19  * 
20  * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
21  * 
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:
25  * 
26  * - emoticon/angry
27  * - emoticon/angry-shout
28  * - emoticon/crazy-laugh
29  * - emoticon/evil-laugh
30  * - emoticon/evil
31  * - emoticon/goggle-smile
32  * - emoticon/grumpy
33  * - emoticon/grumpy-smile
34  * - emoticon/guilty
35  * - emoticon/guilty-smile
36  * - emoticon/haha
37  * - emoticon/half-smile
38  * - emoticon/happy-panting
39  * - emoticon/happy
40  * - emoticon/indifferent
41  * - emoticon/kiss
42  * - emoticon/knowing-grin
43  * - emoticon/laugh
44  * - emoticon/little-bit-sorry
45  * - emoticon/love-lots
46  * - emoticon/love
47  * - emoticon/minimal-smile
48  * - emoticon/not-happy
49  * - emoticon/not-impressed
50  * - emoticon/omg
51  * - emoticon/opensmile
52  * - emoticon/smile
53  * - emoticon/sorry
54  * - emoticon/squint-laugh
55  * - emoticon/surprised
56  * - emoticon/suspicious
57  * - emoticon/tongue-dangling
58  * - emoticon/tongue-poke
59  * - emoticon/uh
60  * - emoticon/unhappy
61  * - emoticon/very-sorry
62  * - emoticon/what
63  * - emoticon/wink
64  * - emoticon/worried
65  * - emoticon/wtf
66  *
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.
70  * 
71  * See the entry test for some more examples of use of this.
72  * 
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
90  */
91
92 typedef struct _Mod_Api Mod_Api;
93
94 typedef struct _Widget_Data Widget_Data;
95 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
96
97 struct _Widget_Data
98 {
99    Evas_Object *ent;
100    Evas_Object *popup;/*copy paste UI - elm_popup*/
101    Evas_Object *ctxpopup;/*copy paste UI - elm_ctxpopup*/
102    Evas_Object *bg;   
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    const char *cut_sel;
109    const char *text;
110    Evas_Coord wrap_w;
111    Evas_Coord lastw;
112    Evas_Coord downx, downy;
113    Evas_Coord cx, cy, cw, ch;
114    Eina_List *items;
115    Eina_List *item_providers;
116    Mod_Api *api; // module api if supplied
117    int max_no_of_bytes;
118    Eina_Bool changed : 1;
119    Eina_Bool linewrap : 1;
120    Eina_Bool char_linewrap : 1;
121    Eina_Bool single_line : 1;
122    Eina_Bool password : 1;
123    Eina_Bool show_last_character : 1;
124    Eina_Bool editable : 1;
125    Eina_Bool selection_asked : 1;
126    Eina_Bool have_selection : 1;
127    Eina_Bool selmode : 1;
128    Eina_Bool deferred_cur : 1;
129    Eina_Bool disabled : 1;
130    Eina_Bool context_menu : 1;
131    Eina_Bool bgcolor : 1;
132    Eina_Bool ellipsis : 1;
133    Eina_Bool autoreturnkey : 1;
134    Eina_Bool input_panel_enable : 1;
135 };
136
137 struct _Elm_Entry_Item_Provider
138 {
139    Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
140    void *data;
141 };
142
143 static const char *widtype = NULL;
144 static void _del_hook(Evas_Object *obj);
145 static void _theme_hook(Evas_Object *obj);
146 static void _disable_hook(Evas_Object *obj);
147 static void _sizing_eval(Evas_Object *obj);
148 static void _on_focus_hook(void *data, Evas_Object *obj);
149 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
150 static const char *_getbase(Evas_Object *obj);
151 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
152 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
153 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
154 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
155 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
156 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
157 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
158 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
159 static int _get_value_in_key_string(char *oldstring, char *key, char *value);
160 static int _string_key_value_replace(char *oldstring, char *key, char *value, char *tagstring);
161 static int _is_width_over(Evas_Object *obj);
162 static void _ellipsis_entry_to_width(Evas_Object *obj);
163 static int _textinput_control_function(void *data,void *input_data);
164 static int _entry_length_get(Evas_Object *obj);
165
166 #define MIN_ENTRY_FONT_SIZE 8
167 #define MAX_ENTRY_FONT_SIZE 60
168
169 static const char SIG_CHANGED[] = "changed";
170 static const char SIG_ACTIVATED[] = "activated";
171 static const char SIG_PRESS[] = "press";
172 static const char SIG_LONGPRESSED[] = "longpressed";
173 static const char SIG_CLICKED[] = "clicked";
174 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
175 static const char SIG_FOCUSED[] = "focused";
176 static const char SIG_UNFOCUSED[] = "unfocused";
177 static const char SIG_SELECTION_PASTE[] = "selection,paste";
178 static const char SIG_SELECTION_COPY[] = "selection,copy";
179 static const char SIG_SELECTION_CUT[] = "selection,cut";
180 static const char SIG_SELECTION_START[] = "selection,start";
181 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
182 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
183 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
184 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
185 static const Evas_Smart_Cb_Description _signals[] = {
186   {SIG_CHANGED, ""},
187   {SIG_ACTIVATED, ""},
188   {SIG_PRESS, ""},
189   {SIG_LONGPRESSED, ""},
190   {SIG_CLICKED, ""},
191   {SIG_CLICKED_DOUBLE, ""},
192   {SIG_FOCUSED, ""},
193   {SIG_UNFOCUSED, ""},
194   {SIG_SELECTION_PASTE, ""},
195   {SIG_SELECTION_COPY, ""},
196   {SIG_SELECTION_CUT, ""},
197   {SIG_SELECTION_START, ""},
198   {SIG_SELECTION_CHANGED, ""},
199   {SIG_SELECTION_CLEARED, ""},
200   {SIG_CURSOR_CHANGED, ""},
201   {SIG_ANCHOR_CLICKED, ""},
202   {NULL, NULL}
203 };
204
205 static Eina_List *entries = NULL;
206
207 struct _Mod_Api
208 {
209    void (*obj_hook) (Evas_Object *obj);
210    void (*obj_unhook) (Evas_Object *obj);
211    void (*obj_longpress) (Evas_Object *obj);
212         void (*obj_mouseup) (Evas_Object *obj);
213 };
214
215 static Mod_Api *
216 _module(Evas_Object *obj __UNUSED__)
217 {
218    static Elm_Module *m = NULL;
219    if (m) goto ok; // already found - just use
220    if (!(m = _elm_module_find_as("entry/api"))) return NULL;
221    // get module api
222    m->api = malloc(sizeof(Mod_Api));
223    if (!m->api) return NULL;
224    ((Mod_Api *)(m->api)      )->obj_hook = // called on creation
225      _elm_module_symbol_get(m, "obj_hook");
226    ((Mod_Api *)(m->api)      )->obj_unhook = // called on deletion
227      _elm_module_symbol_get(m, "obj_unhook");
228    ((Mod_Api *)(m->api)      )->obj_longpress = // called on long press menu
229      _elm_module_symbol_get(m, "obj_longpress");
230     ((Mod_Api *)(m->api)      )->obj_mouseup = // called on mouseup
231    _elm_module_symbol_get(m, "obj_mouseup");
232    ok: // ok - return api
233    return m->api;
234 }
235
236 static void
237 _del_hook(Evas_Object *obj)
238 {
239    Widget_Data *wd = elm_widget_data_get(obj);
240    Elm_Entry_Context_Menu_Item *it;
241    Elm_Entry_Item_Provider *ip;
242
243    if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
244
245    entries = eina_list_remove(entries, obj);
246 #ifdef HAVE_ELEMENTARY_X
247    ecore_event_handler_del(wd->sel_notify_handler);
248    ecore_event_handler_del(wd->sel_clear_handler);
249 #endif
250    if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
251    if (wd->text) eina_stringshare_del(wd->text);
252    if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
253    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
254    EINA_LIST_FREE(wd->items, it)
255      {
256         eina_stringshare_del(it->label);
257         eina_stringshare_del(it->icon_file);
258         eina_stringshare_del(it->icon_group);
259         free(it);
260      }
261    EINA_LIST_FREE(wd->item_providers, ip)
262      {
263         free(ip);
264      }
265    free(wd);
266 }
267
268 static void
269 _theme_hook(Evas_Object *obj)
270 {
271    Widget_Data *wd = elm_widget_data_get(obj);
272    const char *t;
273
274    t = eina_stringshare_add(elm_entry_entry_get(obj));
275    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
276    elm_entry_entry_set(obj, t);
277    eina_stringshare_del(t);
278    edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
279    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
280
281    _sizing_eval(obj);
282 }
283
284 static void
285 _disable_hook(Evas_Object *obj)
286 {
287    Widget_Data *wd = elm_widget_data_get(obj);
288
289    if (elm_widget_disabled_get(obj))
290      {
291         edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
292         wd->disabled = EINA_TRUE;
293      }
294    else
295      {
296         edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
297         wd->disabled = EINA_FALSE;
298      }
299 }
300
301 static void
302 _elm_win_recalc_job(void *data)
303 {
304    Widget_Data *wd = elm_widget_data_get(data);
305    Evas_Coord minw = -1, minh = -1, maxh = -1;
306    Evas_Coord resw, resh, minminw;
307    if (!wd) return;
308    wd->deferred_recalc_job = NULL;
309    evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
310    resh = 0;
311    minminw = 0;
312    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
313    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
314    minminw = minw;
315    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
316    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
317    evas_object_size_hint_min_set(data, minminw, minh);
318    if (wd->single_line) maxh = minh;
319    evas_object_size_hint_max_set(data, -1, maxh);
320    if (wd->deferred_cur)
321      elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
322 }
323
324 static void
325 _sizing_eval(Evas_Object *obj)
326 {
327    Widget_Data *wd = elm_widget_data_get(obj);
328    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
329    Evas_Coord resw, resh;
330    if (!wd) return;
331    if (wd->linewrap || wd->char_linewrap)
332      {
333         evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
334         if ((resw == wd->lastw) && (!wd->changed)) return;
335         wd->changed = EINA_FALSE;
336         wd->lastw = resw;
337         if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
338         wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
339      }
340    else
341      {
342         evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
343         edje_object_size_min_calc(wd->ent, &minw, &minh);
344         elm_coords_finger_size_adjust(1, &minw, 1, &minh);
345         evas_object_size_hint_min_set(obj, minw, minh);
346         if (wd->single_line) maxh = minh;
347         evas_object_size_hint_max_set(obj, maxw, maxh);
348
349         if (wd->ellipsis && wd->single_line)
350           {
351             if (_is_width_over(obj) == 1)
352             {
353               _ellipsis_entry_to_width(obj);
354             }
355           }
356      }
357 }
358
359 static void
360 _check_enable_returnkey(Evas_Object *obj)
361 {
362     Widget_Data *wd = elm_widget_data_get(obj);
363     if (!wd) return;
364
365     Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
366     if (!ic) return;
367
368    if (!wd->autoreturnkey) return;
369
370    if (_entry_length_get(obj) == 0) 
371      {
372         ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
373      }
374    else 
375      {
376         ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
377      }
378 }
379
380 static void
381 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
382 {
383    Widget_Data *wd = elm_widget_data_get(obj);
384    Evas_Object *top = elm_widget_top_get(obj);
385    if (!wd) return;
386    if (!wd->editable) return;
387    if (elm_widget_focus_get(obj))
388      {
389         evas_object_focus_set(wd->ent, 1);
390         edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
391         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
392         evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
393         _check_enable_returnkey(obj);
394      }
395    else
396      {
397         edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
398         edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", "");
399         evas_object_focus_set(wd->ent, 0);
400         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
401         evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
402      }
403 }
404
405 static void
406 _hoversel_position(Evas_Object *obj)
407 {
408    Widget_Data *wd = elm_widget_data_get(obj);
409    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
410    if (!wd) return;
411    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
412    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
413                                              &cx, &cy, &cw, &ch);
414    evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
415    if (cw < mw)
416      {
417         cx += (cw - mw) / 2;
418         cw = mw;
419      }
420    if (ch < mh)
421      {
422         cy += (ch - mh) / 2;
423         ch = mh;
424      }
425    evas_object_move(wd->hoversel, x + cx, y + cy);
426    evas_object_resize(wd->hoversel, cw, ch);
427 }
428
429 static void
430 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
431 {
432    Widget_Data *wd = elm_widget_data_get(data);
433
434    if (wd->hoversel) _hoversel_position(data);
435 }
436
437 static void
438 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
439 {
440    Widget_Data *wd = elm_widget_data_get(data);
441    if (!wd) return;
442    if (wd->linewrap || wd->char_linewrap)
443      {
444         _sizing_eval(data);
445      }
446    if (wd->hoversel) _hoversel_position(data);
447 //   Evas_Coord ww, hh;
448 //   evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
449 }
450
451 static void
452 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
453 {
454    Widget_Data *wd = elm_widget_data_get(data);
455    if (!wd) return;
456    if (wd->hoversel) evas_object_hide(wd->hoversel);
457    if (wd->selmode)
458      {
459         if (!wd->password)
460           edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
461      }
462    elm_widget_scroll_freeze_pop(data);
463 }
464
465 static void
466 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
467 {
468    Widget_Data *wd = elm_widget_data_get(data);
469    if (!wd) return;
470    wd->selmode = EINA_TRUE;
471    edje_object_part_text_select_none(wd->ent, "elm.text");
472    if (!wd->password)
473      edje_object_part_text_select_allow_set(wd->ent, "elm.text", 1);
474    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
475    elm_widget_scroll_hold_push(data);
476 }
477
478 static void
479 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
480 {
481    Widget_Data *wd = elm_widget_data_get(data);
482    if (!wd) return;
483    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
484    if (wd->sel_notify_handler)
485      {
486 #ifdef HAVE_ELEMENTARY_X
487         Evas_Object *top;
488
489         top = elm_widget_top_get(data);
490         if ((top) && (elm_win_xwindow_get(top)))
491           {
492              ecore_x_selection_primary_request
493                (elm_win_xwindow_get(top),
494                 ECORE_X_SELECTION_TARGET_UTF8_STRING);
495              wd->selection_asked = EINA_TRUE;
496           }
497 #endif
498      }
499 }
500
501 static void
502 _store_selection(Evas_Object *obj)
503 {
504    Widget_Data *wd = elm_widget_data_get(obj);
505    const char *sel;
506
507    if (!wd) return;
508    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
509    eina_stringshare_replace(&wd->cut_sel, sel);
510 }
511
512 static void
513 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
514 {
515    Widget_Data *wd = elm_widget_data_get(data);
516
517    wd->selmode = EINA_FALSE;
518    edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
519    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
520    elm_widget_scroll_hold_pop(data);
521    _store_selection(data);
522    edje_object_part_text_insert(wd->ent, "elm.text", "");
523    edje_object_part_text_select_none(wd->ent, "elm.text");
524 }
525
526 static void
527 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
528 {
529    Widget_Data *wd = elm_widget_data_get(data);
530    if (!wd) return;
531    wd->selmode = EINA_FALSE;
532    edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
533    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
534    elm_widget_scroll_hold_pop(data);
535    _store_selection(data);
536    edje_object_part_text_select_none(wd->ent, "elm.text");
537 }
538
539 static void
540 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
541 {
542    Widget_Data *wd = elm_widget_data_get(data);
543    if (!wd) return;
544    wd->selmode = EINA_FALSE;
545    edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
546    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
547    elm_widget_scroll_hold_pop(data);
548    edje_object_part_text_select_none(wd->ent, "elm.text");
549 }
550
551 static void
552 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
553 {
554    Elm_Entry_Context_Menu_Item *it = data;
555    Evas_Object *obj2 = it->obj;
556    if (it->func) it->func(it->data, obj2, NULL);
557 }
558
559 static int
560 _long_press(void *data)
561 {
562    Widget_Data *wd = elm_widget_data_get(data);
563    Evas_Object *top;
564    const Eina_List *l;
565    const Elm_Entry_Context_Menu_Item *it;
566    if (!wd) return 0;
567    if ((wd->api) && (wd->api->obj_longpress))
568      {
569         wd->api->obj_longpress(data);
570      }
571    else if (wd->context_menu)
572      {
573         const char *context_menu_orientation;
574
575         if (wd->hoversel) evas_object_del(wd->hoversel);
576         else elm_widget_scroll_freeze_push(data);
577         wd->hoversel = elm_hoversel_add(data);
578         context_menu_orientation = edje_object_data_get
579           (wd->ent, "context_menu_orientation");
580         if ((context_menu_orientation) &&
581             (!strcmp(context_menu_orientation, "horizontal")))
582           elm_hoversel_horizontal_set(wd->hoversel, 1);
583         elm_object_style_set(wd->hoversel, "entry");
584         elm_widget_sub_object_add(data, wd->hoversel);
585         elm_hoversel_label_set(wd->hoversel, "Text");
586         top = elm_widget_top_get(data);
587         if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
588         evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
589         if (!wd->selmode)
590           {
591              if (!wd->password)
592                elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
593                                      _select, data);
594              if (1) // need way to detect if someone has a selection
595                {
596                   if (wd->editable)
597                     elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
598                                           _paste, data);
599                }
600           }
601         else
602           {
603              if (!wd->password)
604                {
605                   if (wd->have_selection)
606                     {
607                        elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
608                                              _copy, data);
609                        if (wd->editable)
610                          elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
611                                                _cut, data);
612                     }
613                   elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
614                                         _cancel, data);
615                }
616           }
617         EINA_LIST_FOREACH(wd->items, l, it)
618           {
619              elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
620                                    it->icon_type, _item_clicked, it);
621           }
622         if (wd->hoversel)
623           {
624              _hoversel_position(data);
625              evas_object_show(wd->hoversel);
626              elm_hoversel_hover_begin(wd->hoversel);
627           }
628         edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
629         edje_object_part_text_select_abort(wd->ent, "elm.text");
630      }
631    wd->longpress_timer = NULL;
632    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
633    return 0;
634 }
635
636 static void
637 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
638 {
639    Widget_Data *wd = elm_widget_data_get(data);
640    Evas_Event_Mouse_Down *ev = event_info;
641    if (!wd) return;
642    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
643    if (ev->button != 1) return;
644    //   if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
645    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
646    wd->longpress_timer = ecore_timer_add(1.0, _long_press, data);
647    wd->downx = ev->canvas.x;
648    wd->downy = ev->canvas.y;
649 }
650
651 static void
652 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
653 {
654    Widget_Data *wd = elm_widget_data_get(data);
655    Evas_Event_Mouse_Up *ev = event_info;
656    if (!wd) return;
657    if (ev->button != 1) return;
658    if ((wd->api) && (wd->api->obj_mouseup))
659      {
660         wd->api->obj_mouseup(data);
661      } 
662    if (wd->longpress_timer)
663      {
664         ecore_timer_del(wd->longpress_timer);
665         wd->longpress_timer = NULL;
666      }  
667 }
668
669 static void
670 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
671 {
672    Widget_Data *wd = elm_widget_data_get(data);
673    Evas_Event_Mouse_Move *ev = event_info;
674    if (!wd) return;
675    if (!wd->selmode)
676      {
677         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
678           {
679              if (wd->longpress_timer)
680                {
681                   ecore_timer_del(wd->longpress_timer);
682                   wd->longpress_timer = NULL;
683                }
684           }
685         else if (wd->longpress_timer)
686           {
687              Evas_Coord dx, dy;
688
689              dx = wd->downx - ev->cur.canvas.x;
690              dx *= dx;
691              dy = wd->downy - ev->cur.canvas.y;
692              dy *= dy;
693              if ((dx + dy) >
694                  ((_elm_config->finger_size / 2) *
695                   (_elm_config->finger_size / 2)))
696                {
697                   ecore_timer_del(wd->longpress_timer);
698                   wd->longpress_timer = NULL;
699                }
700           }
701      }
702    else if (wd->longpress_timer)
703      {
704         Evas_Coord dx, dy;
705
706         dx = wd->downx - ev->cur.canvas.x;
707         dx *= dx;
708         dy = wd->downy - ev->cur.canvas.y;
709         dy *= dy;
710         if ((dx + dy) >
711             ((_elm_config->finger_size / 2) *
712              (_elm_config->finger_size / 2)))
713           {
714              ecore_timer_del(wd->longpress_timer);
715              wd->longpress_timer = NULL;
716           }
717      }
718 }
719
720 static const char *
721 _getbase(Evas_Object *obj)
722 {
723    Widget_Data *wd = elm_widget_data_get(obj);
724    if (!wd) return "base";
725    if (wd->editable)
726      {
727         if((wd->password)&&(wd->show_last_character)) return "custom-password"; 
728         else if(wd->password) return "base-password";
729         else
730           {
731              if (wd->single_line) return "base-single";
732              else
733                {
734                   if (wd->linewrap) return "base";
735                   else if (wd->char_linewrap) return "base-charwrap";
736                   else  return "base-nowrap";
737                }
738           }
739      }
740    else
741      {
742         if((wd->password)&&(wd->show_last_character)) return "custom-password"; 
743         else if(wd->password) return "base-password";
744         else
745           {
746              if (wd->single_line) return "base-single-noedit";
747              else
748                {
749                   if (wd->linewrap) return "base-noedit";
750                   else if (wd->char_linewrap) return "base-noedit-charwrap";
751                   else  return "base-nowrap-noedit";
752                }
753           }
754      }
755    return "base";
756 }
757
758 static char *
759 _str_append(char *str, const char *txt, int *len, int *alloc)
760 {
761    int txt_len = strlen(txt);
762
763    if (txt_len <= 0) return str;
764    if ((*len + txt_len) >= *alloc)
765      {
766         char *str2;
767         int alloc2;
768
769         alloc2 = *alloc + txt_len + 128;
770         str2 = realloc(str, alloc2);
771         if (!str2) return str;
772         *alloc = alloc2;
773         str = str2;
774      }
775    strcpy(str + *len, txt);
776    *len += txt_len;
777    return str;
778 }
779
780 static char *
781 _strncpy(char* dest, const char* src, size_t count)
782 {
783    if (!dest) 
784      {
785         ERR( "dest is NULL" );
786         return NULL;
787      }
788    if (!src) 
789      {
790         ERR( "src is NULL" );
791         return NULL;
792      }
793    if (count < 0)
794      {
795         ERR( "count is smaller than 0" );
796         return NULL;
797      }
798
799    return strncpy( dest, src, count );
800 }
801
802 static char *
803 _mkup_to_text(const char *mkup)
804 {
805    char *str = NULL;
806    int str_len = 0, str_alloc = 0;
807    char *s, *p;
808    char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
809
810    if (!mkup) return NULL;
811    s=p=NULL;
812    tag_start = tag_end = esc_start = esc_end = NULL;
813    p = (char *)mkup;
814    s = p;
815    for (;;)
816      {
817         if (((p!=NULL)&&(*p == 0)) ||
818             (tag_end) || (esc_end) ||
819             (tag_start) || (esc_start))
820           {
821              if (tag_end)
822                {
823                   char *ttag;
824
825                   ttag = malloc(tag_end - tag_start);
826                   if (ttag)
827                     {
828                        _strncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
829                        ttag[tag_end - tag_start - 1] = 0;
830                        if (!strcmp(ttag, "br"))
831                          str = _str_append(str, "\n", &str_len, &str_alloc);
832                        else if (!strcmp(ttag, "\n"))
833                          str = _str_append(str, "\n", &str_len, &str_alloc);
834                        else if (!strcmp(ttag, "\\n"))
835                          str = _str_append(str, "\n", &str_len, &str_alloc);
836                        else if (!strcmp(ttag, "\t"))
837                          str = _str_append(str, "\t", &str_len, &str_alloc);
838                        else if (!strcmp(ttag, "\\t"))
839                          str = _str_append(str, "\t", &str_len, &str_alloc);
840                        free(ttag);
841                     }
842                   tag_start = tag_end = NULL;
843                }
844              else if (esc_end)
845                {
846                   ts = malloc(esc_end - esc_start + 1);
847                   if (ts)
848                     {
849                        const char *esc;
850                        _strncpy(ts, esc_start, esc_end - esc_start);
851                        ts[esc_end - esc_start] = 0;
852                        esc = evas_textblock_escape_string_get(ts);
853                        if (esc)
854                          str = _str_append(str, esc, &str_len, &str_alloc);
855                        free(ts);
856                     }
857                   esc_start = esc_end = NULL;
858                }
859              else if ((p!=NULL)&&(*p == 0))
860                {
861                   ts = malloc(p - s + 1);
862                   if (ts)
863                     {
864                        _strncpy(ts, s, p - s);
865                        ts[p - s] = 0;
866                        str = _str_append(str, ts, &str_len, &str_alloc);
867                        free(ts);
868                     }
869                   break;
870                }
871           }
872         if ((p!=NULL)&&(*p == '<'))
873           {
874              if (!esc_start)
875                {
876                   tag_start = p;
877                   tag_end = NULL;
878                   ts = malloc(p - s + 1);
879                   if (ts)
880                     {
881                        _strncpy(ts, s, p - s);
882                        ts[p - s] = 0;
883                        str = _str_append(str, ts, &str_len, &str_alloc);
884                        free(ts);
885                     }
886                   s = NULL;
887                }
888           }
889         else if ((p!=NULL)&&(*p == '>'))
890           {
891              if (tag_start)
892                {
893                   tag_end = p;
894                   s = p + 1;
895                }
896           }
897         else if ((p!=NULL)&&(*p == '&'))
898           {
899              if (!tag_start)
900                {
901                   esc_start = p;
902                   esc_end = NULL;
903                   ts = malloc(p - s + 1);
904                   if (ts)
905                     {
906                        _strncpy(ts, s, p - s);
907                        ts[p - s] = 0;
908                        str = _str_append(str, ts, &str_len, &str_alloc);
909                        free(ts);
910                     }
911                   s = NULL;
912                }
913           }
914         else if ((p!=NULL)&&(*p == ';'))
915           {
916              if (esc_start)
917                {
918                   esc_end = p;
919                   s = p + 1;
920                }
921           }
922         p++;
923      }
924    return str;
925 }
926
927 static int
928 _entry_length_get(Evas_Object *obj)
929 {
930    int len;
931    char *str = elm_entry_entry_get(obj);
932    if (!str) return 0;
933
934    char *plain_str = _mkup_to_text(str);
935    if (!plain_str) return 0;
936
937    len = strlen(plain_str);
938    free(plain_str);
939
940    return len;
941 }
942
943 static char *
944 _text_to_mkup(const char *text)
945 {
946    char *str = NULL;
947    int str_len = 0, str_alloc = 0;
948    int ch, pos = 0, pos2 = 0;
949
950    if (!text) return NULL;
951    for (;;)
952      {
953         pos = pos2;
954         pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
955         if ((ch <= 0) || (pos2 <= 0)) break;
956         if (ch == '\n')
957           str = _str_append(str, "<br>", &str_len, &str_alloc);
958         else if (ch == '\t')
959           str = _str_append(str, "<\t>", &str_len, &str_alloc);
960         else if (ch == '<')
961           str = _str_append(str, "&lt;", &str_len, &str_alloc);
962         else if (ch == '>')
963           str = _str_append(str, "&gt;", &str_len, &str_alloc);
964         else if (ch == '&')
965           str = _str_append(str, "&amp;", &str_len, &str_alloc);
966         else
967           {
968              char tstr[16];
969
970              _strncpy(tstr, text + pos, pos2 - pos);
971              tstr[pos2 - pos] = 0;
972              str = _str_append(str, tstr, &str_len, &str_alloc);
973           }
974      }
975    return str;
976 }
977
978 static void
979 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
980 {
981    Widget_Data *wd = elm_widget_data_get(data);
982    if (!wd) return;
983    wd->changed = EINA_TRUE;
984    _sizing_eval(data);
985    if (wd->text) eina_stringshare_del(wd->text);
986    wd->text = NULL;
987    evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
988    
989    _check_enable_returnkey(data);
990 }
991
992 static void
993 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
994 {
995    Widget_Data *wd = elm_widget_data_get(data);
996    const Eina_List *l;
997    Evas_Object *entry;
998    if (!wd) return;
999    EINA_LIST_FOREACH(entries, l, entry)
1000      {
1001         if (entry != data) elm_entry_select_none(entry);
1002      }
1003    wd->have_selection = EINA_TRUE;
1004    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1005    if (wd->sel_notify_handler)
1006      {
1007         char *txt = _mkup_to_text(elm_entry_selection_get(data));
1008
1009         if (txt)
1010           {
1011 #ifdef HAVE_ELEMENTARY_X
1012              Evas_Object *top;
1013
1014              top = elm_widget_top_get(data);
1015              if ((top) && (elm_win_xwindow_get(top)))
1016                ecore_x_selection_primary_set(elm_win_xwindow_get(top), txt,
1017                                              strlen(txt));
1018 #endif
1019              free(txt);
1020           }
1021      }
1022 }
1023
1024 static void
1025 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1026 {
1027    Widget_Data *wd = elm_widget_data_get(data);
1028    if (!wd) return;
1029    wd->have_selection = EINA_TRUE;
1030    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1031    if (wd->sel_notify_handler)
1032      {
1033         char *txt = _mkup_to_text(elm_entry_selection_get(data));
1034
1035         if (txt)
1036           {
1037 #ifdef HAVE_ELEMENTARY_X
1038              Evas_Object *top;
1039
1040              top = elm_widget_top_get(data);
1041              if ((top) && (elm_win_xwindow_get(top)))
1042                ecore_x_selection_primary_set(elm_win_xwindow_get(top), txt,
1043                                              strlen(txt));
1044 #endif
1045              free(txt);
1046           }
1047      }
1048 }
1049
1050 static void
1051 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1052 {
1053    Widget_Data *wd = elm_widget_data_get(data);
1054    if (!wd) return;
1055    if (!wd->have_selection) return;
1056    wd->have_selection = EINA_FALSE;
1057    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1058    if (wd->sel_notify_handler)
1059      {
1060         if (wd->cut_sel)
1061           {
1062 #ifdef HAVE_ELEMENTARY_X
1063              Evas_Object *top;
1064
1065              top = elm_widget_top_get(data);
1066              if ((top) && (elm_win_xwindow_get(top)))
1067                {
1068                   char *t;
1069
1070                   t = _mkup_to_text(wd->cut_sel);
1071                   if (t)
1072                     {
1073                        ecore_x_selection_primary_set(elm_win_xwindow_get(top),
1074                                                      t, strlen(t));
1075                        free(t);
1076                     }
1077                }
1078 #endif
1079              eina_stringshare_del(wd->cut_sel);
1080              wd->cut_sel = NULL;
1081           }
1082         else
1083           {
1084 #ifdef HAVE_ELEMENTARY_X
1085              Evas_Object *top;
1086
1087              top = elm_widget_top_get(data);
1088              if ((top) && (elm_win_xwindow_get(top)))
1089                ecore_x_selection_primary_clear();
1090 #endif
1091           }
1092      }
1093 }
1094
1095 static void
1096 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1097 {
1098    Widget_Data *wd = elm_widget_data_get(data);
1099    if (!wd) return;
1100    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1101    if (wd->sel_notify_handler)
1102      {
1103 #ifdef HAVE_ELEMENTARY_X
1104         Evas_Object *top;
1105
1106         top = elm_widget_top_get(data);
1107         if ((top) && (elm_win_xwindow_get(top)))
1108           {
1109              ecore_x_selection_primary_request(elm_win_xwindow_get(top),
1110                                                ECORE_X_SELECTION_TARGET_UTF8_STRING);
1111              wd->selection_asked = EINA_TRUE;
1112           }
1113 #endif
1114      }
1115 }
1116
1117 static void
1118 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1119 {
1120    Widget_Data *wd = elm_widget_data_get(data);
1121    if (!wd) return;
1122    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1123 }
1124
1125 static void
1126 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1127 {
1128    Widget_Data *wd = elm_widget_data_get(data);
1129    char *txt;
1130    if (!wd) return;
1131    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1132    txt = _mkup_to_text(elm_entry_selection_get(data));
1133    eina_stringshare_replace(&wd->cut_sel, txt);
1134    if (txt) free(txt);
1135    edje_object_part_text_insert(wd->ent, "elm.text", "");
1136    wd->changed = EINA_TRUE;
1137    _sizing_eval(data);
1138 }
1139
1140 static void
1141 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1142 {
1143    Widget_Data *wd = elm_widget_data_get(data);
1144    Evas_Coord cx, cy, cw, ch;
1145    if (!wd) return;
1146    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1147    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1148                                              &cx, &cy, &cw, &ch);
1149    if (!wd->deferred_recalc_job)
1150      elm_widget_show_region_set(data, cx, cy, cw, ch);
1151    else
1152      {
1153         wd->deferred_cur = EINA_TRUE;
1154         wd->cx = cx;
1155         wd->cy = cy;
1156         wd->cw = cw;
1157         wd->ch = ch;
1158      }
1159 }
1160
1161 static void
1162 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1163 {
1164    Widget_Data *wd = elm_widget_data_get(data);
1165    if (!wd) return;
1166 }
1167
1168 static void
1169 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1170 {
1171    Widget_Data *wd = elm_widget_data_get(data);
1172    Elm_Entry_Anchor_Info ei;
1173    char *buf2, *p, *p2, *n;
1174    if (!wd) return;
1175    p = strrchr(emission, ',');
1176    if (p)
1177      {
1178         const Eina_List *geoms;
1179
1180         n = p + 1;
1181         p2 = p -1;
1182         while (p2 >= emission)
1183           {
1184              if (*p2 == ',') break;
1185              p2--;
1186           }
1187         p2++;
1188         buf2 = alloca(5 + p - p2);
1189         strncpy(buf2, p2, p - p2);
1190         buf2[p - p2] = 0;
1191         ei.name = n;
1192         ei.button = atoi(buf2);
1193         ei.x = ei.y = ei.w = ei.h = 0;
1194         geoms =
1195           edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1196         if (geoms)
1197           {
1198              Evas_Textblock_Rectangle *r;
1199              const Eina_List *l;
1200              Evas_Coord px, py, x, y;
1201
1202              evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1203              evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1204              EINA_LIST_FOREACH(geoms, l, r)
1205                {
1206                   if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1207                       ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1208                     {
1209                        ei.x = r->x + x;
1210                        ei.y = r->y + y;
1211                        ei.w = r->w;
1212                        ei.h = r->h;
1213                        break;
1214                     }
1215                }
1216           }
1217         if (!wd->disabled)
1218           evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1219      }
1220 }
1221
1222 static void
1223 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1224 {
1225    Widget_Data *wd = elm_widget_data_get(data);
1226    if (!wd) return;
1227 }
1228
1229 static void
1230 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1231 {
1232    Widget_Data *wd = elm_widget_data_get(data);
1233    if (!wd) return;
1234 }
1235
1236 static void
1237 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1238 {
1239    Widget_Data *wd = elm_widget_data_get(data);
1240    if (!wd) return;
1241 }
1242
1243 static void
1244 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1245 {
1246    Widget_Data *wd = elm_widget_data_get(data);
1247    if (!wd) return;
1248    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1249 }
1250
1251 static void
1252 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1253 {
1254    Widget_Data *wd = elm_widget_data_get(data);
1255    if (!wd) return;
1256    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1257 }
1258
1259 static void
1260 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1261 {
1262    Widget_Data *wd = elm_widget_data_get(data);
1263    if (!wd) return;
1264    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1265 }
1266
1267 static void
1268 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1269 {
1270    Widget_Data *wd = elm_widget_data_get(data);
1271    if (!wd) return;
1272    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1273 }
1274
1275 #ifdef HAVE_ELEMENTARY_X
1276 static int
1277 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1278 {
1279    Widget_Data *wd = elm_widget_data_get(data);
1280    Ecore_X_Event_Selection_Notify *ev = event;
1281    if (!wd) return 1;
1282    if (!wd->selection_asked) return 1;
1283    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1284        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1285      {
1286         Ecore_X_Selection_Data_Text *text_data;
1287
1288         text_data = ev->data;
1289         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1290           {
1291              if (text_data->text)
1292                {
1293                   char *txt = _text_to_mkup(text_data->text);
1294
1295                   if (txt)
1296                     {
1297                        elm_entry_entry_insert(data, txt);
1298                        free(txt);
1299                     }
1300                }
1301           }
1302         wd->selection_asked = EINA_FALSE;
1303      }
1304    return 1;
1305 }
1306
1307 static int
1308 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1309 {
1310    Widget_Data *wd = elm_widget_data_get(data);
1311    Ecore_X_Event_Selection_Clear *ev = event;
1312    if (!wd) return 1;
1313    if (!wd->have_selection) return 1;
1314    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1315        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1316      {
1317         elm_entry_select_none(data);
1318      }
1319    return 1;
1320 }
1321 #endif
1322
1323 static Evas_Object *
1324 _get_item(void *data, Evas_Object *edje, const char *part, const char *item)
1325 {
1326    Widget_Data *wd = elm_widget_data_get(data);
1327    Evas_Object *o;
1328    Eina_List *l;
1329    Elm_Entry_Item_Provider *ip;
1330    int ok = 0;
1331
1332    EINA_LIST_FOREACH(wd->item_providers, l, ip)
1333      {
1334         o = ip->func(ip->data, data, item);
1335         if (o) return o;
1336      }
1337    o = edje_object_add(evas_object_evas_get(data));
1338    if (!strncmp(item, "emoticon/", 9))
1339      ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1340    if (!ok)
1341      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1342    return o;
1343 }
1344
1345
1346 static int
1347 _get_value_in_key_string(char *oldstring, char *key, char *value)
1348 {
1349    char *curlocater, *starttag, *endtag;
1350    int firstindex = 0, foundflag = -1;
1351
1352    curlocater = strstr(oldstring, key);
1353    if (curlocater == NULL)
1354      {
1355         foundflag = 0;
1356      }
1357    else
1358      {
1359         starttag = curlocater;
1360         endtag = curlocater + strlen(key);
1361         if (*endtag != '=')
1362           foundflag = 0;
1363
1364         firstindex = abs(oldstring - curlocater);
1365         firstindex += strlen(key)+1; // strlen("font_size") + strlen("=")
1366         value = oldstring + firstindex;
1367
1368         while (oldstring != starttag)
1369           {
1370              if (*starttag == '>')
1371                {
1372                   foundflag = 0;
1373                   break;
1374                }
1375              if (*starttag == '<')
1376                break;
1377              else
1378                starttag--;
1379              if (starttag == NULL)
1380                break;
1381           }
1382
1383         while (NULL != *endtag)
1384           {
1385              if (*endtag == '<')
1386                {
1387                   foundflag = 0;
1388                   break;
1389                }
1390              if (*endtag == '>')
1391                break;
1392              else
1393                endtag++;
1394              if (endtag == NULL)
1395                break;
1396           }
1397
1398         if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1399           foundflag = 1;
1400         else
1401           foundflag = 0;
1402      }
1403
1404    if (foundflag == 1)
1405      return 0;
1406
1407    return -1;
1408 }
1409
1410
1411 static int
1412 _string_key_value_replace(char *oldstring, char *key, char *value, char *tagstring)
1413 {
1414    char *curlocater, *starttag, *endtag;
1415    int firstindex = 0, insertflag = 0;
1416
1417    curlocater = strstr(oldstring, key);
1418    if (curlocater == NULL)
1419      {
1420         insertflag = 1;
1421      }
1422    else
1423      {
1424         starttag = curlocater - 1;
1425         endtag = curlocater + strlen(key);
1426         if (*endtag != '=')
1427           insertflag = 1;
1428
1429         firstindex = abs(oldstring - curlocater);
1430         firstindex += strlen(key)+1; // strlen("font_size") + strlen("=")
1431         strncpy(tagstring, oldstring, firstindex);
1432         tagstring[firstindex] = '\0';
1433         sprintf(&tagstring[firstindex], "%s", value);
1434
1435         while (curlocater != NULL)
1436           {
1437              if (*curlocater == ' ' || *curlocater == '>')
1438                break;
1439              curlocater++;
1440           }
1441         strcat(tagstring, curlocater);
1442
1443         while (oldstring != starttag)
1444           {
1445              if (*starttag == '>')
1446                {
1447                   insertflag = 1;
1448                   break;
1449                }
1450              if (*starttag == '<')
1451                break;
1452              else
1453                starttag--;
1454              if (starttag == NULL)
1455                break;
1456           }
1457
1458         while (NULL != *endtag)
1459           {
1460              if (*endtag == '<')
1461                {
1462                   insertflag = 1;
1463                   break;
1464                }
1465              if (*endtag == '>')
1466                break;
1467              else
1468                endtag++;
1469              if (endtag == NULL)
1470                break;
1471           }
1472
1473         if (insertflag == 0 && *starttag == '<' && *endtag == '>')
1474           return 0; 
1475         else
1476           insertflag = 1;
1477
1478      }
1479
1480    if (insertflag == 1)
1481      {
1482         sprintf(tagstring, "<%s=%s>", key, value);
1483         strcat(tagstring, oldstring);
1484         return 0;
1485      }
1486
1487    return -1;
1488 }
1489
1490 static int
1491 _is_width_over(Evas_Object *obj)
1492 {
1493    Evas_Coord x, y, w, h;
1494    Evas_Coord vx, vy, vw, vh;
1495    Widget_Data *wd = elm_widget_data_get(obj);
1496
1497    if (!wd) return 0;
1498
1499    edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1500
1501    evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1502
1503    if (x >= 0 && y >= 0)
1504            return 0;
1505
1506    if (4 < wd->wrap_w && w > wd->wrap_w)
1507            return 1;
1508
1509    return 0;
1510 }
1511
1512 static void
1513 _ellipsis_entry_to_width(Evas_Object *obj)
1514 {
1515    Widget_Data *wd = elm_widget_data_get(obj);
1516    int cur_fontsize = 0, len, jumpcount, i, tagend;
1517    char *oldstring, *value, *textlocater, *entrystring;
1518    char *string, fontbuf[16];
1519
1520    if (!wd) return;
1521
1522    entrystring = edje_object_part_text_get(wd->ent, "elm.text");
1523
1524    len = strlen(entrystring);
1525    oldstring = malloc(sizeof(char)*(len+32));
1526    strcpy(oldstring, entrystring);
1527
1528    if (_get_value_in_key_string(oldstring, "font_size", value) == 0 
1529          && value != NULL)
1530      {
1531         cur_fontsize = atoi(value);
1532      }
1533    else
1534      cur_fontsize = 24; /* default size in aqua.edc */
1535
1536    free(oldstring);
1537    oldstring = NULL;
1538
1539    while (_is_width_over(obj) == 1)
1540      {
1541         if (cur_fontsize > MIN_ENTRY_FONT_SIZE)
1542           {
1543              cur_fontsize--;
1544              entrystring = edje_object_part_text_get(wd->ent, "elm.text");
1545              len = strlen(entrystring);
1546              if (len <= 0) return;
1547              string = malloc(sizeof(char)*(len+32));
1548              oldstring = malloc(sizeof(char)*(len+32));
1549              sprintf(fontbuf, "%d", cur_fontsize);
1550
1551              strcpy(oldstring, entrystring);
1552              _string_key_value_replace(oldstring, "font_size", fontbuf, string);
1553
1554              edje_object_part_text_set(wd->ent, "elm.text", string);
1555              if (wd->text) eina_stringshare_del(wd->text);
1556              wd->text = NULL;
1557              edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1558
1559              free(string);
1560              free(oldstring);
1561           }
1562         else
1563           {
1564              entrystring = edje_object_part_text_get(wd->ent, "elm.text");
1565              len = strlen(entrystring) - 1;
1566              tagend = 0;
1567              for (i = 0; i <= len; i++)
1568                {
1569                   if (entrystring[i] == '>' && entrystring[i+1] != NULL &&
1570                         entrystring[i+1] != '<')
1571                     {
1572                        tagend = i;
1573                        break;
1574                     }
1575                }
1576              oldstring = elm_entry_markup_to_utf8(entrystring);
1577              jumpcount = 0;
1578              string = malloc(sizeof(char)*(len+32));
1579              while (jumpcount < len-3)
1580                {
1581                   strncpy(string, entrystring, tagend+1);
1582                   string[tagend+1] = '\0';
1583                   strcat(string, "...");
1584                   strcat(string, &oldstring[jumpcount]);
1585
1586                   edje_object_part_text_set(wd->ent, "elm.text", string);
1587                   if (wd->text) eina_stringshare_del(wd->text);
1588                   wd->text = NULL;
1589                   edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1590
1591                   if (_is_width_over(obj) == 1)
1592                     jumpcount++;
1593                   else
1594                     break;
1595
1596                   entrystring = edje_object_part_text_get(wd->ent, "elm.text");
1597                }
1598              free(string);
1599              free(oldstring);
1600           }
1601      }
1602    wd->changed = 1;
1603    _sizing_eval(obj);
1604 }
1605
1606 static int _textinput_control_function(void *data,void *input_data)
1607 {       
1608    /*calculate character count*/
1609    Widget_Data *wd = elm_widget_data_get(data); 
1610    char buf[10]="\0";
1611    size_t byte_len;
1612    size_t len=0, bytes_per_char=0,insert_text_len=0;
1613    char *text = edje_object_part_text_get(wd->ent, "elm.text"); 
1614    char *insert_text;  
1615    size_t remain_bytes;
1616    if(text!=NULL)
1617      {          
1618         byte_len = strlen(text);/*no of bytes*/
1619         remain_bytes = wd->max_no_of_bytes-byte_len;
1620         sprintf(buf,"%d",remain_bytes); 
1621         edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);         
1622         if(input_data)
1623           {
1624              insert_text =  (char *)input_data;
1625              insert_text_len = strlen(insert_text);     
1626              if(remain_bytes<insert_text_len)
1627                {                        
1628                   evas_object_smart_callback_call(input_data, "maxlength,reached", NULL);
1629                   return EINA_TRUE;
1630                }                        
1631              if(byte_len>=wd->max_no_of_bytes)
1632                {
1633                   evas_object_smart_callback_call(input_data, "maxlength,reached", NULL);
1634                   return EINA_TRUE;
1635                }                        
1636           }             
1637      }
1638    return EINA_FALSE;           
1639 }
1640
1641 /**
1642  * This adds an entry to @p parent object.
1643  *
1644  * @param parent The parent object
1645  * @return The new object or NULL if it cannot be created
1646  *
1647  * @ingroup Entry
1648  */
1649 EAPI Evas_Object *
1650 elm_entry_add(Evas_Object *parent)
1651 {
1652    Evas_Object *obj, *top;
1653    Evas *e;
1654    Widget_Data *wd;
1655
1656    wd = ELM_NEW(Widget_Data);
1657    e = evas_object_evas_get(parent);
1658    wd->bgcolor = EINA_FALSE;
1659    wd->bg = evas_object_rectangle_add(e);
1660    evas_object_color_set(wd->bg, 0, 0, 0, 0);
1661    obj = elm_widget_add(e);
1662    ELM_SET_WIDTYPE(widtype, "entry");
1663    elm_widget_type_set(obj, "entry");
1664    elm_widget_sub_object_add(parent, obj);
1665    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1666    elm_widget_data_set(obj, wd);
1667    elm_widget_del_hook_set(obj, _del_hook);
1668    elm_widget_theme_hook_set(obj, _theme_hook);
1669    elm_widget_disable_hook_set(obj, _disable_hook);
1670    elm_widget_can_focus_set(obj, 1);
1671
1672    wd->linewrap     = EINA_TRUE;
1673    wd->ellipsis     = EINA_FALSE;
1674    wd->char_linewrap= EINA_FALSE;
1675    wd->editable     = EINA_TRUE;
1676    wd->disabled     = EINA_FALSE;
1677    wd->context_menu = EINA_TRUE;
1678
1679    wd->ent = edje_object_add(e);
1680    edje_object_item_provider_set(wd->ent, _get_item, obj);
1681    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1682    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1683    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1684                                   _mouse_down, obj);
1685    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1686                                   _mouse_up, obj);
1687    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1688                                   _mouse_move, obj);
1689
1690    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1691    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1692                                    _signal_entry_changed, obj);
1693    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1694                                    _signal_selection_start, obj);
1695    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1696                                    _signal_selection_changed, obj);
1697    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1698                                    _signal_selection_cleared, obj);
1699    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1700                                    _signal_entry_paste_request, obj);
1701    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1702                                    _signal_entry_copy_notify, obj);
1703    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1704                                    _signal_entry_cut_notify, obj);
1705    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1706                                    _signal_cursor_changed, obj);
1707    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1708                                    _signal_anchor_down, obj);
1709    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1710                                    _signal_anchor_up, obj);
1711    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1712                                    _signal_anchor_move, obj);
1713    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1714                                    _signal_anchor_in, obj);
1715    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1716                                    _signal_anchor_out, obj);
1717    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1718                                    _signal_key_enter, obj);
1719    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1720                                    _signal_mouse_down, obj);
1721    edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
1722                                    _signal_mouse_up, obj);
1723    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1724                                    _signal_mouse_double, obj);
1725    edje_object_part_text_set(wd->ent, "elm.text", "");
1726    elm_widget_resize_object_set(obj, wd->ent);
1727    _sizing_eval(obj);
1728
1729    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
1730
1731 #ifdef HAVE_ELEMENTARY_X
1732    top = elm_widget_top_get(obj);
1733    if ((top) && (elm_win_xwindow_get(top)))
1734      {
1735         wd->sel_notify_handler =
1736           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1737                                   _event_selection_notify, obj);
1738         wd->sel_clear_handler =
1739           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1740                                   _event_selection_clear, obj);
1741      }
1742 #endif
1743
1744    entries = eina_list_prepend(entries, obj);
1745
1746    // module - find module for entry
1747    wd->api = _module(obj);
1748    // if found - hook in
1749    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1750
1751    // TODO: convert Elementary to subclassing of Evas_Smart_Class
1752    // TODO: and save some bytes, making descriptions per-class and not instance!
1753    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1754    return obj;
1755 }
1756
1757 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
1758 {
1759    ELM_CHECK_WIDTYPE(obj, widtype);
1760    Widget_Data *wd = elm_widget_data_get(obj);
1761    if (!wd) return;
1762    ext_mod->cancel = _cancel;
1763    ext_mod->copy = _copy;
1764    ext_mod->cut = _cut;
1765    ext_mod->paste = _paste;
1766    ext_mod->select = _select;
1767    ext_mod->selectall = NULL; /* to be implemented*/
1768    ext_mod->ent = wd->ent;
1769    ext_mod->items = wd->items;
1770    ext_mod->longpress_timer = wd->longpress_timer;
1771    ext_mod->editable = wd->editable;
1772    ext_mod->have_selection = wd->have_selection;
1773    ext_mod->password = wd->password;
1774    ext_mod->selmode = wd->selmode;
1775 }
1776
1777 /**
1778  * This sets the entry object not to line wrap.  All input will
1779  * be on a single line, and the entry box will extend with user input.
1780  *
1781  * @param obj The entry object
1782  * @param single_line If true, the text in the entry
1783  * will be on a single line.
1784  *
1785  * @ingroup Entry
1786  */
1787 EAPI void
1788 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1789 {
1790    ELM_CHECK_WIDTYPE(obj, widtype);
1791    Widget_Data *wd = elm_widget_data_get(obj);
1792    const char *t;
1793    if (!wd) return;
1794    if (wd->single_line == single_line) return;
1795    wd->single_line = single_line;
1796    wd->linewrap = EINA_FALSE;
1797    wd->char_linewrap = EINA_FALSE;
1798    t = eina_stringshare_add(elm_entry_entry_get(obj));
1799    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1800    elm_entry_entry_set(obj, t);
1801    eina_stringshare_del(t);
1802    _sizing_eval(obj);
1803 }
1804
1805 /**
1806  * This returns true if the entry has been set to single line mode.
1807  * See also elm_entry_single_line_set().
1808  *
1809  * @param obj The entry object
1810  * @return single_line If true, the text in the entry is set to display
1811  * on a single line.
1812  *
1813  * @ingroup Entry
1814  */
1815 EAPI Eina_Bool
1816 elm_entry_single_line_get(const Evas_Object *obj)
1817 {
1818    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1819    Widget_Data *wd = elm_widget_data_get(obj);
1820    if (!wd) return EINA_FALSE;
1821    return wd->single_line;
1822 }
1823
1824 /**
1825  * This set's the maximum bytes that can be added in entry.
1826  *
1827  * @param obj The entry object
1828  * @param max_no_of_bytes Maximum number of bytes entry can have.
1829  * 
1830  * @ingroup Entry
1831  */
1832 EAPI void
1833 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
1834 {
1835    Widget_Data *wd = elm_widget_data_get(obj);
1836
1837    wd->max_no_of_bytes = max_no_of_bytes;
1838    edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
1839    edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
1840  }
1841
1842
1843 /**
1844  * This sets the entry object to password mode.  All text entered
1845  * and/or displayed within the widget will be replaced with asterisks (*).
1846  *
1847  * @param obj The entry object
1848  * @param password If true, password mode is enabled.
1849  *
1850  * @ingroup Entry
1851  */
1852 EAPI void
1853 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1854 {
1855    ELM_CHECK_WIDTYPE(obj, widtype);
1856    Widget_Data *wd = elm_widget_data_get(obj);
1857    const char *t;
1858    if (!wd) return;
1859    if (wd->password == password) return;
1860    wd->password = password;
1861    wd->show_last_character = EINA_FALSE;
1862    wd->single_line = EINA_TRUE;
1863    wd->linewrap = EINA_FALSE;
1864    wd->char_linewrap = EINA_FALSE;
1865    t = eina_stringshare_add(elm_entry_entry_get(obj));
1866    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1867    elm_entry_entry_set(obj, t);
1868    eina_stringshare_del(t);
1869    _sizing_eval(obj);
1870 }
1871
1872 /**
1873  * This set's the entry in password mode with out masking the last character entered by user,
1874  * and later masking the character after 2 seconds.
1875  
1876  * @param obj The entry object
1877  * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character" 
1878  * 0 for default).
1879  *
1880  * @ingroup Entry
1881  */
1882 EAPI void         
1883 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
1884 {
1885    Widget_Data *wd = elm_widget_data_get(obj);
1886    const char *t;
1887    if (!wd) return;
1888    if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character))  return;
1889    wd->show_last_character = show_last_character;
1890    wd->password = show_last_character;
1891    wd->single_line = EINA_TRUE;
1892    wd->linewrap = EINA_FALSE;
1893    wd->char_linewrap = EINA_FALSE;
1894    t = eina_stringshare_add(elm_entry_entry_get(obj));
1895     _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1896    elm_entry_entry_set(obj, t);
1897    eina_stringshare_del(t);
1898    _sizing_eval(obj);
1899 }
1900
1901 /**
1902  * This returns whether password mode is enabled.
1903  * See also elm_entry_password_set().
1904  *
1905  * @param obj The entry object
1906  * @return If true, the entry is set to display all characters
1907  * as asterisks (*).
1908  *
1909  * @ingroup Entry
1910  */
1911 EAPI Eina_Bool
1912 elm_entry_password_get(const Evas_Object *obj)
1913 {
1914    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1915    Widget_Data *wd = elm_widget_data_get(obj);
1916    if (!wd) return EINA_FALSE;
1917    return wd->password;
1918 }
1919
1920 /**
1921  * This sets the text displayed within the entry to @p entry.
1922  *
1923  * @param obj The entry object
1924  * @param entry The text to be displayed
1925  *
1926  * @ingroup Entry
1927  */
1928 EAPI void
1929 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1930 {
1931    ELM_CHECK_WIDTYPE(obj, widtype);
1932    Widget_Data *wd = elm_widget_data_get(obj);
1933    if (!wd) return;
1934    if (!entry) entry = "";
1935    if(wd->max_no_of_bytes)
1936      {
1937         int len = strlen(entry);
1938         if(len > wd->max_no_of_bytes)
1939           {
1940              ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
1941              return;
1942           }
1943      }
1944    edje_object_part_text_set(wd->ent, "elm.text", entry);
1945    if (wd->text) eina_stringshare_del(wd->text);
1946    wd->text = NULL;
1947    wd->changed = EINA_TRUE;
1948    _sizing_eval(obj);
1949 }
1950
1951 /**
1952  * This returns the text currently shown in object @p entry.
1953  * See also elm_entry_entry_set().
1954  *
1955  * @param obj The entry object
1956  * @return The currently displayed text or NULL on failure
1957  *
1958  * @ingroup Entry
1959  */
1960 EAPI const char *
1961 elm_entry_entry_get(const Evas_Object *obj)
1962 {
1963    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1964    Widget_Data *wd = elm_widget_data_get(obj);
1965    const char *text;
1966    if (!wd) return NULL;
1967    if (wd->text) return wd->text;
1968    text = edje_object_part_text_get(wd->ent, "elm.text");
1969    if (!text)
1970      {
1971         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1972         return NULL;
1973      }
1974    eina_stringshare_replace(&wd->text, text);
1975    return wd->text;
1976 }
1977
1978 /**
1979  * This returns all selected text within the entry.
1980  *
1981  * @param obj The entry object
1982  * @return The selected text within the entry or NULL on failure
1983  *
1984  * @ingroup Entry
1985  */
1986 EAPI const char *
1987 elm_entry_selection_get(const Evas_Object *obj)
1988 {
1989    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1990    Widget_Data *wd = elm_widget_data_get(obj);
1991    if (!wd) return NULL;
1992    return edje_object_part_text_selection_get(wd->ent, "elm.text");
1993 }
1994
1995 /**
1996  * This inserts text in @p entry at the beginning of the entry
1997  * object.
1998  *
1999  * @param obj The entry object
2000  * @param entry The text to insert
2001  *
2002  * @ingroup Entry
2003  */
2004 EAPI void
2005 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2006 {
2007    ELM_CHECK_WIDTYPE(obj, widtype);
2008    Widget_Data *wd = elm_widget_data_get(obj);
2009    if (!wd) return;
2010    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2011    wd->changed = EINA_TRUE;
2012    _sizing_eval(obj);
2013 }
2014
2015 /**
2016  * This enables word line wrapping in the entry object.  It is the opposite
2017  * of elm_entry_single_line_set().  Additionally, setting this disables
2018  * character line wrapping.
2019  * See also elm_entry_line_char_wrap_set().
2020  *
2021  * @param obj The entry object
2022  * @param wrap If true, the entry will be wrapped once it reaches the end
2023  * of the object. Wrapping will occur at the end of the word before the end of the
2024  * object.
2025  *
2026  * @ingroup Entry
2027  */
2028 EAPI void
2029 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2030 {
2031    ELM_CHECK_WIDTYPE(obj, widtype);
2032    Widget_Data *wd = elm_widget_data_get(obj);
2033    const char *t;
2034    if (!wd) return;
2035    if (wd->linewrap == wrap) return;
2036    wd->linewrap = wrap;
2037    if(wd->linewrap)
2038        wd->char_linewrap = EINA_FALSE;
2039    t = eina_stringshare_add(elm_entry_entry_get(obj));
2040    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2041    elm_entry_entry_set(obj, t);
2042    eina_stringshare_del(t);
2043    _sizing_eval(obj);
2044 }
2045
2046 /**
2047  * Set wrap width of the entry
2048  *
2049  * @param obj The entry object
2050  * @param w The wrap width in pixels at a minimum where words need to wrap
2051  * @ingroup Entry
2052  */
2053 EAPI void
2054 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2055 {
2056    Widget_Data *wd = elm_widget_data_get(obj);
2057    if (wd->wrap_w == w) return;
2058    wd->wrap_w = w;
2059    _sizing_eval(obj);
2060 }
2061
2062 /**
2063  * get wrap width of the entry
2064  *
2065  * @param obj The entry object
2066  * @return The wrap width in pixels at a minimum where words need to wrap
2067  * @ingroup Entry
2068  */
2069 EAPI Evas_Coord
2070 elm_entry_wrap_width_get(const Evas_Object *obj)
2071 {
2072    Widget_Data *wd = elm_widget_data_get(obj);
2073    return wd->wrap_w;
2074 }
2075
2076 /**
2077  * This enables character line wrapping in the entry object.  It is the opposite
2078  * of elm_entry_single_line_set().  Additionally, setting this disables
2079  * word line wrapping.
2080  * See also elm_entry_line_wrap_set().
2081  *
2082  * @param obj The entry object
2083  * @param wrap If true, the entry will be wrapped once it reaches the end
2084  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2085  *
2086  * @ingroup Entry
2087  */
2088 EAPI void
2089 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2090 {
2091    ELM_CHECK_WIDTYPE(obj, widtype);
2092    Widget_Data *wd = elm_widget_data_get(obj);
2093    const char *t;
2094    if (!wd) return;
2095    if (wd->char_linewrap == wrap) return;
2096    wd->char_linewrap = wrap;
2097    if(wd->char_linewrap)
2098        wd->linewrap = EINA_FALSE;
2099    t = eina_stringshare_add(elm_entry_entry_get(obj));
2100    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2101    elm_entry_entry_set(obj, t);
2102    eina_stringshare_del(t);
2103    _sizing_eval(obj);
2104 }
2105
2106 /**
2107  * This sets the editable attribute of the entry.
2108  *
2109  * @param obj The entry object
2110  * @param editable If true, the entry will be editable by the user.
2111  * If false, it will be set to the disabled state.
2112  *
2113  * @ingroup Entry
2114  */
2115 EAPI void
2116 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2117 {
2118    ELM_CHECK_WIDTYPE(obj, widtype);
2119    Widget_Data *wd = elm_widget_data_get(obj);
2120    const char *t;
2121    if (!wd) return;
2122    if (wd->editable == editable) return;
2123    wd->editable = editable;
2124    t = eina_stringshare_add(elm_entry_entry_get(obj));
2125    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2126    elm_entry_entry_set(obj, t);
2127    eina_stringshare_del(t);
2128    _sizing_eval(obj);
2129 }
2130
2131 /**
2132  * This gets the editable attribute of the entry.
2133  * See also elm_entry_editable_set().
2134  *
2135  * @param obj The entry object
2136  * @return If true, the entry is editable by the user.
2137  * If false, it is not editable by the user
2138  *
2139  * @ingroup Entry
2140  */
2141 EAPI Eina_Bool
2142 elm_entry_editable_get(const Evas_Object *obj)
2143 {
2144    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2145    Widget_Data *wd = elm_widget_data_get(obj);
2146    if (!wd) return EINA_FALSE;
2147    return wd->editable;
2148 }
2149
2150 /**
2151  * This drops any existing text selection within the entry.
2152  *
2153  * @param obj The entry object
2154  *
2155  * @ingroup Entry
2156  */
2157 EAPI void
2158 elm_entry_select_none(Evas_Object *obj)
2159 {
2160    ELM_CHECK_WIDTYPE(obj, widtype);
2161    Widget_Data *wd = elm_widget_data_get(obj);
2162    if (!wd) return;
2163    if (wd->selmode)
2164      {
2165         wd->selmode = EINA_FALSE;
2166         edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2167         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2168      }
2169    wd->have_selection = EINA_FALSE;
2170    edje_object_part_text_select_none(wd->ent, "elm.text");
2171 }
2172
2173 /**
2174  * This selects all text within the entry.
2175  *
2176  * @param obj The entry object
2177  *
2178  * @ingroup Entry
2179  */
2180 EAPI void
2181 elm_entry_select_all(Evas_Object *obj)
2182 {
2183    ELM_CHECK_WIDTYPE(obj, widtype);
2184    Widget_Data *wd = elm_widget_data_get(obj);
2185    if (!wd) return;
2186    if (wd->selmode)
2187      {
2188         wd->selmode = EINA_FALSE;
2189         edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2190         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2191      }
2192    wd->have_selection = EINA_TRUE;
2193    edje_object_part_text_select_all(wd->ent, "elm.text");
2194 }
2195
2196 /**
2197  * This moves the cursor one place to the right within the entry.
2198  *
2199  * @param obj The entry object
2200  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2201  *
2202  * @ingroup Entry
2203  */
2204 EAPI Eina_Bool
2205 elm_entry_cursor_next(Evas_Object *obj)
2206 {
2207    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2208    Widget_Data *wd = elm_widget_data_get(obj);
2209    if (!wd) return EINA_FALSE;
2210    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2211 }
2212
2213 /**
2214  * This moves the cursor one place to the left within the entry.
2215  *
2216  * @param obj The entry object
2217  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2218  *
2219  * @ingroup Entry
2220  */
2221 EAPI Eina_Bool
2222 elm_entry_cursor_prev(Evas_Object *obj)
2223 {
2224    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2225    Widget_Data *wd = elm_widget_data_get(obj);
2226    if (!wd) return EINA_FALSE;
2227    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2228 }
2229
2230 /**
2231  * This moves the cursor one line up within the entry.
2232  *
2233  * @param obj The entry object
2234  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2235  *
2236  * @ingroup Entry
2237  */
2238 EAPI Eina_Bool
2239 elm_entry_cursor_up(Evas_Object *obj)
2240 {
2241    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2242    Widget_Data *wd = elm_widget_data_get(obj);
2243    if (!wd) return EINA_FALSE;
2244    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2245 }
2246
2247 /**
2248  * This moves the cursor one line down within the entry.
2249  *
2250  * @param obj The entry object
2251  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2252  *
2253  * @ingroup Entry
2254  */
2255 EAPI Eina_Bool
2256 elm_entry_cursor_down(Evas_Object *obj)
2257 {
2258    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2259    Widget_Data *wd = elm_widget_data_get(obj);
2260    if (!wd) return EINA_FALSE;
2261    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2262 }
2263
2264 /**
2265  * This moves the cursor to the beginning of the entry.
2266  *
2267  * @param obj The entry object
2268  *
2269  * @ingroup Entry
2270  */
2271 EAPI void
2272 elm_entry_cursor_begin_set(Evas_Object *obj)
2273 {
2274    ELM_CHECK_WIDTYPE(obj, widtype);
2275    Widget_Data *wd = elm_widget_data_get(obj);
2276    if (!wd) return;
2277    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2278 }
2279
2280 /**
2281  * This moves the cursor to the end of the entry.
2282  *
2283  * @param obj The entry object
2284  *
2285  * @ingroup Entry
2286  */
2287 EAPI void
2288 elm_entry_cursor_end_set(Evas_Object *obj)
2289 {
2290    ELM_CHECK_WIDTYPE(obj, widtype);
2291    Widget_Data *wd = elm_widget_data_get(obj);
2292    if (!wd) return;
2293    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2294 }
2295
2296 /**
2297  * This moves the cursor to the beginning of the current line.
2298  *
2299  * @param obj The entry object
2300  *
2301  * @ingroup Entry
2302  */
2303 EAPI void
2304 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2305 {
2306    ELM_CHECK_WIDTYPE(obj, widtype);
2307    Widget_Data *wd = elm_widget_data_get(obj);
2308    if (!wd) return;
2309    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2310 }
2311
2312 /**
2313  * This moves the cursor to the end of the current line.
2314  *
2315  * @param obj The entry object
2316  *
2317  * @ingroup Entry
2318  */
2319 EAPI void
2320 elm_entry_cursor_line_end_set(Evas_Object *obj)
2321 {
2322    ELM_CHECK_WIDTYPE(obj, widtype);
2323    Widget_Data *wd = elm_widget_data_get(obj);
2324    if (!wd) return;
2325    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2326 }
2327
2328 /**
2329  * This begins a selection within the entry as though
2330  * the user were holding down the mouse button to make a selection.
2331  *
2332  * @param obj The entry object
2333  *
2334  * @ingroup Entry
2335  */
2336 EAPI void
2337 elm_entry_cursor_selection_begin(Evas_Object *obj)
2338 {
2339    ELM_CHECK_WIDTYPE(obj, widtype);
2340    Widget_Data *wd = elm_widget_data_get(obj);
2341    if (!wd) return;
2342    edje_object_part_text_select_begin(wd->ent, "elm.text");
2343 }
2344
2345 /**
2346  * This ends a selection within the entry as though
2347  * the user had just released the mouse button while making a selection.
2348  *
2349  * @param obj The entry object
2350  *
2351  * @ingroup Entry
2352  */
2353 EAPI void
2354 elm_entry_cursor_selection_end(Evas_Object *obj)
2355 {
2356    ELM_CHECK_WIDTYPE(obj, widtype);
2357    Widget_Data *wd = elm_widget_data_get(obj);
2358    if (!wd) return;
2359    edje_object_part_text_select_extend(wd->ent, "elm.text");
2360 }
2361
2362 /**
2363  * TODO: fill this in
2364  *
2365  * @param obj The entry object
2366  * @return TODO: fill this in
2367  *
2368  * @ingroup Entry
2369  */
2370 EAPI Eina_Bool
2371 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2372 {
2373    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2374    Widget_Data *wd = elm_widget_data_get(obj);
2375    if (!wd) return EINA_FALSE;
2376    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2377 }
2378
2379 /**
2380  * This returns whether the cursor is visible.
2381  *
2382  * @param obj The entry object
2383  * @return If true, the cursor is visible.
2384  *
2385  * @ingroup Entry
2386  */
2387 EAPI Eina_Bool
2388 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2389 {
2390    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2391    Widget_Data *wd = elm_widget_data_get(obj);
2392    if (!wd) return EINA_FALSE;
2393    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2394 }
2395
2396 /**
2397  * TODO: fill this in
2398  *
2399  * @param obj The entry object
2400  * @return TODO: fill this in
2401  *
2402  * @ingroup Entry
2403  */
2404 EAPI const char *
2405 elm_entry_cursor_content_get(const Evas_Object *obj)
2406 {
2407    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2408    Widget_Data *wd = elm_widget_data_get(obj);
2409    if (!wd) return NULL;
2410    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2411 }
2412
2413 /**
2414  * This executes a "cut" action on the selected text in the entry.
2415  *
2416  * @param obj The entry object
2417  *
2418  * @ingroup Entry
2419  */
2420 EAPI void
2421 elm_entry_selection_cut(Evas_Object *obj)
2422 {
2423    ELM_CHECK_WIDTYPE(obj, widtype);
2424    Widget_Data *wd = elm_widget_data_get(obj);
2425    if (!wd) return;
2426    _cut(obj, NULL, NULL);
2427 }
2428
2429 /**
2430  * This executes a "copy" action on the selected text in the entry.
2431  *
2432  * @param obj The entry object
2433  *
2434  * @ingroup Entry
2435  */
2436 EAPI void
2437 elm_entry_selection_copy(Evas_Object *obj)
2438 {
2439    ELM_CHECK_WIDTYPE(obj, widtype);
2440    Widget_Data *wd = elm_widget_data_get(obj);
2441    if (!wd) return;
2442    _copy(obj, NULL, NULL);
2443 }
2444
2445 /**
2446  * This executes a "paste" action in the entry.
2447  *
2448  * @param obj The entry object
2449  *
2450  * @ingroup Entry
2451  */
2452 EAPI void
2453 elm_entry_selection_paste(Evas_Object *obj)
2454 {
2455    ELM_CHECK_WIDTYPE(obj, widtype);
2456    Widget_Data *wd = elm_widget_data_get(obj);
2457    if (!wd) return;
2458    _paste(obj, NULL, NULL);
2459 }
2460
2461 /**
2462  * This clears and frees the items in a entry's contextual (right click) menu.
2463  *
2464  * @param obj The entry object
2465  *
2466  * @ingroup Entry
2467  */
2468 EAPI void
2469 elm_entry_context_menu_clear(Evas_Object *obj)
2470 {
2471    ELM_CHECK_WIDTYPE(obj, widtype);
2472    Widget_Data *wd = elm_widget_data_get(obj);
2473    Elm_Entry_Context_Menu_Item *it;
2474    if (!wd) return;
2475    EINA_LIST_FREE(wd->items, it)
2476      {
2477         eina_stringshare_del(it->label);
2478         eina_stringshare_del(it->icon_file);
2479         eina_stringshare_del(it->icon_group);
2480         free(it);
2481      }
2482 }
2483
2484 /**
2485  * This adds an item to the entry's contextual menu.
2486  *
2487  * @param obj The entry object
2488  * @param label The item's text label
2489  * @param icon_file The item's icon file
2490  * @param icon_type The item's icon type
2491  * @param func The callback to execute when the item is clicked
2492  * @param data The data to associate with the item for related functions
2493  *
2494  * @ingroup Entry
2495  */
2496 EAPI void
2497 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)
2498 {
2499    ELM_CHECK_WIDTYPE(obj, widtype);
2500    Widget_Data *wd = elm_widget_data_get(obj);
2501    Elm_Entry_Context_Menu_Item *it;
2502    if (!wd) return;
2503    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2504    if (!it) return;
2505    wd->items = eina_list_append(wd->items, it);
2506    it->obj = obj;
2507    it->label = eina_stringshare_add(label);
2508    it->icon_file = eina_stringshare_add(icon_file);
2509    it->icon_type = icon_type;
2510    it->func = func;
2511    it->data = (void *)data;
2512 }
2513
2514 /**
2515  * This disables the entry's contextual (right click) menu.
2516  *
2517  * @param obj The entry object
2518  * @param disabled If true, the menu is disabled
2519  *
2520  * @ingroup Entry
2521  */
2522 EAPI void
2523 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2524 {
2525    ELM_CHECK_WIDTYPE(obj, widtype);
2526    Widget_Data *wd = elm_widget_data_get(obj);
2527    if (!wd) return;
2528    if (wd->context_menu == !disabled) return;
2529    wd->context_menu = !disabled;
2530 }
2531
2532 /**
2533  * This returns whether the entry's contextual (right click) menu is disabled.
2534  *
2535  * @param obj The entry object
2536  * @return If true, the menu is disabled
2537  *
2538  * @ingroup Entry
2539  */
2540 EAPI Eina_Bool
2541 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2542 {
2543    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2544    Widget_Data *wd = elm_widget_data_get(obj);
2545    if (!wd) return EINA_FALSE;
2546    return !wd->context_menu;
2547 }
2548
2549 /**
2550  * This appends a custom item provider to the list for that entry
2551  *
2552  * This appends the given callback. The list is walked from beginning to end
2553  * with each function called given the item href string in the text. If the
2554  * function returns an object handle other than NULL (it should create an
2555  * and object to do this), then this object is used to replace that item. If
2556  * not the next provider is called until one provides an item object, or the
2557  * default provider in entry does.
2558  * 
2559  * @param obj The entry object
2560  * @param func The function called to provide the item object
2561  * @param data The data passed to @p func
2562  *
2563  * @ingroup Entry
2564  */
2565 EAPI void
2566 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2567 {
2568    ELM_CHECK_WIDTYPE(obj, widtype);
2569    Widget_Data *wd = elm_widget_data_get(obj);
2570    if (!wd) return;
2571    if (!func) return;
2572    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2573    if (!ip) return;
2574    ip->func = func;
2575    ip->data = data;
2576    wd->item_providers = eina_list_append(wd->item_providers, ip);
2577 }
2578
2579 /**
2580  * This prepends a custom item provider to the list for that entry
2581  *
2582  * This prepends the given callback. See elm_entry_item_provider_append() for
2583  * more information
2584  * 
2585  * @param obj The entry object
2586  * @param func The function called to provide the item object
2587  * @param data The data passed to @p func
2588  *
2589  * @ingroup Entry
2590  */
2591 EAPI void
2592 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2593 {
2594    ELM_CHECK_WIDTYPE(obj, widtype);
2595    Widget_Data *wd = elm_widget_data_get(obj);
2596    if (!wd) return;
2597    if (!func) return;
2598    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2599    if (!ip) return;
2600    ip->func = func;
2601    ip->data = data;
2602    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2603 }
2604
2605 /**
2606  * This removes a custom item provider to the list for that entry
2607  *
2608  * This removes the given callback. See elm_entry_item_provider_append() for
2609  * more information
2610  * 
2611  * @param obj The entry object
2612  * @param func The function called to provide the item object
2613  * @param data The data passed to @p func
2614  *
2615  * @ingroup Entry
2616  */
2617 EAPI void
2618 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2619 {
2620    ELM_CHECK_WIDTYPE(obj, widtype);
2621    Widget_Data *wd = elm_widget_data_get(obj);
2622    Eina_List *l;
2623    Elm_Entry_Item_Provider *ip;
2624    if (!wd) return;
2625    if (!func) return;
2626    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2627      {
2628         if ((ip->func == func) && (ip->data == data))
2629           {
2630              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2631              free(ip);
2632              return;
2633           }
2634      }
2635 }
2636
2637 /**
2638  * This converts a markup (HTML-like) string into UTF-8.
2639  *
2640  * @param s The string (in markup) to be converted
2641  * @return The converted string (in UTF-8)
2642  *
2643  * @ingroup Entry
2644  */
2645 EAPI char *
2646 elm_entry_markup_to_utf8(const char *s)
2647 {
2648    char *ss = _mkup_to_text(s);
2649    if (!ss) ss = strdup("");
2650    return ss;
2651 }
2652
2653 /**
2654  * This converts a UTF-8 string into markup (HTML-like).
2655  *
2656  * @param s The string (in UTF-8) to be converted
2657  * @return The converted string (in markup)
2658  *
2659  * @ingroup Entry
2660  */
2661 EAPI char *
2662 elm_entry_utf8_to_markup(const char *s)
2663 {
2664    char *ss = _text_to_mkup(s);
2665    if (!ss) ss = strdup("");
2666    return ss;
2667 }
2668
2669 /**
2670  * Get the input method context in the entry widget
2671  *
2672  * @param obj The entry object
2673  * @return The input method context
2674  *
2675  * @ingroup Entry
2676  */
2677 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2678 {
2679    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2680    Widget_Data *wd = elm_widget_data_get(obj);
2681    if (!wd || !wd->ent) return NULL;
2682   
2683    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2684 }
2685
2686 /**
2687  * Set whether entry should enable the return key on soft keyboard automatically
2688  *
2689  * @param obj The entry object
2690  * @param on If true, entry enables the return key on soft keyboard automatically.
2691  *
2692  * @ingroup Entry
2693  */
2694 EAPI void 
2695 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
2696 {
2697    ELM_CHECK_WIDTYPE(obj, widtype);
2698    Widget_Data *wd = elm_widget_data_get(obj);
2699    if (!wd) return;
2700
2701    wd->autoreturnkey = on;
2702    _check_enable_returnkey(obj);
2703 }
2704
2705 /**
2706  * Set whether entry should support auto capitalization
2707  *
2708  * @param obj The entry object
2709  * @param on If true, entry suports auto capitalization.
2710  *
2711  * @ingroup Entry
2712  */
2713 EAPI void 
2714 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool on)
2715 {
2716    ELM_CHECK_WIDTYPE(obj, widtype);
2717    Eina_Bool autocap = on;
2718    Widget_Data *wd = elm_widget_data_get(obj);
2719    if (!wd) return;
2720
2721    if (!wd->password)
2722        autocap = EINA_FALSE;
2723    else
2724        autocap = on;
2725
2726    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", autocap);
2727 }
2728
2729 /**
2730  * Set the font size on the entry object
2731  *
2732  * @param obj The entry object
2733  * @param size font size
2734  *
2735  * @ingroup Entry
2736  */
2737 EAPI void
2738 elm_entry_fontsize_set(Evas_Object *obj, const int fontsize)
2739 {
2740    ELM_CHECK_WIDTYPE(obj, widtype);
2741    Widget_Data *wd = elm_widget_data_get(obj);
2742    char *string, fontvalue[16], *entrystring;
2743    int len;
2744
2745    if (!wd) return;
2746    entrystring = elm_entry_entry_get(obj);
2747    if (entrystring == NULL) return;
2748    len = strlen(entrystring);
2749    if (len <= 0) return;
2750    string = alloca(sizeof(char)*(len+32));
2751    sprintf(fontvalue, "%d", fontsize);
2752
2753    if (_string_key_value_replace(entrystring, "font_size", fontvalue, string) == 0)
2754      {
2755         elm_entry_entry_set(obj, string);
2756      }
2757 }
2758
2759 /**
2760  * Set the text align on the entry object
2761  *
2762  * @param obj The entry object
2763  * @param align align mode
2764  *
2765  * @ingroup Entry
2766  */
2767 EAPI void
2768 elm_entry_text_align_set(Evas_Object *obj, char *alignmode)
2769 {
2770    ELM_CHECK_WIDTYPE(obj, widtype);
2771    Widget_Data *wd = elm_widget_data_get(obj);
2772    char *string, *entrystring;
2773    int len;
2774
2775    if (!wd) return;
2776    entrystring = elm_entry_entry_get(obj);
2777    if (entrystring == NULL) return;
2778    len = strlen(entrystring);
2779    if (len <= 0) return;
2780    string = alloca(sizeof(char)*(len+32));
2781
2782    if (_string_key_value_replace(entrystring, "align", alignmode, string) == 0)
2783    {
2784      elm_entry_entry_set(obj, string);
2785    }
2786 }
2787
2788 /**
2789  * Set the text color on the entry object
2790  *
2791  * @param obj The entry object
2792  * @param r Red property background color of The entry object 
2793  * @param g Green property background color of The entry object 
2794  * @param b Blue property background color of The entry object 
2795  * @param a Alpha property background alpha of The entry object 
2796  *
2797  * @ingroup Entry
2798  */
2799 EAPI void
2800 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
2801 {
2802    ELM_CHECK_WIDTYPE(obj, widtype);
2803    Widget_Data *wd = elm_widget_data_get(obj);
2804    char *string, *entrystring, colorstring[16];
2805    int len;
2806
2807    if (!wd) return;
2808    entrystring = elm_entry_entry_get(obj);
2809    if (entrystring == NULL) return;
2810    len = strlen(entrystring);
2811    if (len <= 0) return;
2812    string = alloca(sizeof(char)*(len+32));
2813
2814    sprintf(colorstring, "#%02X%02X%02X%02X", r, g, b, a);
2815    if (_string_key_value_replace(entrystring, "color", colorstring, string) == 0)
2816      {
2817         elm_entry_entry_set(obj, string);
2818      }
2819 }
2820
2821
2822 /**
2823  * Set background color of the entry
2824  *
2825  * @param obj The entry object
2826  * @param r Red property background color of The entry object 
2827  * @param g Green property background color of The entry object 
2828  * @param b Blue property background color of The entry object 
2829  * @param a Alpha property background alpha of The entry object 
2830  * @ingroup Entry
2831  */
2832 EAPI void
2833 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
2834 {
2835    ELM_CHECK_WIDTYPE(obj, widtype);
2836    Widget_Data *wd = elm_widget_data_get(obj);
2837    evas_object_color_set(wd->bg, r, g, b, a);
2838
2839    if (wd->bgcolor == EINA_FALSE)
2840      {
2841         wd->bgcolor = 1;
2842         edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
2843      }
2844 }
2845
2846 /**
2847  * Set the ellipsis behavior of the entry
2848  *
2849  * @param obj The entry object
2850  * @param ellipsis To ellipsis text or not
2851  * @ingroup Entry
2852  */
2853 EAPI void
2854 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
2855 {
2856    ELM_CHECK_WIDTYPE(obj, widtype);
2857    Widget_Data *wd = elm_widget_data_get(obj);
2858    const char *t;
2859    if (wd->ellipsis == ellipsis) return;
2860    wd->ellipsis = ellipsis;
2861    wd->changed = 1;
2862    _sizing_eval(obj);
2863 }
2864
2865 /**
2866  * enable to show the input panel automatically.
2867  *
2868  * @param obj The entry object
2869  * @param enabled If true, the input panel is enabled
2870  *
2871  * @ingroup Entry
2872  */
2873 EAPI void
2874 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
2875 {
2876    ELM_CHECK_WIDTYPE(obj, widtype);
2877    Widget_Data *wd = elm_widget_data_get(obj);
2878    if (!wd) return;
2879
2880    wd->input_panel_enable = enabled;
2881    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
2882 }
2883
2884 /**
2885  * Set the input panel layout of the entry
2886  *
2887  * @param obj The entry object
2888  * @param layout the layout to set
2889  *
2890  * @ingroup Entry
2891  */
2892 EAPI void
2893 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
2894 {
2895    ELM_CHECK_WIDTYPE(obj, widtype);
2896    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
2897    if (!ic) return;
2898    
2899    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
2900 }