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