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