Merge branch 'master' of 165.213.180.234:/git/slp/pkgs/elementary
[framework/uifw/elementary.git] / src / lib / elm_entry.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4 #include <Elementary.h>
5 #include "elm_priv.h"
6 #include "elm_module_priv.h"
7 /**
8  * @defgroup Entry Entry
9  * @ingroup Elementary
10  *
11  * An entry is a convenience widget which shows
12  * a box that the user can enter text into.  Unlike a
13  * @ref Scrolled_Entry widget, entries DO NOT scroll with user
14  * input.  Entry widgets are capable of expanding past the
15  * boundaries of the window, thus resizing the window to its
16  * own length.
17  * 
18  * You can also insert "items" in the entry with:
19  * 
20  * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
21  * 
22  * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
23  * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry
24  * supports a list of emoticon names by default. These are:
25  * 
26  * - emoticon/angry
27  * - emoticon/angry-shout
28  * - emoticon/crazy-laugh
29  * - emoticon/evil-laugh
30  * - emoticon/evil
31  * - emoticon/goggle-smile
32  * - emoticon/grumpy
33  * - emoticon/grumpy-smile
34  * - emoticon/guilty
35  * - emoticon/guilty-smile
36  * - emoticon/haha
37  * - emoticon/half-smile
38  * - emoticon/happy-panting
39  * - emoticon/happy
40  * - emoticon/indifferent
41  * - emoticon/kiss
42  * - emoticon/knowing-grin
43  * - emoticon/laugh
44  * - emoticon/little-bit-sorry
45  * - emoticon/love-lots
46  * - emoticon/love
47  * - emoticon/minimal-smile
48  * - emoticon/not-happy
49  * - emoticon/not-impressed
50  * - emoticon/omg
51  * - emoticon/opensmile
52  * - emoticon/smile
53  * - emoticon/sorry
54  * - emoticon/squint-laugh
55  * - emoticon/surprised
56  * - emoticon/suspicious
57  * - emoticon/tongue-dangling
58  * - emoticon/tongue-poke
59  * - emoticon/uh
60  * - emoticon/unhappy
61  * - emoticon/very-sorry
62  * - emoticon/what
63  * - emoticon/wink
64  * - emoticon/worried
65  * - emoticon/wtf
66  *
67  * These are built-in currently, but you can add your own item provieer that
68  * can create inlined objects in the text and fill the space allocated to the
69  * item with a custom object of your own.
70  * 
71  * See the entry test for some more examples of use of this.
72  * 
73  * Signals that you can add callbacks for are:
74  * - "changed" - The text within the entry was changed
75  * - "activated" - The entry has received focus and the cursor
76  * - "press" - The entry has been clicked
77  * - "longpressed" - The entry has been clicked for a couple seconds
78  * - "clicked" - The entry has been clicked
79  * - "clicked,double" - The entry has been double clicked
80  * - "focused" - The entry has received focus
81  * - "unfocused" - The entry has lost focus
82  * - "selection,paste" - A paste action has occurred
83  * - "selection,copy" - A copy action has occurred
84  * - "selection,cut" - A cut action has occurred
85  * - "selection,start" - A selection has begun
86  * - "selection,changed" - The selection has changed
87  * - "selection,cleared" - The selection has been cleared
88  * - "cursor,changed" - The cursor has changed
89  * - "anchor,clicked" - The anchor has been clicked
90  */
91
92 typedef struct _Mod_Api Mod_Api;
93
94 typedef struct _Widget_Data Widget_Data;
95 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
96
97 struct _Widget_Data
98 {
99    Evas_Object *ent;
100    Evas_Object *popup;/*copy paste UI - elm_popup*/
101    Evas_Object *ctxpopup;/*copy paste UI - elm_ctxpopup*/
102    Evas_Object *bg;   
103    Evas_Object *hoversel;
104    Ecore_Job *deferred_recalc_job;
105    Ecore_Event_Handler *sel_notify_handler;
106    Ecore_Event_Handler *sel_clear_handler;
107    Ecore_Timer *longpress_timer;
108    /* Only for clipboard */
109    const char *cut_sel;
110    const char *text;
111    Evas_Coord wrap_w;
112    int ellipsis_threshold;
113    Evas_Coord lastw;
114    Evas_Coord downx, downy;
115    Evas_Coord cx, cy, cw, ch;
116    Eina_List *items;
117    Eina_List *item_providers;
118    Ecore_Job *hovdeljob;
119    Mod_Api *api; // module api if supplied
120    int max_no_of_bytes;
121    Eina_Bool changed : 1;
122    Eina_Bool linewrap : 1;
123    Eina_Bool char_linewrap : 1;
124    Eina_Bool single_line : 1;
125    Eina_Bool password : 1;
126    Eina_Bool show_last_character : 1;
127    Eina_Bool editable : 1;
128    Eina_Bool selection_asked : 1;
129    Eina_Bool have_selection : 1;
130    Eina_Bool selmode : 1;
131    Eina_Bool deferred_cur : 1;
132    Eina_Bool disabled : 1;
133    Eina_Bool 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 autocapitalize : 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->autocapitalize);
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", 1);
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", 1);
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", 0);
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", 0);
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", 0);
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", 0);
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
1089           {
1090              char tstr[16];
1091
1092              _strncpy(tstr, text + pos, pos2 - pos);
1093              tstr[pos2 - pos] = 0;
1094              str = _str_append(str, tstr, &str_len, &str_alloc);
1095           }
1096      }
1097    return str;
1098 }
1099
1100 static void
1101 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1102 {
1103    Widget_Data *wd = elm_widget_data_get(data);
1104    if (!wd) return;
1105    wd->changed = EINA_TRUE;
1106    _sizing_eval(data);
1107    if (wd->text) eina_stringshare_del(wd->text);
1108    wd->text = NULL;
1109    _check_enable_returnkey(data);   
1110    evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1111 }
1112
1113 static void
1114 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1115 {
1116    Widget_Data *wd = elm_widget_data_get(data);
1117    const Eina_List *l;
1118    Evas_Object *entry;
1119    if (!wd) return;
1120    EINA_LIST_FOREACH(entries, l, entry)
1121      {
1122         if (entry != data) elm_entry_select_none(entry);
1123      }
1124    wd->have_selection = EINA_TRUE;
1125    wd->selmode = EINA_TRUE;
1126    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1127 #ifdef HAVE_ELEMENTARY_X
1128    if (wd->sel_notify_handler)
1129      {
1130         const char *txt = elm_entry_selection_get(data);
1131         Evas_Object *top;
1132
1133         top = elm_widget_top_get(data);
1134         if ((top) && (elm_win_xwindow_get(top)))
1135              elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1136      }
1137 #endif
1138 }
1139
1140 static void
1141 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1142 {
1143    Widget_Data *wd = elm_widget_data_get(data);
1144    if (!wd) return;
1145    wd->have_selection = EINA_TRUE;
1146    wd->selmode = EINA_TRUE;
1147    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1148    elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1149                    elm_entry_selection_get(data));
1150 }
1151
1152 static void
1153 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1154 {
1155    Widget_Data *wd = elm_widget_data_get(data);
1156    if (!wd) return;
1157    if (!wd->have_selection) return;
1158    wd->have_selection = EINA_FALSE;
1159    wd->selmode = EINA_FALSE;
1160    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1161    if (wd->sel_notify_handler)
1162      {
1163         if (wd->cut_sel)
1164           {
1165 #ifdef HAVE_ELEMENTARY_X
1166              Evas_Object *top;
1167
1168              top = elm_widget_top_get(data);
1169              if ((top) && (elm_win_xwindow_get(top)))
1170                  elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1171                                        wd->cut_sel);
1172 #endif
1173              eina_stringshare_del(wd->cut_sel);
1174              wd->cut_sel = NULL;
1175           }
1176         else
1177           {
1178 #ifdef HAVE_ELEMENTARY_X
1179              Evas_Object *top;
1180
1181              top = elm_widget_top_get(data);
1182              if ((top) && (elm_win_xwindow_get(top)))
1183                 elm_selection_clear(ELM_SEL_PRIMARY, data);
1184 #endif
1185           }
1186      }
1187 }
1188
1189 static void
1190 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1191 {
1192    Widget_Data *wd = elm_widget_data_get(data);
1193    if (!wd) return;
1194    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1195    if (wd->sel_notify_handler)
1196      {
1197 #ifdef HAVE_ELEMENTARY_X
1198         Evas_Object *top;
1199
1200         top = elm_widget_top_get(data);
1201         if ((top) && (elm_win_xwindow_get(top)))
1202           {
1203              wd->selection_asked = EINA_TRUE;
1204              elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data);
1205           }
1206 #endif
1207      }
1208 }
1209
1210 static void
1211 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1212 {
1213    Widget_Data *wd = elm_widget_data_get(data);
1214    if (!wd) return;
1215    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1216    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1217                         elm_entry_selection_get(data));
1218 }
1219
1220 static void
1221 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1222 {
1223    Widget_Data *wd = elm_widget_data_get(data);
1224    if (!wd) return;
1225    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1226    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1227                         elm_entry_selection_get(data));
1228    edje_object_part_text_insert(wd->ent, "elm.text", "");
1229    wd->changed = EINA_TRUE;
1230    _sizing_eval(data);
1231 }
1232
1233 static void
1234 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1235 {
1236    Widget_Data *wd = elm_widget_data_get(data);
1237    Evas_Coord cx, cy, cw, ch;
1238    if (!wd) return;
1239    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1240    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1241                                              &cx, &cy, &cw, &ch);
1242    if (!wd->deferred_recalc_job)
1243      elm_widget_show_region_set(data, cx, cy, cw, ch);
1244    else
1245      {
1246         wd->deferred_cur = EINA_TRUE;
1247         wd->cx = cx;
1248         wd->cy = cy;
1249         wd->cw = cw;
1250         wd->ch = ch;
1251      }
1252 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1253    evas_object_smart_callback_call(data, SIG_IMPREGION_CHANGED, NULL);
1254 #endif
1255 }
1256
1257 static void
1258 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1259 {
1260    Widget_Data *wd = elm_widget_data_get(data);
1261    if (!wd) return;
1262 }
1263
1264 static void
1265 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1266 {
1267    Widget_Data *wd = elm_widget_data_get(data);
1268    Elm_Entry_Anchor_Info ei;
1269    char *buf2, *p, *p2, *n;
1270    if (!wd) return;
1271    p = strrchr(emission, ',');
1272    if (p)
1273      {
1274         const Eina_List *geoms;
1275
1276         n = p + 1;
1277         p2 = p -1;
1278         while (p2 >= emission)
1279           {
1280              if (*p2 == ',') break;
1281              p2--;
1282           }
1283         p2++;
1284         buf2 = alloca(5 + p - p2);
1285         strncpy(buf2, p2, p - p2);
1286         buf2[p - p2] = 0;
1287         ei.name = n;
1288         ei.button = atoi(buf2);
1289         ei.x = ei.y = ei.w = ei.h = 0;
1290         geoms =
1291           edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1292         if (geoms)
1293           {
1294              Evas_Textblock_Rectangle *r;
1295              const Eina_List *l;
1296              Evas_Coord px, py, x, y;
1297
1298              evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1299              evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1300              EINA_LIST_FOREACH(geoms, l, r)
1301                {
1302                   if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1303                       ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1304                     {
1305                        ei.x = r->x + x;
1306                        ei.y = r->y + y;
1307                        ei.w = r->w;
1308                        ei.h = r->h;
1309                        break;
1310                     }
1311                }
1312           }
1313         if (!wd->disabled)
1314           evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1315      }
1316 }
1317
1318 static void
1319 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1320 {
1321    Widget_Data *wd = elm_widget_data_get(data);
1322    if (!wd) return;
1323 }
1324
1325 static void
1326 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1327 {
1328    Widget_Data *wd = elm_widget_data_get(data);
1329    if (!wd) return;
1330 }
1331
1332 static void
1333 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1334 {
1335    Widget_Data *wd = elm_widget_data_get(data);
1336    if (!wd) return;
1337 }
1338
1339 static void
1340 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1341 {
1342    Widget_Data *wd = elm_widget_data_get(data);
1343    if (!wd) return;
1344    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1345 }
1346
1347 static void
1348 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1349 {
1350    Widget_Data *wd = elm_widget_data_get(data);
1351    if (!wd) return;
1352    wd->double_clicked = EINA_FALSE;
1353    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1354 }
1355
1356 static void
1357 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1358 {
1359    Widget_Data *wd = elm_widget_data_get(data);
1360    if (!wd) return;
1361    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1362 }
1363
1364 static void
1365 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1366 {
1367    Widget_Data *wd = elm_widget_data_get(data);
1368    if (!wd) return;
1369    wd->double_clicked = EINA_TRUE;
1370    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1371 }
1372
1373 #ifdef HAVE_ELEMENTARY_X
1374 static Eina_Bool
1375 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1376 {
1377    Widget_Data *wd = elm_widget_data_get(data);
1378    Ecore_X_Event_Selection_Notify *ev = event;
1379    if (!wd) return ECORE_CALLBACK_PASS_ON;
1380    if (!wd->selection_asked && !wd->drag_selection_asked)
1381       return ECORE_CALLBACK_PASS_ON;
1382
1383    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1384        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1385      {
1386         Ecore_X_Selection_Data_Text *text_data;
1387
1388         text_data = ev->data;
1389         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1390           {
1391              if (text_data->text)
1392                {
1393                   char *txt = _text_to_mkup(text_data->text);
1394
1395                   if (txt)
1396                     {
1397                        elm_entry_entry_insert(data, txt);
1398                        free(txt);
1399                     }
1400                }
1401           }
1402         wd->selection_asked = EINA_FALSE;
1403      }
1404    else if (ev->selection == ECORE_X_SELECTION_XDND)
1405      {
1406         Ecore_X_Selection_Data_Text *text_data;
1407
1408         text_data = ev->data;
1409         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1410           {
1411              if (text_data->text)
1412                {
1413                   char *txt = _text_to_mkup(text_data->text);
1414
1415                   if (txt)
1416                     {
1417                      /* Massive FIXME: this should be at the drag point */
1418                        elm_entry_entry_insert(data, txt);
1419                        free(txt);
1420                     }
1421                }
1422           }
1423         wd->drag_selection_asked = EINA_FALSE;
1424
1425         ecore_x_dnd_send_finished();
1426
1427      }
1428    return ECORE_CALLBACK_PASS_ON;
1429 }
1430
1431 static Eina_Bool
1432 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1433 {
1434 /*
1435    Widget_Data *wd = elm_widget_data_get(data);
1436    Ecore_X_Event_Selection_Clear *ev = event;
1437    if (!wd) return 1;
1438    if (!wd->have_selection) return 1;
1439    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1440        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1441      {
1442         elm_entry_select_none(data);
1443      }
1444    return 1;*/
1445
1446         // start for cbhm
1447    Evas_Object *top = elm_widget_top_get(data);
1448    Ecore_X_Event_Selection_Clear *ev = event;
1449
1450    if (!top)
1451            return ECORE_CALLBACK_PASS_ON;
1452
1453         if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1454         {
1455                 return ECORE_CALLBACK_PASS_ON;
1456         }
1457
1458         elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data);
1459         // end for cbhm
1460    return ECORE_CALLBACK_PASS_ON;
1461 }
1462
1463
1464 static Eina_Bool
1465 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Drop_Data *drop)
1466 {
1467    Widget_Data *wd;
1468    Eina_Bool rv;
1469
1470    wd = elm_widget_data_get(obj);
1471
1472    if (!wd) return EINA_FALSE;
1473 //printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1474
1475    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1476                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1477    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1478                                           EDJE_CURSOR_MAIN,drop->x,drop->y);
1479 //   if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1480    elm_entry_entry_insert(obj, drop->data);
1481    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1482                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1483
1484    return EINA_TRUE;
1485 }
1486 #endif
1487
1488 static Evas_Object *
1489 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1490 {
1491    Widget_Data *wd = elm_widget_data_get(data);
1492    Evas_Object *o;
1493    Eina_List *l;
1494    Elm_Entry_Item_Provider *ip;
1495    int ok = 0;
1496
1497    EINA_LIST_FOREACH(wd->item_providers, l, ip)
1498      {
1499         o = ip->func(ip->data, data, item);
1500         if (o) return o;
1501      }
1502    o = edje_object_add(evas_object_evas_get(data));
1503    if (!strncmp(item, "emoticon/", 9))
1504      ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1505    if (!ok)
1506      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1507    return o;
1508 }
1509
1510 static int
1511 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1512 {
1513    char *curlocater, *starttag, *endtag;
1514    int firstindex = 0, foundflag = -1;
1515
1516    curlocater = strstr(oldstring, key);
1517    if (curlocater)
1518      {
1519         starttag = curlocater;
1520         endtag = curlocater + strlen(key);
1521         if (endtag == NULL || *endtag != '=') 
1522           {
1523             foundflag = 0;
1524             return -1;
1525           }
1526
1527         firstindex = abs(oldstring - curlocater);
1528         firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1529         *value = (char*)oldstring + firstindex;
1530
1531         while (oldstring != starttag)
1532           {
1533             if (*starttag == '>')
1534               {
1535                 foundflag = 0;
1536                 break;
1537               }
1538             if (*starttag == '<') 
1539               break;
1540             else 
1541               starttag--;
1542             if (starttag == NULL) break;
1543           }
1544
1545         while (NULL != endtag)
1546           {
1547             if (*endtag == '<')
1548               {
1549                 foundflag = 0;
1550                 break;
1551               }
1552             if (*endtag == '>') 
1553               break;
1554             else 
1555               endtag++;
1556             if (endtag == NULL) break;
1557           }
1558
1559         if (foundflag != 0 && *starttag == '<' && *endtag == '>') 
1560           foundflag = 1;
1561         else 
1562           foundflag = 0;
1563      }
1564    else
1565      {
1566        foundflag = 0;
1567      }
1568
1569    if (foundflag == 1) return 0;
1570
1571    return -1;
1572 }
1573
1574 static int
1575 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1576 {
1577    const char *srcstring = NULL;
1578    Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1579    char *curlocater, *replocater;
1580    char *starttag, *endtag;
1581    int tagtxtlen = 0, insertflag = 0;
1582
1583    srcstring = eina_strbuf_string_get(srcbuf);
1584    curlocater = strstr(srcstring, key);
1585
1586    if (curlocater == NULL)
1587      {
1588        insertflag = 1;
1589      }
1590    else
1591      {
1592        do 
1593          {
1594            starttag = strchr(srcstring, '<');
1595            endtag = strchr(srcstring, '>');
1596            tagtxtlen = endtag - starttag;
1597            if (tagtxtlen <= 0) tagtxtlen = 0;
1598            if (starttag < curlocater && curlocater < endtag) break;
1599            if (endtag != NULL && endtag+1 != NULL)
1600              srcstring = endtag+1;
1601            else
1602              break;
1603          } while (strlen(srcstring) > 1);
1604
1605        if (starttag && endtag && tagtxtlen > strlen(key))
1606          {
1607            repbuf = eina_strbuf_new();
1608            diffbuf = eina_strbuf_new();
1609            eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1610            srcstring = eina_strbuf_string_get(repbuf);
1611            curlocater = strstr(srcstring, key);
1612
1613            if (curlocater != NULL)
1614              {
1615                replocater = curlocater + strlen(key) + 1;
1616
1617                while (*replocater == ' ' || *replocater == '=')
1618                            {
1619                  replocater++;
1620                            }
1621
1622                 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1623                   replocater++;
1624
1625                if (replocater-curlocater > strlen(key)+1)
1626                  {
1627                    replocater--;
1628                    eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1629                  }
1630                else
1631                  insertflag = 1;
1632              }
1633            else
1634              {
1635                insertflag = 1;
1636              }
1637            eina_strbuf_reset(repbuf);
1638          }
1639        else
1640          {
1641            insertflag = 1; 
1642          }
1643      }
1644
1645    if (repbuf == NULL) repbuf = eina_strbuf_new();
1646    if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1647
1648    if (insertflag)
1649      {
1650        eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1651        eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1652      }
1653    else
1654      {
1655         if (deleteflag)
1656           {
1657             eina_strbuf_prepend(diffbuf, "<");
1658             eina_strbuf_append(diffbuf, ">");
1659             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1660           }
1661         else
1662           {
1663             eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1664             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1665           }
1666      }
1667
1668    if (repbuf) eina_strbuf_free(repbuf);
1669    if (diffbuf) eina_strbuf_free(diffbuf);
1670   
1671    return 0;           
1672 }
1673
1674 static int
1675 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1676 {
1677    Eina_Strbuf *sharebuf = NULL;   
1678    
1679    sharebuf = eina_strbuf_new();
1680    eina_strbuf_append(sharebuf, *srcstring);
1681    _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1682    eina_stringshare_del(*srcstring);
1683    *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1684    eina_strbuf_free(sharebuf);
1685
1686    return 0;
1687 }
1688
1689 static int
1690 _is_width_over(Evas_Object *obj)
1691 {
1692    Evas_Coord x, y, w, h;
1693    Evas_Coord vx, vy, vw, vh;
1694    Widget_Data *wd = elm_widget_data_get(obj);
1695
1696    if (!wd) return 0;
1697
1698    edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1699
1700    evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1701
1702    if (x >= 0 && y >= 0)
1703            return 0;
1704
1705    if (4 < wd->wrap_w && w > wd->wrap_w)
1706            return 1;
1707
1708    return 0;
1709 }
1710
1711 static void
1712 _reverse_ellipsis_entry(Evas_Object *obj)
1713 {
1714    Widget_Data *wd = elm_widget_data_get(obj);
1715    int cur_fontsize = 0;
1716    Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1717    char **kvalue = NULL;
1718    const char *minfont, *deffont, *maxfont;
1719    const char *ellipsis_string = "...";
1720    int minfontsize, maxfontsize, minshowcount;
1721
1722    minshowcount = strlen(ellipsis_string) + 1;
1723    minfont = edje_object_data_get(wd->ent, "min_font_size");
1724    if (minfont) minfontsize = atoi(minfont);
1725    else minfontsize = 1;
1726    maxfont = edje_object_data_get(wd->ent, "max_font_size");
1727    if (maxfont) maxfontsize = atoi(maxfont);
1728    else maxfontsize = 1;
1729    deffont = edje_object_data_get(wd->ent, "default_font_size");
1730    if (deffont) cur_fontsize = atoi(deffont);
1731    else cur_fontsize = 1;
1732    if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1733    if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1734
1735    if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1736      {
1737        if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1738      }
1739
1740    txtbuf = eina_strbuf_new();
1741    eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1742
1743    if (cur_fontsize >= atoi(deffont))
1744      {
1745        if (txtbuf) eina_strbuf_free(txtbuf);
1746        return;
1747      }
1748
1749    if (_is_width_over(obj) != 1)
1750      {
1751        int rev_fontsize = cur_fontsize;
1752   
1753        do {
1754            rev_fontsize++;
1755            if (rev_fontsize > atoi(deffont))
1756              break;
1757
1758            if (fontbuf != NULL)
1759              {
1760                eina_strbuf_free(fontbuf);
1761                fontbuf = NULL;
1762              }
1763            fontbuf = eina_strbuf_new();
1764            eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1765            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1766            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1767
1768            eina_strbuf_free(fontbuf);
1769            fontbuf = NULL;
1770          } while (_is_width_over(obj) != 1);
1771
1772        while (_is_width_over(obj))
1773          {
1774            rev_fontsize--;
1775            if (rev_fontsize < atoi(deffont))
1776              break;
1777
1778            if (fontbuf != NULL)
1779              {
1780                eina_strbuf_free(fontbuf);
1781                fontbuf = NULL;
1782              }
1783            fontbuf = eina_strbuf_new();
1784            eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1785            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1786            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1787            eina_strbuf_free(fontbuf);
1788            fontbuf = NULL;
1789          }
1790      }
1791
1792    if (txtbuf) eina_strbuf_free(txtbuf);
1793    wd->changed = 1;
1794    _sizing_eval(obj);
1795 }
1796
1797 static void
1798 _ellipsis_entry_to_width(Evas_Object *obj)
1799 {
1800    Widget_Data *wd = elm_widget_data_get(obj);
1801    int cur_fontsize = 0, len, jumpcount;
1802    Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1803    char **kvalue = NULL;
1804    const char *minfont, *deffont, *maxfont;
1805    const char *ellipsis_string = "...";
1806    int minfontsize, maxfontsize, minshowcount;
1807    int i, tagend, cur_len;
1808    char *cur_str;
1809
1810    minshowcount = strlen(ellipsis_string) + 1;
1811    minfont = edje_object_data_get(wd->ent, "min_font_size");
1812    if (minfont) minfontsize = atoi(minfont);
1813    else minfontsize = 1;
1814    maxfont = edje_object_data_get(wd->ent, "max_font_size");
1815    if (maxfont) maxfontsize = atoi(maxfont);
1816    else maxfontsize = 1;
1817    deffont = edje_object_data_get(wd->ent, "default_font_size");
1818    if (deffont) cur_fontsize = atoi(deffont);
1819    else cur_fontsize = 1;
1820    if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1821    if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1822
1823    if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1824      {
1825        if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1826      }
1827
1828    txtbuf = eina_strbuf_new();
1829    eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1830
1831    while (_is_width_over(obj))
1832      {
1833        if (wd->ellipsis_threshold == 0)
1834          wd->ellipsis_threshold = _entry_length_get(obj);
1835        if (cur_fontsize > minfontsize)
1836          {
1837            cur_fontsize--;
1838            if (fontbuf != NULL)
1839              {
1840                eina_strbuf_free(fontbuf);
1841                fontbuf = NULL;
1842              }
1843            fontbuf = eina_strbuf_new();
1844            eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1845            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1846            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1847            eina_strbuf_free(fontbuf);
1848            fontbuf = NULL;
1849                    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1850          }
1851        else
1852          {
1853            len = _entry_length_get(obj);
1854            cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1855            cur_len = strlen(cur_str);
1856            tagend = 0;
1857            for (i = 0; i < len; i++)
1858              {
1859                if(cur_str[i] == '>' && cur_str[i+1] != NULL && 
1860                   cur_str[i+1] != '<')
1861                  {
1862                    tagend = i;
1863                    break;
1864                  }
1865              }
1866            jumpcount = 0;
1867            while (jumpcount < len-strlen(ellipsis_string))
1868              {
1869                cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1870
1871                if (txtbuf != NULL)
1872                  {
1873                    eina_strbuf_free(txtbuf);
1874                    txtbuf = NULL;
1875                  }
1876                txtbuf = eina_strbuf_new();
1877                eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1878                eina_strbuf_append(txtbuf, ellipsis_string);
1879                eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1880                edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1881                edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1882
1883                if (_is_width_over(obj)) 
1884                  jumpcount++;
1885                else 
1886                  break;
1887              }
1888          }
1889      }
1890
1891    if (txtbuf) eina_strbuf_free(txtbuf);
1892    wd->changed = 1;
1893    _sizing_eval(obj);
1894 }
1895
1896 static int _textinput_control_function(void *data,void *input_data)
1897 {
1898    /*calculate character count*/
1899    Evas_Object *entry = (Evas_Object *)data;
1900    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1901    char buf[10]="\0";
1902    size_t byte_len;
1903    size_t insert_text_len=0;
1904    char *text = edje_object_part_text_get(wd->ent, "elm.text");
1905    char *insert_text;  
1906    size_t remain_bytes;
1907    if(text!=NULL)
1908      {
1909        byte_len = strlen(text);/*no of bytes*/
1910        remain_bytes = wd->max_no_of_bytes-byte_len;
1911        sprintf(buf,"%d",remain_bytes);
1912        edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1913        if(input_data)
1914          {
1915            insert_text =  (char *)input_data;
1916            insert_text_len = strlen(insert_text);
1917            if(remain_bytes<insert_text_len)
1918              {
1919                evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1920                return EINA_TRUE;
1921              }
1922            if(byte_len>=wd->max_no_of_bytes)
1923              {
1924                evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1925                return EINA_TRUE;
1926              }
1927          }
1928      }
1929    return EINA_FALSE;  
1930 }
1931
1932 /**
1933  * This adds an entry to @p parent object.
1934  *
1935  * @param parent The parent object
1936  * @return The new object or NULL if it cannot be created
1937  *
1938  * @ingroup Entry
1939  */
1940 EAPI Evas_Object *
1941 elm_entry_add(Evas_Object *parent)
1942 {
1943    Evas_Object *obj, *top;
1944    Evas *e;
1945    Widget_Data *wd;
1946
1947    wd = ELM_NEW(Widget_Data);
1948    e = evas_object_evas_get(parent);
1949    wd->bgcolor = EINA_FALSE;
1950    wd->bg = evas_object_rectangle_add(e);
1951    evas_object_color_set(wd->bg, 0, 0, 0, 0);
1952    obj = elm_widget_add(e);
1953    ELM_SET_WIDTYPE(widtype, "entry");
1954    elm_widget_type_set(obj, "entry");
1955    elm_widget_sub_object_add(parent, obj);
1956    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1957    elm_widget_data_set(obj, wd);
1958    elm_widget_del_hook_set(obj, _del_hook);
1959    elm_widget_theme_hook_set(obj, _theme_hook);
1960    elm_widget_disable_hook_set(obj, _disable_hook);
1961    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1962    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1963    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1964    elm_widget_can_focus_set(obj, 1);
1965 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1966    elm_widget_imp_region_get_hook_set(obj, _imp_region_get_hook, NULL);
1967 #endif
1968
1969    wd->linewrap     = EINA_TRUE;
1970    wd->ellipsis     = EINA_FALSE;
1971    wd->char_linewrap= EINA_FALSE;
1972    wd->editable     = EINA_TRUE;
1973    wd->disabled     = EINA_FALSE;
1974    wd->context_menu = EINA_TRUE;
1975
1976    wd->ellipsis_threshold = 0;
1977
1978    wd->ent = edje_object_add(e);
1979    edje_object_item_provider_set(wd->ent, _get_item, obj);
1980    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1981    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1982    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1983                                   _mouse_down, obj);
1984    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1985                                   _mouse_up, obj);
1986    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1987                                   _mouse_move, obj);
1988
1989    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1990    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1991                                    _signal_entry_changed, obj);
1992    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1993                                    _signal_selection_start, obj);
1994    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1995                                    _signal_selection_changed, obj);
1996    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1997                                    _signal_selection_cleared, obj);
1998    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1999                                    _signal_entry_paste_request, obj);
2000    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2001                                    _signal_entry_copy_notify, obj);
2002    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2003                                    _signal_entry_cut_notify, obj);
2004    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2005                                    _signal_cursor_changed, obj);
2006    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2007                                    _signal_anchor_down, obj);
2008    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2009                                    _signal_anchor_up, obj);
2010    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2011                                    _signal_anchor_move, obj);
2012    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2013                                    _signal_anchor_in, obj);
2014    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2015                                    _signal_anchor_out, obj);
2016    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2017                                    _signal_key_enter, obj);
2018    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2019                                    _signal_mouse_down, obj);
2020    edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
2021                                    _signal_mouse_up, obj);
2022    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2023                                    _signal_mouse_double, obj);
2024    edje_object_part_text_set(wd->ent, "elm.text", "");
2025    elm_widget_resize_object_set(obj, wd->ent);
2026    _sizing_eval(obj);
2027
2028    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2029
2030 #ifdef HAVE_ELEMENTARY_X
2031    top = elm_widget_top_get(obj);
2032    if ((top) && (elm_win_xwindow_get(top)))
2033      {
2034         wd->sel_notify_handler =
2035           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2036                                   _event_selection_notify, obj);
2037         wd->sel_clear_handler =
2038           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2039                                   _event_selection_clear, obj);
2040      }
2041
2042    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2043 #endif
2044
2045    entries = eina_list_prepend(entries, obj);
2046
2047    // module - find module for entry
2048    wd->api = _module(obj);
2049    // if found - hook in
2050    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2051
2052    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2053    // TODO: and save some bytes, making descriptions per-class and not instance!
2054    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2055    return obj;
2056 }
2057
2058 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2059 {
2060    ELM_CHECK_WIDTYPE(obj, widtype);
2061    Widget_Data *wd = elm_widget_data_get(obj);
2062    if (!wd) return;
2063    ext_mod->cancel = _cancel;
2064    ext_mod->copy = _copy;
2065    ext_mod->cut = _cut;
2066    ext_mod->paste = _paste;
2067    ext_mod->select = _select;
2068    ext_mod->selectall = NULL; /* to be implemented*/
2069    ext_mod->ent = wd->ent;
2070    ext_mod->items = wd->items;
2071    ext_mod->longpress_timer = wd->longpress_timer;
2072    ext_mod->editable = wd->editable;
2073    ext_mod->have_selection = wd->have_selection;
2074    ext_mod->password = wd->password;
2075    ext_mod->selmode = wd->selmode;
2076    ext_mod->context_menu = wd->context_menu;
2077 }
2078
2079 /**
2080  * This sets the entry object not to line wrap.  All input will
2081  * be on a single line, and the entry box will extend with user input.
2082  *
2083  * @param obj The entry object
2084  * @param single_line If true, the text in the entry
2085  * will be on a single line.
2086  *
2087  * @ingroup Entry
2088  */
2089 EAPI void
2090 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2091 {
2092    ELM_CHECK_WIDTYPE(obj, widtype);
2093    Widget_Data *wd = elm_widget_data_get(obj);
2094    const char *t;
2095    Ecore_IMF_Context *ic;
2096    if (!wd) return;
2097    if (wd->single_line == single_line) return;
2098    wd->single_line = single_line;
2099    wd->linewrap = EINA_FALSE;
2100    wd->char_linewrap = EINA_FALSE;
2101    t = eina_stringshare_add(elm_entry_entry_get(obj));
2102    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2103    elm_entry_entry_set(obj, t);
2104    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2105    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2106    ic = elm_entry_imf_context_get(obj);
2107    if (ic)
2108      {
2109         ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2110      }
2111
2112    eina_stringshare_del(t);
2113    _sizing_eval(obj);
2114 }
2115
2116 /**
2117  * This returns true if the entry has been set to single line mode.
2118  * See also elm_entry_single_line_set().
2119  *
2120  * @param obj The entry object
2121  * @return single_line If true, the text in the entry is set to display
2122  * on a single line.
2123  *
2124  * @ingroup Entry
2125  */
2126 EAPI Eina_Bool
2127 elm_entry_single_line_get(const Evas_Object *obj)
2128 {
2129    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2130    Widget_Data *wd = elm_widget_data_get(obj);
2131    if (!wd) return EINA_FALSE;
2132    return wd->single_line;
2133 }
2134
2135 /**
2136  * This set's the maximum bytes that can be added in entry.
2137  *
2138  * @param obj The entry object
2139  * @param max_no_of_bytes Maximum number of bytes entry can have.
2140  * 
2141  * @ingroup Entry
2142  */
2143 EAPI void
2144 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2145 {
2146    Widget_Data *wd = elm_widget_data_get(obj);
2147
2148    wd->max_no_of_bytes = max_no_of_bytes;
2149    edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2150    edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2151  }
2152
2153
2154 /**
2155  * This sets the entry object to password mode.  All text entered
2156  * and/or displayed within the widget will be replaced with asterisks (*).
2157  *
2158  * @param obj The entry object
2159  * @param password If true, password mode is enabled.
2160  *
2161  * @ingroup Entry
2162  */
2163 EAPI void
2164 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2165 {
2166    ELM_CHECK_WIDTYPE(obj, widtype);
2167    Widget_Data *wd = elm_widget_data_get(obj);
2168    Ecore_IMF_Context *ic;
2169    const char *t;
2170    if (!wd) return;
2171    if (wd->password == password) return;
2172    wd->password = password;
2173    wd->show_last_character = EINA_FALSE;
2174    wd->single_line = EINA_TRUE;
2175    wd->linewrap = EINA_FALSE;
2176    wd->char_linewrap = EINA_FALSE;
2177    t = eina_stringshare_add(elm_entry_entry_get(obj));
2178    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2179    elm_entry_entry_set(obj, t);
2180
2181    ic = elm_entry_imf_context_get(obj);
2182    if (ic)
2183      {
2184         ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2185      }
2186
2187    eina_stringshare_del(t);
2188    _sizing_eval(obj);
2189 }
2190
2191 /**
2192  * This set's the entry in password mode with out masking the last character entered by user,
2193  * and later masking the character after 2 seconds.
2194  
2195  * @param obj The entry object
2196  * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character" 
2197  * 0 for default).
2198  *
2199  * @ingroup Entry
2200  */
2201 EAPI void         
2202 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2203 {
2204    Widget_Data *wd = elm_widget_data_get(obj);
2205    const char *t;
2206    if (!wd) return;
2207    if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character))  return;
2208    wd->show_last_character = show_last_character;
2209    wd->password = show_last_character;
2210    wd->single_line = EINA_TRUE;
2211    wd->linewrap = EINA_FALSE;
2212    wd->char_linewrap = EINA_FALSE;
2213    t = eina_stringshare_add(elm_entry_entry_get(obj));
2214     _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2215    elm_entry_entry_set(obj, t);
2216    eina_stringshare_del(t);
2217    _sizing_eval(obj);
2218 }
2219
2220 /**
2221  * This returns whether password mode is enabled.
2222  * See also elm_entry_password_set().
2223  *
2224  * @param obj The entry object
2225  * @return If true, the entry is set to display all characters
2226  * as asterisks (*).
2227  *
2228  * @ingroup Entry
2229  */
2230 EAPI Eina_Bool
2231 elm_entry_password_get(const Evas_Object *obj)
2232 {
2233    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2234    Widget_Data *wd = elm_widget_data_get(obj);
2235    if (!wd) return EINA_FALSE;
2236    return wd->password;
2237 }
2238
2239 /**
2240  * This sets the text displayed within the entry to @p entry.
2241  *
2242  * @param obj The entry object
2243  * @param entry The text to be displayed
2244  *
2245  * @ingroup Entry
2246  */
2247 EAPI void
2248 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2249 {
2250    ELM_CHECK_WIDTYPE(obj, widtype);
2251    Widget_Data *wd = elm_widget_data_get(obj);
2252    if (!wd) return;
2253    if (!entry) entry = "";
2254    if(wd->max_no_of_bytes)
2255      {
2256        int len = strlen(entry);
2257        if(len > wd->max_no_of_bytes)
2258        {
2259          ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2260          return;
2261        }
2262      }
2263    edje_object_part_text_set(wd->ent, "elm.text", entry);
2264    if (wd->text) eina_stringshare_del(wd->text);
2265    wd->text = NULL;
2266    wd->changed = EINA_TRUE;
2267    _sizing_eval(obj);
2268 }
2269
2270 /**
2271  * This returns the text currently shown in object @p entry.
2272  * See also elm_entry_entry_set().
2273  *
2274  * @param obj The entry object
2275  * @return The currently displayed text or NULL on failure
2276  *
2277  * @ingroup Entry
2278  */
2279 EAPI const char *
2280 elm_entry_entry_get(const Evas_Object *obj)
2281 {
2282    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2283    Widget_Data *wd = elm_widget_data_get(obj);
2284    const char *text;
2285    if (!wd) return NULL;
2286    if (wd->text) return wd->text;
2287    text = edje_object_part_text_get(wd->ent, "elm.text");
2288    if (!text)
2289      {
2290         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2291         return NULL;
2292      }
2293    eina_stringshare_replace(&wd->text, text);
2294    return wd->text;
2295 }
2296
2297 /**
2298  * This returns all selected text within the entry.
2299  *
2300  * @param obj The entry object
2301  * @return The selected text within the entry or NULL on failure
2302  *
2303  * @ingroup Entry
2304  */
2305 EAPI const char *
2306 elm_entry_selection_get(const Evas_Object *obj)
2307 {
2308    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2309    Widget_Data *wd = elm_widget_data_get(obj);
2310    if (!wd) return NULL;
2311    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2312 }
2313
2314 /**
2315  * This inserts text in @p entry at the beginning of the entry
2316  * object.
2317  *
2318  * @param obj The entry object
2319  * @param entry The text to insert
2320  *
2321  * @ingroup Entry
2322  */
2323 EAPI void
2324 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2325 {
2326    ELM_CHECK_WIDTYPE(obj, widtype);
2327    Widget_Data *wd = elm_widget_data_get(obj);
2328    if (!wd) return;
2329    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2330    wd->changed = EINA_TRUE;
2331    _sizing_eval(obj);
2332 }
2333
2334 /**
2335  * This enables word line wrapping in the entry object.  It is the opposite
2336  * of elm_entry_single_line_set().  Additionally, setting this disables
2337  * character line wrapping.
2338  * See also elm_entry_line_char_wrap_set().
2339  *
2340  * @param obj The entry object
2341  * @param wrap If true, the entry will be wrapped once it reaches the end
2342  * of the object. Wrapping will occur at the end of the word before the end of the
2343  * object.
2344  *
2345  * @ingroup Entry
2346  */
2347 EAPI void
2348 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2349 {
2350    ELM_CHECK_WIDTYPE(obj, widtype);
2351    Widget_Data *wd = elm_widget_data_get(obj);
2352    const char *t;
2353    if (!wd) return;
2354    if (wd->linewrap == wrap) return;
2355    wd->linewrap = wrap;
2356    if(wd->linewrap)
2357        wd->char_linewrap = EINA_FALSE;
2358    t = eina_stringshare_add(elm_entry_entry_get(obj));
2359    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2360    elm_entry_entry_set(obj, t);
2361    eina_stringshare_del(t);
2362    _sizing_eval(obj);
2363 }
2364
2365 /**
2366  * Set wrap width of the entry
2367  *
2368  * @param obj The entry object
2369  * @param w The wrap width in pixels at a minimum where words need to wrap
2370  * @ingroup Entry
2371  */
2372 EAPI void
2373 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2374 {
2375    Widget_Data *wd = elm_widget_data_get(obj);
2376    if (wd->wrap_w == w) return;
2377    wd->wrap_w = w;
2378    _sizing_eval(obj);
2379 }
2380
2381 /**
2382  * get wrap width of the entry
2383  *
2384  * @param obj The entry object
2385  * @return The wrap width in pixels at a minimum where words need to wrap
2386  * @ingroup Entry
2387  */
2388 EAPI Evas_Coord
2389 elm_entry_wrap_width_get(const Evas_Object *obj)
2390 {
2391    Widget_Data *wd = elm_widget_data_get(obj);
2392    return wd->wrap_w;
2393 }
2394
2395 /**
2396  * This enables character line wrapping in the entry object.  It is the opposite
2397  * of elm_entry_single_line_set().  Additionally, setting this disables
2398  * word line wrapping.
2399  * See also elm_entry_line_wrap_set().
2400  *
2401  * @param obj The entry object
2402  * @param wrap If true, the entry will be wrapped once it reaches the end
2403  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2404  *
2405  * @ingroup Entry
2406  */
2407 EAPI void
2408 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2409 {
2410    ELM_CHECK_WIDTYPE(obj, widtype);
2411    Widget_Data *wd = elm_widget_data_get(obj);
2412    const char *t;
2413    if (!wd) return;
2414    if (wd->char_linewrap == wrap) return;
2415    wd->char_linewrap = wrap;
2416    if(wd->char_linewrap)
2417        wd->linewrap = EINA_FALSE;
2418    t = eina_stringshare_add(elm_entry_entry_get(obj));
2419    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2420    elm_entry_entry_set(obj, t);
2421    eina_stringshare_del(t);
2422    _sizing_eval(obj);
2423 }
2424
2425 /**
2426  * This sets the editable attribute of the entry.
2427  *
2428  * @param obj The entry object
2429  * @param editable If true, the entry will be editable by the user.
2430  * If false, it will be set to the disabled state.
2431  *
2432  * @ingroup Entry
2433  */
2434 EAPI void
2435 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2436 {
2437    ELM_CHECK_WIDTYPE(obj, widtype);
2438    Widget_Data *wd = elm_widget_data_get(obj);
2439    const char *t;
2440    if (!wd) return;
2441    if (wd->editable == editable) return;
2442    wd->editable = editable;
2443    t = eina_stringshare_add(elm_entry_entry_get(obj));
2444    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2445    elm_entry_entry_set(obj, t);
2446    eina_stringshare_del(t);
2447    _sizing_eval(obj);
2448
2449 #ifdef HAVE_ELEMENTARY_X
2450    if (editable)
2451       elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2452    else
2453       elm_drop_target_del(obj);
2454 #endif
2455 }
2456
2457 /**
2458  * This gets the editable attribute of the entry.
2459  * See also elm_entry_editable_set().
2460  *
2461  * @param obj The entry object
2462  * @return If true, the entry is editable by the user.
2463  * If false, it is not editable by the user
2464  *
2465  * @ingroup Entry
2466  */
2467 EAPI Eina_Bool
2468 elm_entry_editable_get(const Evas_Object *obj)
2469 {
2470    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2471    Widget_Data *wd = elm_widget_data_get(obj);
2472    if (!wd) return EINA_FALSE;
2473    return wd->editable;
2474 }
2475
2476 /**
2477  * This drops any existing text selection within the entry.
2478  *
2479  * @param obj The entry object
2480  *
2481  * @ingroup Entry
2482  */
2483 EAPI void
2484 elm_entry_select_none(Evas_Object *obj)
2485 {
2486    ELM_CHECK_WIDTYPE(obj, widtype);
2487    Widget_Data *wd = elm_widget_data_get(obj);
2488    if (!wd) return;
2489    if (wd->selmode)
2490      {
2491         wd->selmode = EINA_FALSE;
2492         edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2493         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2494      }
2495    wd->have_selection = EINA_FALSE;
2496    edje_object_part_text_select_none(wd->ent, "elm.text");
2497 }
2498
2499 /**
2500  * This selects all text within the entry.
2501  *
2502  * @param obj The entry object
2503  *
2504  * @ingroup Entry
2505  */
2506 EAPI void
2507 elm_entry_select_all(Evas_Object *obj)
2508 {
2509    ELM_CHECK_WIDTYPE(obj, widtype);
2510    Widget_Data *wd = elm_widget_data_get(obj);
2511    if (!wd) return;
2512    if (wd->selmode)
2513      {
2514         wd->selmode = EINA_FALSE;
2515         edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2516         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2517      }
2518    wd->have_selection = EINA_TRUE;
2519    edje_object_part_text_select_all(wd->ent, "elm.text");
2520 }
2521
2522 /**
2523  * This moves the cursor one place to the right within the entry.
2524  *
2525  * @param obj The entry object
2526  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2527  *
2528  * @ingroup Entry
2529  */
2530 EAPI Eina_Bool
2531 elm_entry_cursor_next(Evas_Object *obj)
2532 {
2533    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2534    Widget_Data *wd = elm_widget_data_get(obj);
2535    if (!wd) return EINA_FALSE;
2536    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2537 }
2538
2539 /**
2540  * This moves the cursor one place to the left within the entry.
2541  *
2542  * @param obj The entry object
2543  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2544  *
2545  * @ingroup Entry
2546  */
2547 EAPI Eina_Bool
2548 elm_entry_cursor_prev(Evas_Object *obj)
2549 {
2550    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2551    Widget_Data *wd = elm_widget_data_get(obj);
2552    if (!wd) return EINA_FALSE;
2553    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2554 }
2555
2556 /**
2557  * This moves the cursor one line up within the entry.
2558  *
2559  * @param obj The entry object
2560  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2561  *
2562  * @ingroup Entry
2563  */
2564 EAPI Eina_Bool
2565 elm_entry_cursor_up(Evas_Object *obj)
2566 {
2567    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2568    Widget_Data *wd = elm_widget_data_get(obj);
2569    if (!wd) return EINA_FALSE;
2570    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2571 }
2572
2573 /**
2574  * This moves the cursor one line down within the entry.
2575  *
2576  * @param obj The entry object
2577  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2578  *
2579  * @ingroup Entry
2580  */
2581 EAPI Eina_Bool
2582 elm_entry_cursor_down(Evas_Object *obj)
2583 {
2584    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2585    Widget_Data *wd = elm_widget_data_get(obj);
2586    if (!wd) return EINA_FALSE;
2587    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2588 }
2589
2590 /**
2591  * This moves the cursor to the beginning of the entry.
2592  *
2593  * @param obj The entry object
2594  *
2595  * @ingroup Entry
2596  */
2597 EAPI void
2598 elm_entry_cursor_begin_set(Evas_Object *obj)
2599 {
2600    ELM_CHECK_WIDTYPE(obj, widtype);
2601    Widget_Data *wd = elm_widget_data_get(obj);
2602    if (!wd) return;
2603    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2604 }
2605
2606 /**
2607  * This moves the cursor to the end of the entry.
2608  *
2609  * @param obj The entry object
2610  *
2611  * @ingroup Entry
2612  */
2613 EAPI void
2614 elm_entry_cursor_end_set(Evas_Object *obj)
2615 {
2616    ELM_CHECK_WIDTYPE(obj, widtype);
2617    Widget_Data *wd = elm_widget_data_get(obj);
2618    if (!wd) return;
2619    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2620 }
2621
2622 /**
2623  * This moves the cursor to the beginning of the current line.
2624  *
2625  * @param obj The entry object
2626  *
2627  * @ingroup Entry
2628  */
2629 EAPI void
2630 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2631 {
2632    ELM_CHECK_WIDTYPE(obj, widtype);
2633    Widget_Data *wd = elm_widget_data_get(obj);
2634    if (!wd) return;
2635    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2636 }
2637
2638 /**
2639  * This moves the cursor to the end of the current line.
2640  *
2641  * @param obj The entry object
2642  *
2643  * @ingroup Entry
2644  */
2645 EAPI void
2646 elm_entry_cursor_line_end_set(Evas_Object *obj)
2647 {
2648    ELM_CHECK_WIDTYPE(obj, widtype);
2649    Widget_Data *wd = elm_widget_data_get(obj);
2650    if (!wd) return;
2651    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2652 }
2653
2654 /**
2655  * This begins a selection within the entry as though
2656  * the user were holding down the mouse button to make a selection.
2657  *
2658  * @param obj The entry object
2659  *
2660  * @ingroup Entry
2661  */
2662 EAPI void
2663 elm_entry_cursor_selection_begin(Evas_Object *obj)
2664 {
2665    ELM_CHECK_WIDTYPE(obj, widtype);
2666    Widget_Data *wd = elm_widget_data_get(obj);
2667    if (!wd) return;
2668    edje_object_part_text_select_begin(wd->ent, "elm.text");
2669 }
2670
2671 /**
2672  * This ends a selection within the entry as though
2673  * the user had just released the mouse button while making a selection.
2674  *
2675  * @param obj The entry object
2676  *
2677  * @ingroup Entry
2678  */
2679 EAPI void
2680 elm_entry_cursor_selection_end(Evas_Object *obj)
2681 {
2682    ELM_CHECK_WIDTYPE(obj, widtype);
2683    Widget_Data *wd = elm_widget_data_get(obj);
2684    if (!wd) return;
2685    edje_object_part_text_select_extend(wd->ent, "elm.text");
2686 }
2687
2688 /**
2689  * TODO: fill this in
2690  *
2691  * @param obj The entry object
2692  * @return TODO: fill this in
2693  *
2694  * @ingroup Entry
2695  */
2696 EAPI Eina_Bool
2697 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2698 {
2699    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2700    Widget_Data *wd = elm_widget_data_get(obj);
2701    if (!wd) return EINA_FALSE;
2702    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2703 }
2704
2705 /**
2706  * This returns whether the cursor is visible.
2707  *
2708  * @param obj The entry object
2709  * @return If true, the cursor is visible.
2710  *
2711  * @ingroup Entry
2712  */
2713 EAPI Eina_Bool
2714 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2715 {
2716    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2717    Widget_Data *wd = elm_widget_data_get(obj);
2718    if (!wd) return EINA_FALSE;
2719    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2720 }
2721
2722 /**
2723  * TODO: fill this in
2724  *
2725  * @param obj The entry object
2726  * @return TODO: fill this in
2727  *
2728  * @ingroup Entry
2729  */
2730 EAPI const char *
2731 elm_entry_cursor_content_get(const Evas_Object *obj)
2732 {
2733    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2734    Widget_Data *wd = elm_widget_data_get(obj);
2735    if (!wd) return NULL;
2736    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2737 }
2738
2739 /**
2740  * This executes a "cut" action on the selected text in the entry.
2741  *
2742  * @param obj The entry object
2743  *
2744  * @ingroup Entry
2745  */
2746 EAPI void
2747 elm_entry_selection_cut(Evas_Object *obj)
2748 {
2749    ELM_CHECK_WIDTYPE(obj, widtype);
2750    Widget_Data *wd = elm_widget_data_get(obj);
2751    if (!wd) return;
2752    _cut(obj, NULL, NULL);
2753 }
2754
2755 /**
2756  * This executes a "copy" action on the selected text in the entry.
2757  *
2758  * @param obj The entry object
2759  *
2760  * @ingroup Entry
2761  */
2762 EAPI void
2763 elm_entry_selection_copy(Evas_Object *obj)
2764 {
2765    ELM_CHECK_WIDTYPE(obj, widtype);
2766    Widget_Data *wd = elm_widget_data_get(obj);
2767    if (!wd) return;
2768    _copy(obj, NULL, NULL);
2769 }
2770
2771 /**
2772  * This executes a "paste" action in the entry.
2773  *
2774  * @param obj The entry object
2775  *
2776  * @ingroup Entry
2777  */
2778 EAPI void
2779 elm_entry_selection_paste(Evas_Object *obj)
2780 {
2781    ELM_CHECK_WIDTYPE(obj, widtype);
2782    Widget_Data *wd = elm_widget_data_get(obj);
2783    if (!wd) return;
2784    _paste(obj, NULL, NULL);
2785 }
2786
2787 /**
2788  * This clears and frees the items in a entry's contextual (right click) menu.
2789  *
2790  * @param obj The entry object
2791  *
2792  * @ingroup Entry
2793  */
2794 EAPI void
2795 elm_entry_context_menu_clear(Evas_Object *obj)
2796 {
2797    ELM_CHECK_WIDTYPE(obj, widtype);
2798    Widget_Data *wd = elm_widget_data_get(obj);
2799    Elm_Entry_Context_Menu_Item *it;
2800    if (!wd) return;
2801    EINA_LIST_FREE(wd->items, it)
2802      {
2803         eina_stringshare_del(it->label);
2804         eina_stringshare_del(it->icon_file);
2805         eina_stringshare_del(it->icon_group);
2806         free(it);
2807      }
2808 }
2809
2810 /**
2811  * This adds an item to the entry's contextual menu.
2812  *
2813  * @param obj The entry object
2814  * @param label The item's text label
2815  * @param icon_file The item's icon file
2816  * @param icon_type The item's icon type
2817  * @param func The callback to execute when the item is clicked
2818  * @param data The data to associate with the item for related functions
2819  *
2820  * @ingroup Entry
2821  */
2822 EAPI void
2823 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)
2824 {
2825    ELM_CHECK_WIDTYPE(obj, widtype);
2826    Widget_Data *wd = elm_widget_data_get(obj);
2827    Elm_Entry_Context_Menu_Item *it;
2828    if (!wd) return;
2829    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2830    if (!it) return;
2831    wd->items = eina_list_append(wd->items, it);
2832    it->obj = obj;
2833    it->label = eina_stringshare_add(label);
2834    it->icon_file = eina_stringshare_add(icon_file);
2835    it->icon_type = icon_type;
2836    it->func = func;
2837    it->data = (void *)data;
2838 }
2839
2840 /**
2841  * This disables the entry's contextual (right click) menu.
2842  *
2843  * @param obj The entry object
2844  * @param disabled If true, the menu is disabled
2845  *
2846  * @ingroup Entry
2847  */
2848 EAPI void
2849 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2850 {
2851    ELM_CHECK_WIDTYPE(obj, widtype);
2852    Widget_Data *wd = elm_widget_data_get(obj);
2853    if (!wd) return;
2854    if (wd->context_menu == !disabled) return;
2855    wd->context_menu = !disabled;
2856 }
2857
2858 /**
2859  * This returns whether the entry's contextual (right click) menu is disabled.
2860  *
2861  * @param obj The entry object
2862  * @return If true, the menu is disabled
2863  *
2864  * @ingroup Entry
2865  */
2866 EAPI Eina_Bool
2867 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2868 {
2869    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2870    Widget_Data *wd = elm_widget_data_get(obj);
2871    if (!wd) return EINA_FALSE;
2872    return !wd->context_menu;
2873 }
2874
2875 /**
2876  * This appends a custom item provider to the list for that entry
2877  *
2878  * This appends the given callback. The list is walked from beginning to end
2879  * with each function called given the item href string in the text. If the
2880  * function returns an object handle other than NULL (it should create an
2881  * and object to do this), then this object is used to replace that item. If
2882  * not the next provider is called until one provides an item object, or the
2883  * default provider in entry does.
2884  * 
2885  * @param obj The entry object
2886  * @param func The function called to provide the item object
2887  * @param data The data passed to @p func
2888  *
2889  * @ingroup Entry
2890  */
2891 EAPI void
2892 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2893 {
2894    ELM_CHECK_WIDTYPE(obj, widtype);
2895    Widget_Data *wd = elm_widget_data_get(obj);
2896    if (!wd) return;
2897    if (!func) return;
2898    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2899    if (!ip) return;
2900    ip->func = func;
2901    ip->data = data;
2902    wd->item_providers = eina_list_append(wd->item_providers, ip);
2903 }
2904
2905 /**
2906  * This prepends a custom item provider to the list for that entry
2907  *
2908  * This prepends the given callback. See elm_entry_item_provider_append() for
2909  * more information
2910  * 
2911  * @param obj The entry object
2912  * @param func The function called to provide the item object
2913  * @param data The data passed to @p func
2914  *
2915  * @ingroup Entry
2916  */
2917 EAPI void
2918 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2919 {
2920    ELM_CHECK_WIDTYPE(obj, widtype);
2921    Widget_Data *wd = elm_widget_data_get(obj);
2922    if (!wd) return;
2923    if (!func) return;
2924    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2925    if (!ip) return;
2926    ip->func = func;
2927    ip->data = data;
2928    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2929 }
2930
2931 /**
2932  * This removes a custom item provider to the list for that entry
2933  *
2934  * This removes the given callback. See elm_entry_item_provider_append() for
2935  * more information
2936  * 
2937  * @param obj The entry object
2938  * @param func The function called to provide the item object
2939  * @param data The data passed to @p func
2940  *
2941  * @ingroup Entry
2942  */
2943 EAPI void
2944 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2945 {
2946    ELM_CHECK_WIDTYPE(obj, widtype);
2947    Widget_Data *wd = elm_widget_data_get(obj);
2948    Eina_List *l;
2949    Elm_Entry_Item_Provider *ip;
2950    if (!wd) return;
2951    if (!func) return;
2952    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2953      {
2954         if ((ip->func == func) && (ip->data == data))
2955           {
2956              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2957              free(ip);
2958              return;
2959           }
2960      }
2961 }
2962
2963 /**
2964  * This converts a markup (HTML-like) string into UTF-8.
2965  *
2966  * @param s The string (in markup) to be converted
2967  * @return The converted string (in UTF-8)
2968  *
2969  * @ingroup Entry
2970  */
2971 EAPI char *
2972 elm_entry_markup_to_utf8(const char *s)
2973 {
2974    char *ss = _mkup_to_text(s);
2975    if (!ss) ss = strdup("");
2976    return ss;
2977 }
2978
2979 /**
2980  * This converts a UTF-8 string into markup (HTML-like).
2981  *
2982  * @param s The string (in UTF-8) to be converted
2983  * @return The converted string (in markup)
2984  *
2985  * @ingroup Entry
2986  */
2987 EAPI char *
2988 elm_entry_utf8_to_markup(const char *s)
2989 {
2990    char *ss = _text_to_mkup(s);
2991    if (!ss) ss = strdup("");
2992    return ss;
2993 }
2994
2995 /**
2996  * Get the input method context in the entry widget
2997  *
2998  * @param obj The entry object
2999  * @return The input method context
3000  *
3001  * @ingroup Entry
3002  */
3003 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3004 {
3005    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3006    Widget_Data *wd = elm_widget_data_get(obj);
3007    if (!wd || !wd->ent) return NULL;
3008   
3009    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3010 }
3011
3012 /**
3013  * Set whether entry should enable the return key on soft keyboard automatically
3014  *
3015  * @param obj The entry object
3016  * @param on If true, entry enables the return key on soft keyboard automatically.
3017  *
3018  * @ingroup Entry
3019  */
3020 EAPI void 
3021 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3022 {
3023    ELM_CHECK_WIDTYPE(obj, widtype);
3024    Widget_Data *wd = elm_widget_data_get(obj);
3025    if (!wd) return;
3026
3027    wd->autoreturnkey = on;
3028    _check_enable_returnkey(obj);
3029 }
3030
3031 /**
3032  * Set whether entry should support auto capitalization
3033  *
3034  * @param obj The entry object
3035  * @param on If true, entry suports auto capitalization.
3036  *
3037  * @ingroup Entry
3038  */
3039 EAPI void 
3040 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3041 {
3042    ELM_CHECK_WIDTYPE(obj, widtype);
3043    Widget_Data *wd = elm_widget_data_get(obj);
3044    if (!wd) return;
3045
3046    if (wd->password)
3047        wd->autocapitalize = EINA_FALSE;
3048    else
3049        wd->autocapitalize = autocap;
3050
3051    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
3052 }
3053
3054 /**
3055  * Set whether entry should support auto period
3056  *
3057  * @param obj The entry object
3058  * @param on If true, entry suports auto period.
3059  *
3060  * @ingroup Entry
3061  */
3062 EAPI void 
3063 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3064 {
3065    ELM_CHECK_WIDTYPE(obj, widtype);
3066    Widget_Data *wd = elm_widget_data_get(obj);
3067    if (!wd) return;
3068
3069    if (wd->password)
3070        wd->autoperiod = EINA_FALSE;
3071    else
3072        wd->autoperiod = autoperiod;
3073
3074    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3075 }
3076
3077 /**
3078  * Set the font size on the entry object
3079  *
3080  * @param obj The entry object
3081  * @param size font size
3082  *
3083  * @ingroup Entry
3084  */
3085 EAPI void
3086 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3087 {
3088    ELM_CHECK_WIDTYPE(obj, widtype);
3089    Widget_Data *wd = elm_widget_data_get(obj);
3090    Eina_Strbuf *fontbuf = NULL;
3091    int removeflag = 0;
3092    const char *t;
3093
3094    if (!wd) return;
3095    t = eina_stringshare_add(elm_entry_entry_get(obj));
3096    fontbuf = eina_strbuf_new();
3097    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3098
3099    if (fontsize == 0) removeflag = 1; // remove fontsize tag
3100
3101    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3102      {
3103        elm_entry_entry_set(obj, t);
3104        wd->changed = 1;
3105        _sizing_eval(obj);
3106      }
3107    eina_strbuf_free(fontbuf);
3108    eina_stringshare_del(t);
3109 }
3110
3111 /**
3112  * Set the text align on the entry object
3113  *
3114  * @param obj The entry object
3115  * @param align align mode
3116  *
3117  * @ingroup Entry
3118  */
3119 EAPI void
3120 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3121 {
3122    ELM_CHECK_WIDTYPE(obj, widtype);
3123    Widget_Data *wd = elm_widget_data_get(obj);
3124    int len;
3125    const char *t;
3126
3127    if (!wd) return;
3128    t = eina_stringshare_add(elm_entry_entry_get(obj));
3129    len = strlen(t);
3130    if (len <= 0) return;
3131
3132    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3133      elm_entry_entry_set(obj, t);
3134
3135    wd->changed = 1;
3136    _sizing_eval(obj);
3137    eina_stringshare_del(t);
3138 }
3139
3140 /**
3141  * Set the text color on the entry object
3142  *
3143  * @param obj The entry object
3144  * @param r Red property background color of The entry object 
3145  * @param g Green property background color of The entry object 
3146  * @param b Blue property background color of The entry object 
3147  * @param a Alpha property background alpha of The entry object 
3148  *
3149  * @ingroup Entry
3150  */
3151 EAPI void
3152 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3153 {
3154    ELM_CHECK_WIDTYPE(obj, widtype);
3155    Widget_Data *wd = elm_widget_data_get(obj);
3156    Eina_Strbuf *colorbuf = NULL;
3157    const char *t;
3158    int len;
3159
3160    if (!wd) return;
3161    t = eina_stringshare_add(elm_entry_entry_get(obj));
3162    len = strlen(t);
3163    if (len <= 0) return;
3164    colorbuf = eina_strbuf_new();
3165    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3166
3167    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3168      {
3169        elm_entry_entry_set(obj, t);
3170        wd->changed = 1;
3171        _sizing_eval(obj);
3172      }
3173    eina_strbuf_free(colorbuf);
3174    eina_stringshare_del(t);
3175 }
3176
3177
3178 /**
3179  * Set background color of the entry
3180  *
3181  * @param obj The entry object
3182  * @param r Red property background color of The entry object 
3183  * @param g Green property background color of The entry object 
3184  * @param b Blue property background color of The entry object 
3185  * @param a Alpha property background alpha of The entry object 
3186  * @ingroup Entry
3187  */
3188 EAPI void
3189 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3190 {
3191    ELM_CHECK_WIDTYPE(obj, widtype);
3192    Widget_Data *wd = elm_widget_data_get(obj);
3193    evas_object_color_set(wd->bg, r, g, b, a);
3194
3195    if (wd->bgcolor == EINA_FALSE)
3196      {
3197        wd->bgcolor = 1;
3198        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3199      }
3200 }
3201
3202 /**
3203  * Set the ellipsis behavior of the entry
3204  *
3205  * @param obj The entry object
3206  * @param ellipsis To ellipsis text or not
3207  * @ingroup Entry
3208  */
3209 EAPI void
3210 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3211 {
3212    ELM_CHECK_WIDTYPE(obj, widtype);
3213    Widget_Data *wd = elm_widget_data_get(obj);
3214    if (wd->ellipsis == ellipsis) return;
3215    wd->ellipsis = ellipsis;
3216    wd->changed = 1;
3217    _sizing_eval(obj);
3218 }
3219
3220 /**
3221  * This sets the attribute to show the input panel automatically.
3222  *
3223  * @param obj The entry object
3224  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3225  *
3226  * @ingroup Entry
3227  */
3228 EAPI void
3229 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3230 {
3231    ELM_CHECK_WIDTYPE(obj, widtype);
3232    Widget_Data *wd = elm_widget_data_get(obj);
3233    if (!wd) return;
3234
3235    wd->input_panel_enable = enabled;
3236    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3237 }
3238
3239 /**
3240  * Set the input panel layout of the entry
3241  *
3242  * @param obj The entry object
3243  * @param layout the layout to set
3244  *
3245  * @ingroup Entry
3246  */
3247 EAPI void
3248 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3249 {
3250    ELM_CHECK_WIDTYPE(obj, widtype);
3251    Widget_Data *wd = elm_widget_data_get(obj);
3252    if (!wd) return;
3253    
3254    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3255    if (!ic) return;
3256
3257    wd->input_panel_layout = layout;
3258    
3259    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3260 }
3261
3262 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/