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