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