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