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