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