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