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