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