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