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