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