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