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