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