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