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