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