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