[Last character show in password feature]
[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->cnpinit = _cnpinit;
2095    ext_mod->context_menu = wd->context_menu;
2096 }
2097
2098 /**
2099  * This sets the entry object not to line wrap.  All input will
2100  * be on a single line, and the entry box will extend with user input.
2101  *
2102  * @param obj The entry object
2103  * @param single_line If true, the text in the entry
2104  * will be on a single line.
2105  *
2106  * @ingroup Entry
2107  */
2108 EAPI void
2109 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2110 {
2111    ELM_CHECK_WIDTYPE(obj, widtype);
2112    Widget_Data *wd = elm_widget_data_get(obj);
2113    const char *t;
2114    Ecore_IMF_Context *ic;
2115    if (!wd) return;
2116    if (wd->single_line == single_line) return;
2117    wd->single_line = single_line;
2118    wd->linewrap = EINA_FALSE;
2119    wd->char_linewrap = EINA_FALSE;
2120    t = eina_stringshare_add(elm_entry_entry_get(obj));
2121    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2122    elm_entry_entry_set(obj, t);
2123    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2124    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2125    ic = elm_entry_imf_context_get(obj);
2126    if (ic)
2127      {
2128         ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2129      }
2130
2131    eina_stringshare_del(t);
2132    _sizing_eval(obj);
2133 }
2134
2135 /**
2136  * This returns true if the entry has been set to single line mode.
2137  * See also elm_entry_single_line_set().
2138  *
2139  * @param obj The entry object
2140  * @return single_line If true, the text in the entry is set to display
2141  * on a single line.
2142  *
2143  * @ingroup Entry
2144  */
2145 EAPI Eina_Bool
2146 elm_entry_single_line_get(const Evas_Object *obj)
2147 {
2148    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2149    Widget_Data *wd = elm_widget_data_get(obj);
2150    if (!wd) return EINA_FALSE;
2151    return wd->single_line;
2152 }
2153
2154 /**
2155  * This set's the maximum bytes that can be added in entry.
2156  *
2157  * @param obj The entry object
2158  * @param max_no_of_bytes Maximum number of bytes entry can have.
2159  * 
2160  * @ingroup Entry
2161  */
2162 EAPI void
2163 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2164 {
2165    Widget_Data *wd = elm_widget_data_get(obj);
2166
2167    wd->max_no_of_bytes = max_no_of_bytes;
2168    edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2169    edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2170 }
2171
2172
2173 /**
2174  * This sets the entry object to password mode.  All text entered
2175  * and/or displayed within the widget will be replaced with asterisks (*).
2176  *
2177  * @param obj The entry object
2178  * @param password If true, password mode is enabled.
2179  *
2180  * @ingroup Entry
2181  */
2182 EAPI void
2183 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2184 {
2185    ELM_CHECK_WIDTYPE(obj, widtype);
2186    Widget_Data *wd = elm_widget_data_get(obj);
2187    Ecore_IMF_Context *ic;
2188    const char *t;
2189    if (!wd) return;
2190    if (wd->password == password) return;
2191    wd->password = password;
2192    wd->single_line = EINA_TRUE;
2193    wd->linewrap = EINA_FALSE;
2194    wd->char_linewrap = EINA_FALSE;
2195    if (_elm_config->password_show_last_character)
2196      wd->show_last_character = EINA_TRUE;
2197    t = eina_stringshare_add(elm_entry_entry_get(obj));
2198    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2199    elm_entry_entry_set(obj, t);
2200
2201    if (password)
2202      {
2203         if (wd->autoperiod)
2204           {
2205              elm_entry_autoperiod_set(obj, EINA_FALSE);
2206           }
2207
2208         if (wd->autocapital)
2209           {
2210              elm_entry_autocapitalization_set(obj, EINA_FALSE);
2211           }
2212      }
2213
2214    ic = elm_entry_imf_context_get(obj);
2215    if (ic)
2216      {
2217         ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2218      }
2219
2220    eina_stringshare_del(t);
2221    _sizing_eval(obj);
2222 }
2223
2224 /**
2225  * This set's the entry in password mode with out masking the last character entered by user,
2226  * and later masking the character after 2 seconds.
2227  
2228  * @param obj The entry object
2229  * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character" 
2230  * 0 for default).
2231  *
2232  * @ingroup Entry
2233  */
2234 EAPI void         
2235 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2236 {
2237    Widget_Data *wd = elm_widget_data_get(obj);
2238    const char *t;
2239    if (!wd) return;
2240    if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character))  return;
2241    wd->show_last_character = show_last_character;
2242    wd->password = show_last_character;
2243    wd->single_line = EINA_TRUE;
2244    wd->linewrap = EINA_FALSE;
2245    wd->char_linewrap = EINA_FALSE;
2246    t = eina_stringshare_add(elm_entry_entry_get(obj));
2247     _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2248    elm_entry_entry_set(obj, t);
2249    eina_stringshare_del(t);
2250    _sizing_eval(obj);
2251 }
2252
2253 /**
2254  * This returns whether password mode is enabled.
2255  * See also elm_entry_password_set().
2256  *
2257  * @param obj The entry object
2258  * @return If true, the entry is set to display all characters
2259  * as asterisks (*).
2260  *
2261  * @ingroup Entry
2262  */
2263 EAPI Eina_Bool
2264 elm_entry_password_get(const Evas_Object *obj)
2265 {
2266    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2267    Widget_Data *wd = elm_widget_data_get(obj);
2268    if (!wd) return EINA_FALSE;
2269    return wd->password;
2270 }
2271
2272 /**
2273  * This sets the text displayed within the entry to @p entry.
2274  *
2275  * @param obj The entry object
2276  * @param entry The text to be displayed
2277  *
2278  * @ingroup Entry
2279  */
2280 EAPI void
2281 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2282 {
2283    ELM_CHECK_WIDTYPE(obj, widtype);
2284    Widget_Data *wd = elm_widget_data_get(obj);
2285    if (!wd) return;
2286    if (!entry) entry = "";
2287    if(wd->max_no_of_bytes)
2288      {
2289        int len = strlen(entry);
2290        if(len > wd->max_no_of_bytes)
2291        {
2292          ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2293          return;
2294        }
2295      }
2296    edje_object_part_text_set(wd->ent, "elm.text", entry);
2297    if (wd->text) eina_stringshare_del(wd->text);
2298    wd->text = NULL;
2299    wd->changed = EINA_TRUE;
2300    _sizing_eval(obj);
2301 }
2302
2303 /**
2304  * This returns the text currently shown in object @p entry.
2305  * See also elm_entry_entry_set().
2306  *
2307  * @param obj The entry object
2308  * @return The currently displayed text or NULL on failure
2309  *
2310  * @ingroup Entry
2311  */
2312 EAPI const char *
2313 elm_entry_entry_get(const Evas_Object *obj)
2314 {
2315    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2316    Widget_Data *wd = elm_widget_data_get(obj);
2317    const char *text;
2318    if (!wd) return NULL;
2319    if (wd->text) return wd->text;
2320    text = edje_object_part_text_get(wd->ent, "elm.text");
2321    if (!text)
2322      {
2323         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2324         return NULL;
2325      }
2326    eina_stringshare_replace(&wd->text, text);
2327    return wd->text;
2328 }
2329
2330 /**
2331  * This returns all selected text within the entry.
2332  *
2333  * @param obj The entry object
2334  * @return The selected text within the entry or NULL on failure
2335  *
2336  * @ingroup Entry
2337  */
2338 EAPI const char *
2339 elm_entry_selection_get(const Evas_Object *obj)
2340 {
2341    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2342    Widget_Data *wd = elm_widget_data_get(obj);
2343    if (!wd) return NULL;
2344    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2345 }
2346
2347 /**
2348  * This inserts text in @p entry at the beginning of the entry
2349  * object.
2350  *
2351  * @param obj The entry object
2352  * @param entry The text to insert
2353  *
2354  * @ingroup Entry
2355  */
2356 EAPI void
2357 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2358 {
2359    ELM_CHECK_WIDTYPE(obj, widtype);
2360    Widget_Data *wd = elm_widget_data_get(obj);
2361    if (!wd) return;
2362    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2363    // start for cbhm
2364    if (cnpwidgetdata == obj)
2365            ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2366    // end for cbhm
2367    wd->changed = EINA_TRUE;
2368    _sizing_eval(obj);
2369 }
2370
2371 /**
2372  * This enables word line wrapping in the entry object.  It is the opposite
2373  * of elm_entry_single_line_set().  Additionally, setting this disables
2374  * character line wrapping.
2375  * See also elm_entry_line_char_wrap_set().
2376  *
2377  * @param obj The entry object
2378  * @param wrap If true, the entry will be wrapped once it reaches the end
2379  * of the object. Wrapping will occur at the end of the word before the end of the
2380  * object.
2381  *
2382  * @ingroup Entry
2383  */
2384 EAPI void
2385 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2386 {
2387    ELM_CHECK_WIDTYPE(obj, widtype);
2388    Widget_Data *wd = elm_widget_data_get(obj);
2389    const char *t;
2390    if (!wd) return;
2391    if (wd->linewrap == wrap) return;
2392    wd->linewrap = wrap;
2393    if(wd->linewrap)
2394        wd->char_linewrap = EINA_FALSE;
2395    t = eina_stringshare_add(elm_entry_entry_get(obj));
2396    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2397    elm_entry_entry_set(obj, t);
2398    eina_stringshare_del(t);
2399    _sizing_eval(obj);
2400 }
2401
2402 /**
2403  * Set wrap width of the entry
2404  *
2405  * @param obj The entry object
2406  * @param w The wrap width in pixels at a minimum where words need to wrap
2407  * @ingroup Entry
2408  */
2409 EAPI void
2410 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2411 {
2412    Widget_Data *wd = elm_widget_data_get(obj);
2413    if (wd->wrap_w == w) return;
2414    wd->wrap_w = w;
2415    _sizing_eval(obj);
2416 }
2417
2418 /**
2419  * get wrap width of the entry
2420  *
2421  * @param obj The entry object
2422  * @return The wrap width in pixels at a minimum where words need to wrap
2423  * @ingroup Entry
2424  */
2425 EAPI Evas_Coord
2426 elm_entry_wrap_width_get(const Evas_Object *obj)
2427 {
2428    Widget_Data *wd = elm_widget_data_get(obj);
2429    return wd->wrap_w;
2430 }
2431
2432 /**
2433  * This enables character line wrapping in the entry object.  It is the opposite
2434  * of elm_entry_single_line_set().  Additionally, setting this disables
2435  * word line wrapping.
2436  * See also elm_entry_line_wrap_set().
2437  *
2438  * @param obj The entry object
2439  * @param wrap If true, the entry will be wrapped once it reaches the end
2440  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2441  *
2442  * @ingroup Entry
2443  */
2444 EAPI void
2445 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2446 {
2447    ELM_CHECK_WIDTYPE(obj, widtype);
2448    Widget_Data *wd = elm_widget_data_get(obj);
2449    const char *t;
2450    if (!wd) return;
2451    if (wd->char_linewrap == wrap) return;
2452    wd->char_linewrap = wrap;
2453    if(wd->char_linewrap)
2454        wd->linewrap = EINA_FALSE;
2455    t = eina_stringshare_add(elm_entry_entry_get(obj));
2456    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2457    elm_entry_entry_set(obj, t);
2458    eina_stringshare_del(t);
2459    _sizing_eval(obj);
2460 }
2461
2462 /**
2463  * This sets the editable attribute of the entry.
2464  *
2465  * @param obj The entry object
2466  * @param editable If true, the entry will be editable by the user.
2467  * If false, it will be set to the disabled state.
2468  *
2469  * @ingroup Entry
2470  */
2471 EAPI void
2472 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2473 {
2474    ELM_CHECK_WIDTYPE(obj, widtype);
2475    Widget_Data *wd = elm_widget_data_get(obj);
2476    const char *t;
2477    if (!wd) return;
2478    if (wd->editable == editable) return;
2479    wd->editable = editable;
2480    t = eina_stringshare_add(elm_entry_entry_get(obj));
2481    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2482    elm_entry_entry_set(obj, t);
2483    eina_stringshare_del(t);
2484    _sizing_eval(obj);
2485
2486 #ifdef HAVE_ELEMENTARY_X
2487    if (editable)
2488       elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2489    else
2490       elm_drop_target_del(obj);
2491 #endif
2492 }
2493
2494 /**
2495  * This gets the editable attribute of the entry.
2496  * See also elm_entry_editable_set().
2497  *
2498  * @param obj The entry object
2499  * @return If true, the entry is editable by the user.
2500  * If false, it is not editable by the user
2501  *
2502  * @ingroup Entry
2503  */
2504 EAPI Eina_Bool
2505 elm_entry_editable_get(const Evas_Object *obj)
2506 {
2507    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2508    Widget_Data *wd = elm_widget_data_get(obj);
2509    if (!wd) return EINA_FALSE;
2510    return wd->editable;
2511 }
2512
2513 /**
2514  * This drops any existing text selection within the entry.
2515  *
2516  * @param obj The entry object
2517  *
2518  * @ingroup Entry
2519  */
2520 EAPI void
2521 elm_entry_select_none(Evas_Object *obj)
2522 {
2523    ELM_CHECK_WIDTYPE(obj, widtype);
2524    Widget_Data *wd = elm_widget_data_get(obj);
2525    if (!wd) return;
2526    if (wd->selmode)
2527      {
2528         wd->selmode = EINA_FALSE;
2529         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2530         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2531      }
2532    wd->have_selection = EINA_FALSE;
2533    edje_object_part_text_select_none(wd->ent, "elm.text");
2534 }
2535
2536 /**
2537  * This selects all text within the entry.
2538  *
2539  * @param obj The entry object
2540  *
2541  * @ingroup Entry
2542  */
2543 EAPI void
2544 elm_entry_select_all(Evas_Object *obj)
2545 {
2546    ELM_CHECK_WIDTYPE(obj, widtype);
2547    Widget_Data *wd = elm_widget_data_get(obj);
2548    if (!wd) return;
2549    if (wd->selmode)
2550      {
2551         wd->selmode = EINA_FALSE;
2552         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2553         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2554      }
2555    wd->have_selection = EINA_TRUE;
2556    edje_object_part_text_select_all(wd->ent, "elm.text");
2557 }
2558
2559 /**
2560  * This moves the cursor one place to the right within the entry.
2561  *
2562  * @param obj The entry object
2563  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2564  *
2565  * @ingroup Entry
2566  */
2567 EAPI Eina_Bool
2568 elm_entry_cursor_next(Evas_Object *obj)
2569 {
2570    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2571    Widget_Data *wd = elm_widget_data_get(obj);
2572    if (!wd) return EINA_FALSE;
2573    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2574 }
2575
2576 /**
2577  * This moves the cursor one place to the left within the entry.
2578  *
2579  * @param obj The entry object
2580  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2581  *
2582  * @ingroup Entry
2583  */
2584 EAPI Eina_Bool
2585 elm_entry_cursor_prev(Evas_Object *obj)
2586 {
2587    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2588    Widget_Data *wd = elm_widget_data_get(obj);
2589    if (!wd) return EINA_FALSE;
2590    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2591 }
2592
2593 /**
2594  * This moves the cursor one line up within the entry.
2595  *
2596  * @param obj The entry object
2597  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2598  *
2599  * @ingroup Entry
2600  */
2601 EAPI Eina_Bool
2602 elm_entry_cursor_up(Evas_Object *obj)
2603 {
2604    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2605    Widget_Data *wd = elm_widget_data_get(obj);
2606    if (!wd) return EINA_FALSE;
2607    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2608 }
2609
2610 /**
2611  * This moves the cursor one line down within the entry.
2612  *
2613  * @param obj The entry object
2614  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2615  *
2616  * @ingroup Entry
2617  */
2618 EAPI Eina_Bool
2619 elm_entry_cursor_down(Evas_Object *obj)
2620 {
2621    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2622    Widget_Data *wd = elm_widget_data_get(obj);
2623    if (!wd) return EINA_FALSE;
2624    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2625 }
2626
2627 /**
2628  * This moves the cursor to the beginning of the entry.
2629  *
2630  * @param obj The entry object
2631  *
2632  * @ingroup Entry
2633  */
2634 EAPI void
2635 elm_entry_cursor_begin_set(Evas_Object *obj)
2636 {
2637    ELM_CHECK_WIDTYPE(obj, widtype);
2638    Widget_Data *wd = elm_widget_data_get(obj);
2639    if (!wd) return;
2640    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2641 }
2642
2643 /**
2644  * This moves the cursor to the end of the entry.
2645  *
2646  * @param obj The entry object
2647  *
2648  * @ingroup Entry
2649  */
2650 EAPI void
2651 elm_entry_cursor_end_set(Evas_Object *obj)
2652 {
2653    ELM_CHECK_WIDTYPE(obj, widtype);
2654    Widget_Data *wd = elm_widget_data_get(obj);
2655    if (!wd) return;
2656    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2657 }
2658
2659 /**
2660  * This moves the cursor to the beginning of the current line.
2661  *
2662  * @param obj The entry object
2663  *
2664  * @ingroup Entry
2665  */
2666 EAPI void
2667 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2668 {
2669    ELM_CHECK_WIDTYPE(obj, widtype);
2670    Widget_Data *wd = elm_widget_data_get(obj);
2671    if (!wd) return;
2672    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2673 }
2674
2675 /**
2676  * This moves the cursor to the end of the current line.
2677  *
2678  * @param obj The entry object
2679  *
2680  * @ingroup Entry
2681  */
2682 EAPI void
2683 elm_entry_cursor_line_end_set(Evas_Object *obj)
2684 {
2685    ELM_CHECK_WIDTYPE(obj, widtype);
2686    Widget_Data *wd = elm_widget_data_get(obj);
2687    if (!wd) return;
2688    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2689 }
2690
2691 /**
2692  * This begins a selection within the entry as though
2693  * the user were holding down the mouse button to make a selection.
2694  *
2695  * @param obj The entry object
2696  *
2697  * @ingroup Entry
2698  */
2699 EAPI void
2700 elm_entry_cursor_selection_begin(Evas_Object *obj)
2701 {
2702    ELM_CHECK_WIDTYPE(obj, widtype);
2703    Widget_Data *wd = elm_widget_data_get(obj);
2704    if (!wd) return;
2705    edje_object_part_text_select_begin(wd->ent, "elm.text");
2706 }
2707
2708 /**
2709  * This ends a selection within the entry as though
2710  * the user had just released the mouse button while making a selection.
2711  *
2712  * @param obj The entry object
2713  *
2714  * @ingroup Entry
2715  */
2716 EAPI void
2717 elm_entry_cursor_selection_end(Evas_Object *obj)
2718 {
2719    ELM_CHECK_WIDTYPE(obj, widtype);
2720    Widget_Data *wd = elm_widget_data_get(obj);
2721    if (!wd) return;
2722    edje_object_part_text_select_extend(wd->ent, "elm.text");
2723 }
2724
2725 /**
2726  * TODO: fill this in
2727  *
2728  * @param obj The entry object
2729  * @return TODO: fill this in
2730  *
2731  * @ingroup Entry
2732  */
2733 EAPI Eina_Bool
2734 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2735 {
2736    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2737    Widget_Data *wd = elm_widget_data_get(obj);
2738    if (!wd) return EINA_FALSE;
2739    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2740 }
2741
2742 /**
2743  * This returns whether the cursor is visible.
2744  *
2745  * @param obj The entry object
2746  * @return If true, the cursor is visible.
2747  *
2748  * @ingroup Entry
2749  */
2750 EAPI Eina_Bool
2751 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2752 {
2753    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2754    Widget_Data *wd = elm_widget_data_get(obj);
2755    if (!wd) return EINA_FALSE;
2756    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2757 }
2758
2759 /**
2760  * TODO: fill this in
2761  *
2762  * @param obj The entry object
2763  * @return TODO: fill this in
2764  *
2765  * @ingroup Entry
2766  */
2767 EAPI const char *
2768 elm_entry_cursor_content_get(const Evas_Object *obj)
2769 {
2770    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2771    Widget_Data *wd = elm_widget_data_get(obj);
2772    if (!wd) return NULL;
2773    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2774 }
2775
2776 /**
2777  * This executes a "cut" action on the selected text in the entry.
2778  *
2779  * @param obj The entry object
2780  *
2781  * @ingroup Entry
2782  */
2783 EAPI void
2784 elm_entry_selection_cut(Evas_Object *obj)
2785 {
2786    ELM_CHECK_WIDTYPE(obj, widtype);
2787    Widget_Data *wd = elm_widget_data_get(obj);
2788    if (!wd) return;
2789    _cut(obj, NULL, NULL);
2790 }
2791
2792 /**
2793  * This executes a "copy" action on the selected text in the entry.
2794  *
2795  * @param obj The entry object
2796  *
2797  * @ingroup Entry
2798  */
2799 EAPI void
2800 elm_entry_selection_copy(Evas_Object *obj)
2801 {
2802    ELM_CHECK_WIDTYPE(obj, widtype);
2803    Widget_Data *wd = elm_widget_data_get(obj);
2804    if (!wd) return;
2805    _copy(obj, NULL, NULL);
2806 }
2807
2808 /**
2809  * This executes a "paste" action in the entry.
2810  *
2811  * @param obj The entry object
2812  *
2813  * @ingroup Entry
2814  */
2815 EAPI void
2816 elm_entry_selection_paste(Evas_Object *obj)
2817 {
2818    ELM_CHECK_WIDTYPE(obj, widtype);
2819    Widget_Data *wd = elm_widget_data_get(obj);
2820    if (!wd) return;
2821    _paste(obj, NULL, NULL);
2822 }
2823
2824 /**
2825  * This clears and frees the items in a entry's contextual (right click) menu.
2826  *
2827  * @param obj The entry object
2828  *
2829  * @ingroup Entry
2830  */
2831 EAPI void
2832 elm_entry_context_menu_clear(Evas_Object *obj)
2833 {
2834    ELM_CHECK_WIDTYPE(obj, widtype);
2835    Widget_Data *wd = elm_widget_data_get(obj);
2836    Elm_Entry_Context_Menu_Item *it;
2837    if (!wd) return;
2838    EINA_LIST_FREE(wd->items, it)
2839      {
2840         eina_stringshare_del(it->label);
2841         eina_stringshare_del(it->icon_file);
2842         eina_stringshare_del(it->icon_group);
2843         free(it);
2844      }
2845 }
2846
2847 /**
2848  * This adds an item to the entry's contextual menu.
2849  *
2850  * @param obj The entry object
2851  * @param label The item's text label
2852  * @param icon_file The item's icon file
2853  * @param icon_type The item's icon type
2854  * @param func The callback to execute when the item is clicked
2855  * @param data The data to associate with the item for related functions
2856  *
2857  * @ingroup Entry
2858  */
2859 EAPI void
2860 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)
2861 {
2862    ELM_CHECK_WIDTYPE(obj, widtype);
2863    Widget_Data *wd = elm_widget_data_get(obj);
2864    Elm_Entry_Context_Menu_Item *it;
2865    if (!wd) return;
2866    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2867    if (!it) return;
2868    wd->items = eina_list_append(wd->items, it);
2869    it->obj = obj;
2870    it->label = eina_stringshare_add(label);
2871    it->icon_file = eina_stringshare_add(icon_file);
2872    it->icon_type = icon_type;
2873    it->func = func;
2874    it->data = (void *)data;
2875 }
2876
2877 /**
2878  * This disables the entry's contextual (right click) menu.
2879  *
2880  * @param obj The entry object
2881  * @param disabled If true, the menu is disabled
2882  *
2883  * @ingroup Entry
2884  */
2885 EAPI void
2886 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2887 {
2888    ELM_CHECK_WIDTYPE(obj, widtype);
2889    Widget_Data *wd = elm_widget_data_get(obj);
2890    if (!wd) return;
2891    if (wd->context_menu == !disabled) return;
2892    wd->context_menu = !disabled;
2893 }
2894
2895 /**
2896  * This returns whether the entry's contextual (right click) menu is disabled.
2897  *
2898  * @param obj The entry object
2899  * @return If true, the menu is disabled
2900  *
2901  * @ingroup Entry
2902  */
2903 EAPI Eina_Bool
2904 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2905 {
2906    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2907    Widget_Data *wd = elm_widget_data_get(obj);
2908    if (!wd) return EINA_FALSE;
2909    return !wd->context_menu;
2910 }
2911
2912 /**
2913  * This appends a custom item provider to the list for that entry
2914  *
2915  * This appends the given callback. The list is walked from beginning to end
2916  * with each function called given the item href string in the text. If the
2917  * function returns an object handle other than NULL (it should create an
2918  * and object to do this), then this object is used to replace that item. If
2919  * not the next provider is called until one provides an item object, or the
2920  * default provider in entry does.
2921  * 
2922  * @param obj The entry object
2923  * @param func The function called to provide the item object
2924  * @param data The data passed to @p func
2925  *
2926  * @ingroup Entry
2927  */
2928 EAPI void
2929 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2930 {
2931    ELM_CHECK_WIDTYPE(obj, widtype);
2932    Widget_Data *wd = elm_widget_data_get(obj);
2933    if (!wd) return;
2934    if (!func) return;
2935    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2936    if (!ip) return;
2937    ip->func = func;
2938    ip->data = data;
2939    wd->item_providers = eina_list_append(wd->item_providers, ip);
2940 }
2941
2942 /**
2943  * This prepends a custom item provider to the list for that entry
2944  *
2945  * This prepends the given callback. See elm_entry_item_provider_append() for
2946  * more information
2947  * 
2948  * @param obj The entry object
2949  * @param func The function called to provide the item object
2950  * @param data The data passed to @p func
2951  *
2952  * @ingroup Entry
2953  */
2954 EAPI void
2955 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2956 {
2957    ELM_CHECK_WIDTYPE(obj, widtype);
2958    Widget_Data *wd = elm_widget_data_get(obj);
2959    if (!wd) return;
2960    if (!func) return;
2961    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2962    if (!ip) return;
2963    ip->func = func;
2964    ip->data = data;
2965    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2966 }
2967
2968 /**
2969  * This removes a custom item provider to the list for that entry
2970  *
2971  * This removes the given callback. See elm_entry_item_provider_append() for
2972  * more information
2973  * 
2974  * @param obj The entry object
2975  * @param func The function called to provide the item object
2976  * @param data The data passed to @p func
2977  *
2978  * @ingroup Entry
2979  */
2980 EAPI void
2981 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2982 {
2983    ELM_CHECK_WIDTYPE(obj, widtype);
2984    Widget_Data *wd = elm_widget_data_get(obj);
2985    Eina_List *l;
2986    Elm_Entry_Item_Provider *ip;
2987    if (!wd) return;
2988    if (!func) return;
2989    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2990      {
2991         if ((ip->func == func) && (ip->data == data))
2992           {
2993              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2994              free(ip);
2995              return;
2996           }
2997      }
2998 }
2999
3000 /**
3001  * This converts a markup (HTML-like) string into UTF-8.
3002  *
3003  * @param s The string (in markup) to be converted
3004  * @return The converted string (in UTF-8)
3005  *
3006  * @ingroup Entry
3007  */
3008 EAPI char *
3009 elm_entry_markup_to_utf8(const char *s)
3010 {
3011    char *ss = _mkup_to_text(s);
3012    if (!ss) ss = strdup("");
3013    return ss;
3014 }
3015
3016 /**
3017  * This converts a UTF-8 string into markup (HTML-like).
3018  *
3019  * @param s The string (in UTF-8) to be converted
3020  * @return The converted string (in markup)
3021  *
3022  * @ingroup Entry
3023  */
3024 EAPI char *
3025 elm_entry_utf8_to_markup(const char *s)
3026 {
3027    char *ss = _text_to_mkup(s);
3028    if (!ss) ss = strdup("");
3029    return ss;
3030 }
3031
3032 /**
3033  * Get the input method context in the entry widget
3034  *
3035  * @param obj The entry object
3036  * @return The input method context
3037  *
3038  * @ingroup Entry
3039  */
3040 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3041 {
3042    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3043    Widget_Data *wd = elm_widget_data_get(obj);
3044    if (!wd || !wd->ent) return NULL;
3045   
3046    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3047 }
3048
3049 /**
3050  * Set whether entry should enable the return key on soft keyboard automatically
3051  *
3052  * @param obj The entry object
3053  * @param on If true, entry enables the return key on soft keyboard automatically.
3054  *
3055  * @ingroup Entry
3056  */
3057 EAPI void 
3058 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3059 {
3060    ELM_CHECK_WIDTYPE(obj, widtype);
3061    Widget_Data *wd = elm_widget_data_get(obj);
3062    if (!wd) return;
3063
3064    wd->autoreturnkey = on;
3065    _check_enable_returnkey(obj);
3066 }
3067
3068 /**
3069  * Set whether entry should support auto capitalization
3070  *
3071  * @param obj The entry object
3072  * @param on If true, entry suports auto capitalization.
3073  *
3074  * @ingroup Entry
3075  */
3076 EAPI void 
3077 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3078 {
3079    ELM_CHECK_WIDTYPE(obj, widtype);
3080    Widget_Data *wd = elm_widget_data_get(obj);
3081    if (!wd) return;
3082
3083    if (wd->password)
3084        wd->autocapital = EINA_FALSE;
3085    else
3086        wd->autocapital = autocap;
3087
3088    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL || 
3089        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL) 
3090        wd->autocapital = EINA_FALSE;
3091
3092    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3093 }
3094
3095 /**
3096  * Set whether entry should support auto period
3097  *
3098  * @param obj The entry object
3099  * @param on If true, entry suports auto period.
3100  *
3101  * @ingroup Entry
3102  */
3103 EAPI void 
3104 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3105 {
3106    ELM_CHECK_WIDTYPE(obj, widtype);
3107    Widget_Data *wd = elm_widget_data_get(obj);
3108    if (!wd) return;
3109
3110    if (wd->password)
3111        wd->autoperiod = EINA_FALSE;
3112    else
3113        wd->autoperiod = autoperiod;
3114
3115    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL || 
3116        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL) 
3117        wd->autoperiod = EINA_FALSE;
3118
3119    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3120 }
3121
3122 /**
3123  * Set the font size on the entry object
3124  *
3125  * @param obj The entry object
3126  * @param size font size
3127  *
3128  * @ingroup Entry
3129  */
3130 EAPI void
3131 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3132 {
3133    ELM_CHECK_WIDTYPE(obj, widtype);
3134    Widget_Data *wd = elm_widget_data_get(obj);
3135    Eina_Strbuf *fontbuf = NULL;
3136    int removeflag = 0;
3137    const char *t;
3138
3139    if (!wd) return;
3140    t = eina_stringshare_add(elm_entry_entry_get(obj));
3141    fontbuf = eina_strbuf_new();
3142    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3143
3144    if (fontsize == 0) removeflag = 1; // remove fontsize tag
3145
3146    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3147      {
3148        elm_entry_entry_set(obj, t);
3149        wd->changed = 1;
3150        _sizing_eval(obj);
3151      }
3152    eina_strbuf_free(fontbuf);
3153    eina_stringshare_del(t);
3154 }
3155
3156 /**
3157  * Set the text align on the entry object
3158  *
3159  * @param obj The entry object
3160  * @param align align mode
3161  *
3162  * @ingroup Entry
3163  */
3164 EAPI void
3165 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3166 {
3167    ELM_CHECK_WIDTYPE(obj, widtype);
3168    Widget_Data *wd = elm_widget_data_get(obj);
3169    int len;
3170    const char *t;
3171
3172    if (!wd) return;
3173    t = eina_stringshare_add(elm_entry_entry_get(obj));
3174    len = strlen(t);
3175    if (len <= 0) return;
3176
3177    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3178      elm_entry_entry_set(obj, t);
3179
3180    wd->changed = 1;
3181    _sizing_eval(obj);
3182    eina_stringshare_del(t);
3183 }
3184
3185 /**
3186  * Set the text color on the entry object
3187  *
3188  * @param obj The entry object
3189  * @param r Red property background color of The entry object 
3190  * @param g Green property background color of The entry object 
3191  * @param b Blue property background color of The entry object 
3192  * @param a Alpha property background alpha of The entry object 
3193  *
3194  * @ingroup Entry
3195  */
3196 EAPI void
3197 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3198 {
3199    ELM_CHECK_WIDTYPE(obj, widtype);
3200    Widget_Data *wd = elm_widget_data_get(obj);
3201    Eina_Strbuf *colorbuf = NULL;
3202    const char *t;
3203    int len;
3204
3205    if (!wd) return;
3206    t = eina_stringshare_add(elm_entry_entry_get(obj));
3207    len = strlen(t);
3208    if (len <= 0) return;
3209    colorbuf = eina_strbuf_new();
3210    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3211
3212    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3213      {
3214        elm_entry_entry_set(obj, t);
3215        wd->changed = 1;
3216        _sizing_eval(obj);
3217      }
3218    eina_strbuf_free(colorbuf);
3219    eina_stringshare_del(t);
3220 }
3221
3222
3223 /**
3224  * Set background color of the entry
3225  *
3226  * @param obj The entry object
3227  * @param r Red property background color of The entry object 
3228  * @param g Green property background color of The entry object 
3229  * @param b Blue property background color of The entry object 
3230  * @param a Alpha property background alpha of The entry object 
3231  * @ingroup Entry
3232  */
3233 EAPI void
3234 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3235 {
3236    ELM_CHECK_WIDTYPE(obj, widtype);
3237    Widget_Data *wd = elm_widget_data_get(obj);
3238    evas_object_color_set(wd->bg, r, g, b, a);
3239
3240    if (wd->bgcolor == EINA_FALSE)
3241      {
3242        wd->bgcolor = 1;
3243        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3244      }
3245 }
3246
3247 /**
3248  * Set the ellipsis behavior of the entry
3249  *
3250  * @param obj The entry object
3251  * @param ellipsis To ellipsis text or not
3252  * @ingroup Entry
3253  */
3254 EAPI void
3255 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3256 {
3257    ELM_CHECK_WIDTYPE(obj, widtype);
3258    Widget_Data *wd = elm_widget_data_get(obj);
3259    if (wd->ellipsis == ellipsis) return;
3260    wd->ellipsis = ellipsis;
3261    wd->changed = 1;
3262    _sizing_eval(obj);
3263 }
3264
3265 /**
3266  * This sets the attribute to show the input panel automatically.
3267  *
3268  * @param obj The entry object
3269  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3270  *
3271  * @ingroup Entry
3272  */
3273 EAPI void
3274 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3275 {
3276    ELM_CHECK_WIDTYPE(obj, widtype);
3277    Widget_Data *wd = elm_widget_data_get(obj);
3278    if (!wd) return;
3279
3280    wd->input_panel_enable = enabled;
3281    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3282 }
3283
3284 /**
3285  * Set the input panel layout of the entry
3286  *
3287  * @param obj The entry object
3288  * @param layout the layout to set
3289  *
3290  * @ingroup Entry
3291  */
3292 EAPI void
3293 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3294 {
3295    ELM_CHECK_WIDTYPE(obj, widtype);
3296    Widget_Data *wd = elm_widget_data_get(obj);
3297    if (!wd) return;
3298    
3299    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3300    if (!ic) return;
3301
3302    wd->input_panel_layout = layout;
3303    
3304    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3305 }
3306
3307 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/