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