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