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    wd->selmode = EINA_TRUE;
1114    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1115 #ifdef HAVE_ELEMENTARY_X
1116    if (wd->sel_notify_handler)
1117      {
1118         const char *txt = elm_entry_selection_get(data);
1119         Evas_Object *top;
1120
1121         top = elm_widget_top_get(data);
1122         if ((top) && (elm_win_xwindow_get(top)))
1123              elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1124      }
1125 #endif
1126 }
1127
1128 static void
1129 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1130 {
1131    Widget_Data *wd = elm_widget_data_get(data);
1132    if (!wd) return;
1133    wd->have_selection = EINA_TRUE;
1134    wd->selmode = EINA_TRUE;
1135    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1136    elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1137                    elm_entry_selection_get(data));
1138 }
1139
1140 static void
1141 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1142 {
1143    Widget_Data *wd = elm_widget_data_get(data);
1144    if (!wd) return;
1145    if (!wd->have_selection) return;
1146    wd->have_selection = EINA_FALSE;
1147    wd->selmode = EINA_FALSE;
1148    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1149    if (wd->sel_notify_handler)
1150      {
1151         if (wd->cut_sel)
1152           {
1153 #ifdef HAVE_ELEMENTARY_X
1154              Evas_Object *top;
1155
1156              top = elm_widget_top_get(data);
1157              if ((top) && (elm_win_xwindow_get(top)))
1158                  elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1159                                        wd->cut_sel);
1160 #endif
1161              eina_stringshare_del(wd->cut_sel);
1162              wd->cut_sel = NULL;
1163           }
1164         else
1165           {
1166 #ifdef HAVE_ELEMENTARY_X
1167              Evas_Object *top;
1168
1169              top = elm_widget_top_get(data);
1170              if ((top) && (elm_win_xwindow_get(top)))
1171                 elm_selection_clear(ELM_SEL_PRIMARY, data);
1172 #endif
1173           }
1174      }
1175 }
1176
1177 static void
1178 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1179 {
1180    Widget_Data *wd = elm_widget_data_get(data);
1181    if (!wd) return;
1182    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1183    if (wd->sel_notify_handler)
1184      {
1185 #ifdef HAVE_ELEMENTARY_X
1186         Evas_Object *top;
1187
1188         top = elm_widget_top_get(data);
1189         if ((top) && (elm_win_xwindow_get(top)))
1190           {
1191              wd->selection_asked = EINA_TRUE;
1192              elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data);
1193           }
1194 #endif
1195      }
1196 }
1197
1198 static void
1199 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1200 {
1201    Widget_Data *wd = elm_widget_data_get(data);
1202    if (!wd) return;
1203    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1204    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1205                         elm_entry_selection_get(data));
1206 }
1207
1208 static void
1209 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1210 {
1211    Widget_Data *wd = elm_widget_data_get(data);
1212    if (!wd) return;
1213    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1214    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1215                         elm_entry_selection_get(data));
1216    edje_object_part_text_insert(wd->ent, "elm.text", "");
1217    wd->changed = EINA_TRUE;
1218    _sizing_eval(data);
1219 }
1220
1221 static void
1222 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1223 {
1224    Widget_Data *wd = elm_widget_data_get(data);
1225    Evas_Coord cx, cy, cw, ch;
1226    if (!wd) return;
1227    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1228    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1229                                              &cx, &cy, &cw, &ch);
1230    if (!wd->deferred_recalc_job)
1231      elm_widget_show_region_set(data, cx, cy, cw, ch);
1232    else
1233      {
1234         wd->deferred_cur = EINA_TRUE;
1235         wd->cx = cx;
1236         wd->cy = cy;
1237         wd->cw = cw;
1238         wd->ch = ch;
1239      }
1240 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1241    evas_object_smart_callback_call(data, SIG_IMPREGION_CHANGED, NULL);
1242 #endif
1243 }
1244
1245 static void
1246 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1247 {
1248    Widget_Data *wd = elm_widget_data_get(data);
1249    if (!wd) return;
1250 }
1251
1252 static void
1253 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1254 {
1255    Widget_Data *wd = elm_widget_data_get(data);
1256    Elm_Entry_Anchor_Info ei;
1257    char *buf2, *p, *p2, *n;
1258    if (!wd) return;
1259    p = strrchr(emission, ',');
1260    if (p)
1261      {
1262         const Eina_List *geoms;
1263
1264         n = p + 1;
1265         p2 = p -1;
1266         while (p2 >= emission)
1267           {
1268              if (*p2 == ',') break;
1269              p2--;
1270           }
1271         p2++;
1272         buf2 = alloca(5 + p - p2);
1273         strncpy(buf2, p2, p - p2);
1274         buf2[p - p2] = 0;
1275         ei.name = n;
1276         ei.button = atoi(buf2);
1277         ei.x = ei.y = ei.w = ei.h = 0;
1278         geoms =
1279           edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1280         if (geoms)
1281           {
1282              Evas_Textblock_Rectangle *r;
1283              const Eina_List *l;
1284              Evas_Coord px, py, x, y;
1285
1286              evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1287              evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1288              EINA_LIST_FOREACH(geoms, l, r)
1289                {
1290                   if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1291                       ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1292                     {
1293                        ei.x = r->x + x;
1294                        ei.y = r->y + y;
1295                        ei.w = r->w;
1296                        ei.h = r->h;
1297                        break;
1298                     }
1299                }
1300           }
1301         if (!wd->disabled)
1302           evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1303      }
1304 }
1305
1306 static void
1307 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1308 {
1309    Widget_Data *wd = elm_widget_data_get(data);
1310    if (!wd) return;
1311 }
1312
1313 static void
1314 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1315 {
1316    Widget_Data *wd = elm_widget_data_get(data);
1317    if (!wd) return;
1318 }
1319
1320 static void
1321 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1322 {
1323    Widget_Data *wd = elm_widget_data_get(data);
1324    if (!wd) return;
1325 }
1326
1327 static void
1328 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1329 {
1330    Widget_Data *wd = elm_widget_data_get(data);
1331    if (!wd) return;
1332    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1333 }
1334
1335 static void
1336 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1337 {
1338    Widget_Data *wd = elm_widget_data_get(data);
1339    if (!wd) return;
1340    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1341 }
1342
1343 static void
1344 _signal_mouse_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1345 {
1346    Widget_Data *wd = elm_widget_data_get(data);
1347    if (!wd) return;
1348    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1349 }
1350
1351 static void
1352 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1353 {
1354    Widget_Data *wd = elm_widget_data_get(data);
1355    if (!wd) return;
1356    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1357 }
1358
1359 #ifdef HAVE_ELEMENTARY_X
1360 static Eina_Bool
1361 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1362 {
1363    Widget_Data *wd = elm_widget_data_get(data);
1364    Ecore_X_Event_Selection_Notify *ev = event;
1365    if (!wd) return ECORE_CALLBACK_PASS_ON;
1366    if (!wd->selection_asked && !wd->drag_selection_asked)
1367       return ECORE_CALLBACK_PASS_ON;
1368
1369    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1370        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1371      {
1372         Ecore_X_Selection_Data_Text *text_data;
1373
1374         text_data = ev->data;
1375         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1376           {
1377              if (text_data->text)
1378                {
1379                   char *txt = _text_to_mkup(text_data->text);
1380
1381                   if (txt)
1382                     {
1383                        elm_entry_entry_insert(data, txt);
1384                        free(txt);
1385                     }
1386                }
1387           }
1388         wd->selection_asked = EINA_FALSE;
1389      }
1390    else if (ev->selection == ECORE_X_SELECTION_XDND)
1391      {
1392         Ecore_X_Selection_Data_Text *text_data;
1393
1394         text_data = ev->data;
1395         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1396           {
1397              if (text_data->text)
1398                {
1399                   char *txt = _text_to_mkup(text_data->text);
1400
1401                   if (txt)
1402                     {
1403                      /* Massive FIXME: this should be at the drag point */
1404                        elm_entry_entry_insert(data, txt);
1405                        free(txt);
1406                     }
1407                }
1408           }
1409         wd->drag_selection_asked = EINA_FALSE;
1410
1411         ecore_x_dnd_send_finished();
1412
1413      }
1414    return ECORE_CALLBACK_PASS_ON;
1415 }
1416
1417 static Eina_Bool
1418 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1419 {
1420 /*
1421    Widget_Data *wd = elm_widget_data_get(data);
1422    Ecore_X_Event_Selection_Clear *ev = event;
1423    if (!wd) return 1;
1424    if (!wd->have_selection) return 1;
1425    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1426        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1427      {
1428         elm_entry_select_none(data);
1429      }
1430    return 1;*/
1431
1432         // start for cbhm
1433    Evas_Object *top = elm_widget_top_get(data);
1434    Ecore_X_Event_Selection_Clear *ev = event;
1435
1436    if (!top)
1437            return ECORE_CALLBACK_PASS_ON;
1438
1439         if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1440         {
1441                 return ECORE_CALLBACK_PASS_ON;
1442         }
1443
1444         elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data);
1445         // end for cbhm
1446    return ECORE_CALLBACK_PASS_ON;
1447 }
1448
1449
1450 static Eina_Bool
1451 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Drop_Data *drop)
1452 {
1453    Widget_Data *wd;
1454    Eina_Bool rv;
1455
1456    wd = elm_widget_data_get(obj);
1457
1458    if (!wd) return EINA_FALSE;
1459 //printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1460
1461    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1462                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1463    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1464                                           EDJE_CURSOR_MAIN,drop->x,drop->y);
1465 //   if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1466    elm_entry_entry_insert(obj, drop->data);
1467    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1468                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1469
1470    return EINA_TRUE;
1471 }
1472 #endif
1473
1474 static Evas_Object *
1475 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1476 {
1477    Widget_Data *wd = elm_widget_data_get(data);
1478    Evas_Object *o;
1479    Eina_List *l;
1480    Elm_Entry_Item_Provider *ip;
1481    int ok = 0;
1482
1483    EINA_LIST_FOREACH(wd->item_providers, l, ip)
1484      {
1485         o = ip->func(ip->data, data, item);
1486         if (o) return o;
1487      }
1488    o = edje_object_add(evas_object_evas_get(data));
1489    if (!strncmp(item, "emoticon/", 9))
1490      ok = _elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data));
1491    if (!ok)
1492      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1493    return o;
1494 }
1495
1496 static int
1497 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1498 {
1499    char *curlocater, *starttag, *endtag;
1500    int firstindex = 0, foundflag = -1;
1501
1502    curlocater = strstr(oldstring, key);
1503    if (curlocater)
1504      {
1505         starttag = curlocater;
1506         endtag = curlocater + strlen(key);
1507         if (endtag == NULL || *endtag != '=') 
1508           {
1509             foundflag = 0;
1510             return -1;
1511           }
1512
1513         firstindex = abs(oldstring - curlocater);
1514         firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1515         *value = (char*)oldstring + firstindex;
1516
1517         while (oldstring != starttag)
1518           {
1519             if (*starttag == '>')
1520               {
1521                 foundflag = 0;
1522                 break;
1523               }
1524             if (*starttag == '<') 
1525               break;
1526             else 
1527               starttag--;
1528             if (starttag == NULL) break;
1529           }
1530
1531         while (NULL != endtag)
1532           {
1533             if (*endtag == '<')
1534               {
1535                 foundflag = 0;
1536                 break;
1537               }
1538             if (*endtag == '>') 
1539               break;
1540             else 
1541               endtag++;
1542             if (endtag == NULL) break;
1543           }
1544
1545         if (foundflag != 0 && *starttag == '<' && *endtag == '>') 
1546           foundflag = 1;
1547         else 
1548           foundflag = 0;
1549      }
1550    else
1551      {
1552        foundflag = 0;
1553      }
1554
1555    if (foundflag == 1) return 0;
1556
1557    return -1;
1558 }
1559
1560 static int
1561 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1562 {
1563    const char *srcstring = NULL;
1564    Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1565    char *curlocater, *replocater;
1566    char *starttag, *endtag;
1567    int tagtxtlen = 0, insertflag = 0;
1568
1569    srcstring = eina_strbuf_string_get(srcbuf);
1570    curlocater = strstr(srcstring, key);
1571
1572    if (curlocater == NULL)
1573      {
1574        insertflag = 1;
1575      }
1576    else
1577      {
1578        do 
1579          {
1580            starttag = strchr(srcstring, '<');
1581            endtag = strchr(srcstring, '>');
1582            tagtxtlen = endtag - starttag;
1583            if (tagtxtlen <= 0) tagtxtlen = 0;
1584            if (starttag < curlocater && curlocater < endtag) break;
1585            if (endtag != NULL && endtag+1 != NULL)
1586              srcstring = endtag+1;
1587            else
1588              break;
1589          } while (strlen(srcstring) > 1);
1590
1591        if (starttag && endtag && tagtxtlen > strlen(key))
1592          {
1593            repbuf = eina_strbuf_new();
1594            diffbuf = eina_strbuf_new();
1595            eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1596            srcstring = eina_strbuf_string_get(repbuf);
1597            curlocater = strstr(srcstring, key);
1598
1599            if (curlocater != NULL)
1600              {
1601                replocater = curlocater + strlen(key) + 1;
1602
1603                while (*replocater == ' ' || *replocater == '=')
1604                            {
1605                  replocater++;
1606                            }
1607
1608                 while (*replocater != NULL && *replocater != ' ' && *replocater != '>')
1609                   replocater++;
1610
1611                if (replocater-curlocater > strlen(key)+1)
1612                  {
1613                    replocater--;
1614                    eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1615                  }
1616                else
1617                  insertflag = 1;
1618              }
1619            else
1620              {
1621                insertflag = 1;
1622              }
1623            eina_strbuf_reset(repbuf);
1624          }
1625        else
1626          {
1627            insertflag = 1; 
1628          }
1629      }
1630
1631    if (repbuf == NULL) repbuf = eina_strbuf_new();
1632    if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1633
1634    if (insertflag)
1635      {
1636        eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1637        eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1638      }
1639    else
1640      {
1641         if (deleteflag)
1642           {
1643             eina_strbuf_prepend(diffbuf, "<");
1644             eina_strbuf_append(diffbuf, ">");
1645             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1646           }
1647         else
1648           {
1649             eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1650             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1651           }
1652      }
1653
1654    if (repbuf) eina_strbuf_free(repbuf);
1655    if (diffbuf) eina_strbuf_free(diffbuf);
1656   
1657    return 0;           
1658 }
1659
1660 static int
1661 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1662 {
1663    Eina_Strbuf *sharebuf = NULL;   
1664    
1665    sharebuf = eina_strbuf_new();
1666    eina_strbuf_append(sharebuf, *srcstring);
1667    _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1668    eina_stringshare_del(*srcstring);
1669    *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1670    eina_strbuf_free(sharebuf);
1671
1672    return 0;
1673 }
1674
1675 static int
1676 _is_width_over(Evas_Object *obj)
1677 {
1678    Evas_Coord x, y, w, h;
1679    Evas_Coord vx, vy, vw, vh;
1680    Widget_Data *wd = elm_widget_data_get(obj);
1681
1682    if (!wd) return 0;
1683
1684    edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1685
1686    evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1687
1688    if (x >= 0 && y >= 0)
1689            return 0;
1690
1691    if (4 < wd->wrap_w && w > wd->wrap_w)
1692            return 1;
1693
1694    return 0;
1695 }
1696
1697 static void
1698 _reverse_ellipsis_entry(Evas_Object *obj)
1699 {
1700    Widget_Data *wd = elm_widget_data_get(obj);
1701    int cur_fontsize = 0;
1702    Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1703    char **kvalue = NULL;
1704    const char *minfont, *deffont, *maxfont;
1705    const char *ellipsis_string = "...";
1706    int minfontsize, maxfontsize, minshowcount;
1707
1708    minshowcount = strlen(ellipsis_string) + 1;
1709    minfont = edje_object_data_get(wd->ent, "min_font_size");
1710    if (minfont) minfontsize = atoi(minfont);
1711    else minfontsize = 1;
1712    maxfont = edje_object_data_get(wd->ent, "max_font_size");
1713    if (maxfont) maxfontsize = atoi(maxfont);
1714    else maxfontsize = 1;
1715    deffont = edje_object_data_get(wd->ent, "default_font_size");
1716    if (deffont) cur_fontsize = atoi(deffont);
1717    else cur_fontsize = 1;
1718    if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1719    if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1720
1721    if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1722      {
1723        if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1724      }
1725
1726    txtbuf = eina_strbuf_new();
1727    eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1728
1729    if (cur_fontsize >= atoi(deffont))
1730      {
1731        if (txtbuf) eina_strbuf_free(txtbuf);
1732        return;
1733      }
1734
1735    if (_is_width_over(obj) != 1)
1736      {
1737        int rev_fontsize = cur_fontsize;
1738   
1739        do {
1740            rev_fontsize++;
1741            if (rev_fontsize > atoi(deffont))
1742              break;
1743
1744            if (fontbuf != NULL)
1745              {
1746                eina_strbuf_free(fontbuf);
1747                fontbuf = NULL;
1748              }
1749            fontbuf = eina_strbuf_new();
1750            eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1751            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1752            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1753
1754            eina_strbuf_free(fontbuf);
1755            fontbuf = NULL;
1756          } while (_is_width_over(obj) != 1);
1757
1758        while (_is_width_over(obj))
1759          {
1760            rev_fontsize--;
1761            if (rev_fontsize < atoi(deffont))
1762              break;
1763
1764            if (fontbuf != NULL)
1765              {
1766                eina_strbuf_free(fontbuf);
1767                fontbuf = NULL;
1768              }
1769            fontbuf = eina_strbuf_new();
1770            eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1771            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1772            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1773            eina_strbuf_free(fontbuf);
1774            fontbuf = NULL;
1775          }
1776      }
1777
1778    if (txtbuf) eina_strbuf_free(txtbuf);
1779    wd->changed = 1;
1780    _sizing_eval(obj);
1781 }
1782
1783 static void
1784 _ellipsis_entry_to_width(Evas_Object *obj)
1785 {
1786    Widget_Data *wd = elm_widget_data_get(obj);
1787    int cur_fontsize = 0, len, jumpcount;
1788    Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1789    char **kvalue = NULL;
1790    const char *minfont, *deffont, *maxfont;
1791    const char *ellipsis_string = "...";
1792    int minfontsize, maxfontsize, minshowcount;
1793    int i, tagend, cur_len;
1794    char *cur_str;
1795
1796    minshowcount = strlen(ellipsis_string) + 1;
1797    minfont = edje_object_data_get(wd->ent, "min_font_size");
1798    if (minfont) minfontsize = atoi(minfont);
1799    else minfontsize = 1;
1800    maxfont = edje_object_data_get(wd->ent, "max_font_size");
1801    if (maxfont) maxfontsize = atoi(maxfont);
1802    else maxfontsize = 1;
1803    deffont = edje_object_data_get(wd->ent, "default_font_size");
1804    if (deffont) cur_fontsize = atoi(deffont);
1805    else cur_fontsize = 1;
1806    if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1807    if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1808
1809    if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1810      {
1811        if (*kvalue != NULL) cur_fontsize = atoi((char*)kvalue);
1812      }
1813
1814    txtbuf = eina_strbuf_new();
1815    eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1816
1817    while (_is_width_over(obj))
1818      {
1819        if (wd->ellipsis_threshold == 0)
1820          wd->ellipsis_threshold = _entry_length_get(obj);
1821        if (cur_fontsize > minfontsize)
1822          {
1823            cur_fontsize--;
1824            if (fontbuf != NULL)
1825              {
1826                eina_strbuf_free(fontbuf);
1827                fontbuf = NULL;
1828              }
1829            fontbuf = eina_strbuf_new();
1830            eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1831            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1832            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1833            eina_strbuf_free(fontbuf);
1834            fontbuf = NULL;
1835                    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1836          }
1837        else
1838          {
1839            len = _entry_length_get(obj);
1840            cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1841            cur_len = strlen(cur_str);
1842            tagend = 0;
1843            for (i = 0; i < len; i++)
1844              {
1845                if(cur_str[i] == '>' && cur_str[i+1] != NULL && 
1846                   cur_str[i+1] != '<')
1847                  {
1848                    tagend = i;
1849                    break;
1850                  }
1851              }
1852            jumpcount = 0;
1853            while (jumpcount < len-strlen(ellipsis_string))
1854              {
1855                cur_str = edje_object_part_text_get(wd->ent, "elm.text");
1856
1857                if (txtbuf != NULL)
1858                  {
1859                    eina_strbuf_free(txtbuf);
1860                    txtbuf = NULL;
1861                  }
1862                txtbuf = eina_strbuf_new();
1863                eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1864                eina_strbuf_append(txtbuf, ellipsis_string);
1865                eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1866                edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1867                edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1868
1869                if (_is_width_over(obj)) 
1870                  jumpcount++;
1871                else 
1872                  break;
1873              }
1874          }
1875      }
1876
1877    if (txtbuf) eina_strbuf_free(txtbuf);
1878    wd->changed = 1;
1879    _sizing_eval(obj);
1880 }
1881
1882 static int _textinput_control_function(void *data,void *input_data)
1883 {
1884    /*calculate character count*/
1885    Evas_Object *entry = (Evas_Object *)data;
1886    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1887    char buf[10]="\0";
1888    size_t byte_len;
1889    size_t insert_text_len=0;
1890    char *text = edje_object_part_text_get(wd->ent, "elm.text");
1891    char *insert_text;  
1892    size_t remain_bytes;
1893    if(text!=NULL)
1894      {
1895        byte_len = strlen(text);/*no of bytes*/
1896        remain_bytes = wd->max_no_of_bytes-byte_len;
1897        sprintf(buf,"%d",remain_bytes);
1898        edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1899        if(input_data)
1900          {
1901            insert_text =  (char *)input_data;
1902            insert_text_len = strlen(insert_text);
1903            if(remain_bytes<insert_text_len)
1904              {
1905                evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1906                return EINA_TRUE;
1907              }
1908            if(byte_len>=wd->max_no_of_bytes)
1909              {
1910                evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1911                return EINA_TRUE;
1912              }
1913          }
1914      }
1915    return EINA_FALSE;  
1916 }
1917
1918 /**
1919  * This adds an entry to @p parent object.
1920  *
1921  * @param parent The parent object
1922  * @return The new object or NULL if it cannot be created
1923  *
1924  * @ingroup Entry
1925  */
1926 EAPI Evas_Object *
1927 elm_entry_add(Evas_Object *parent)
1928 {
1929    Evas_Object *obj, *top;
1930    Evas *e;
1931    Widget_Data *wd;
1932
1933    wd = ELM_NEW(Widget_Data);
1934    e = evas_object_evas_get(parent);
1935    wd->bgcolor = EINA_FALSE;
1936    wd->bg = evas_object_rectangle_add(e);
1937    evas_object_color_set(wd->bg, 0, 0, 0, 0);
1938    obj = elm_widget_add(e);
1939    ELM_SET_WIDTYPE(widtype, "entry");
1940    elm_widget_type_set(obj, "entry");
1941    elm_widget_sub_object_add(parent, obj);
1942    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1943    elm_widget_data_set(obj, wd);
1944    elm_widget_del_hook_set(obj, _del_hook);
1945    elm_widget_theme_hook_set(obj, _theme_hook);
1946    elm_widget_disable_hook_set(obj, _disable_hook);
1947    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1948    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1949    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1950    elm_widget_can_focus_set(obj, 1);
1951 #ifdef HAVE_CONFORMANT_AUTOSCROLL
1952    elm_widget_imp_region_get_hook_set(obj, _imp_region_get_hook, NULL);
1953 #endif
1954
1955    wd->linewrap     = EINA_TRUE;
1956    wd->ellipsis     = EINA_FALSE;
1957    wd->char_linewrap= EINA_FALSE;
1958    wd->editable     = EINA_TRUE;
1959    wd->disabled     = EINA_FALSE;
1960    wd->context_menu = EINA_TRUE;
1961
1962    wd->ellipsis_threshold = 0;
1963
1964    wd->ent = edje_object_add(e);
1965    edje_object_item_provider_set(wd->ent, _get_item, obj);
1966    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1967    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1968    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1969                                   _mouse_down, obj);
1970    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1971                                   _mouse_up, obj);
1972    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1973                                   _mouse_move, obj);
1974
1975    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1976    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1977                                    _signal_entry_changed, obj);
1978    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1979                                    _signal_selection_start, obj);
1980    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1981                                    _signal_selection_changed, obj);
1982    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1983                                    _signal_selection_cleared, obj);
1984    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1985                                    _signal_entry_paste_request, obj);
1986    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1987                                    _signal_entry_copy_notify, obj);
1988    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1989                                    _signal_entry_cut_notify, obj);
1990    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1991                                    _signal_cursor_changed, obj);
1992    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1993                                    _signal_anchor_down, obj);
1994    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1995                                    _signal_anchor_up, obj);
1996    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1997                                    _signal_anchor_move, obj);
1998    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1999                                    _signal_anchor_in, obj);
2000    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2001                                    _signal_anchor_out, obj);
2002    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2003                                    _signal_key_enter, obj);
2004    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2005                                    _signal_mouse_down, obj);
2006    edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
2007                                    _signal_mouse_up, obj);
2008    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2009                                    _signal_mouse_double, obj);
2010    edje_object_part_text_set(wd->ent, "elm.text", "");
2011    elm_widget_resize_object_set(obj, wd->ent);
2012    _sizing_eval(obj);
2013
2014    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2015
2016 #ifdef HAVE_ELEMENTARY_X
2017    top = elm_widget_top_get(obj);
2018    if ((top) && (elm_win_xwindow_get(top)))
2019      {
2020         wd->sel_notify_handler =
2021           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2022                                   _event_selection_notify, obj);
2023         wd->sel_clear_handler =
2024           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2025                                   _event_selection_clear, obj);
2026      }
2027
2028    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2029 #endif
2030
2031    entries = eina_list_prepend(entries, obj);
2032
2033    // module - find module for entry
2034    wd->api = _module(obj);
2035    // if found - hook in
2036    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2037
2038    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2039    // TODO: and save some bytes, making descriptions per-class and not instance!
2040    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2041    return obj;
2042 }
2043
2044 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2045 {
2046    ELM_CHECK_WIDTYPE(obj, widtype);
2047    Widget_Data *wd = elm_widget_data_get(obj);
2048    if (!wd) return;
2049    ext_mod->cancel = _cancel;
2050    ext_mod->copy = _copy;
2051    ext_mod->cut = _cut;
2052    ext_mod->paste = _paste;
2053    ext_mod->select = _select;
2054    ext_mod->selectall = NULL; /* to be implemented*/
2055    ext_mod->ent = wd->ent;
2056    ext_mod->items = wd->items;
2057    ext_mod->longpress_timer = wd->longpress_timer;
2058    ext_mod->editable = wd->editable;
2059    ext_mod->have_selection = wd->have_selection;
2060    ext_mod->password = wd->password;
2061    ext_mod->selmode = wd->selmode;
2062    ext_mod->context_menu = wd->context_menu;
2063 }
2064
2065 /**
2066  * This sets the entry object not to line wrap.  All input will
2067  * be on a single line, and the entry box will extend with user input.
2068  *
2069  * @param obj The entry object
2070  * @param single_line If true, the text in the entry
2071  * will be on a single line.
2072  *
2073  * @ingroup Entry
2074  */
2075 EAPI void
2076 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2077 {
2078    ELM_CHECK_WIDTYPE(obj, widtype);
2079    Widget_Data *wd = elm_widget_data_get(obj);
2080    const char *t;
2081    Ecore_IMF_Context *ic;
2082    if (!wd) return;
2083    if (wd->single_line == single_line) return;
2084    wd->single_line = single_line;
2085    wd->linewrap = EINA_FALSE;
2086    wd->char_linewrap = EINA_FALSE;
2087    t = eina_stringshare_add(elm_entry_entry_get(obj));
2088    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2089    elm_entry_entry_set(obj, t);
2090    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2091    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2092    ic = elm_entry_imf_context_get(obj);
2093    if (ic)
2094      {
2095         ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2096      }
2097
2098    eina_stringshare_del(t);
2099    _sizing_eval(obj);
2100 }
2101
2102 /**
2103  * This returns true if the entry has been set to single line mode.
2104  * See also elm_entry_single_line_set().
2105  *
2106  * @param obj The entry object
2107  * @return single_line If true, the text in the entry is set to display
2108  * on a single line.
2109  *
2110  * @ingroup Entry
2111  */
2112 EAPI Eina_Bool
2113 elm_entry_single_line_get(const Evas_Object *obj)
2114 {
2115    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2116    Widget_Data *wd = elm_widget_data_get(obj);
2117    if (!wd) return EINA_FALSE;
2118    return wd->single_line;
2119 }
2120
2121 /**
2122  * This set's the maximum bytes that can be added in entry.
2123  *
2124  * @param obj The entry object
2125  * @param max_no_of_bytes Maximum number of bytes entry can have.
2126  * 
2127  * @ingroup Entry
2128  */
2129 EAPI void
2130 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2131 {
2132    Widget_Data *wd = elm_widget_data_get(obj);
2133
2134    wd->max_no_of_bytes = max_no_of_bytes;
2135    edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2136    edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2137  }
2138
2139
2140 /**
2141  * This sets the entry object to password mode.  All text entered
2142  * and/or displayed within the widget will be replaced with asterisks (*).
2143  *
2144  * @param obj The entry object
2145  * @param password If true, password mode is enabled.
2146  *
2147  * @ingroup Entry
2148  */
2149 EAPI void
2150 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2151 {
2152    ELM_CHECK_WIDTYPE(obj, widtype);
2153    Widget_Data *wd = elm_widget_data_get(obj);
2154    Ecore_IMF_Context *ic;
2155    const char *t;
2156    if (!wd) return;
2157    if (wd->password == password) return;
2158    wd->password = password;
2159    wd->show_last_character = EINA_FALSE;
2160    wd->single_line = EINA_TRUE;
2161    wd->linewrap = EINA_FALSE;
2162    wd->char_linewrap = EINA_FALSE;
2163    t = eina_stringshare_add(elm_entry_entry_get(obj));
2164    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2165    elm_entry_entry_set(obj, t);
2166
2167    ic = elm_entry_imf_context_get(obj);
2168    if (ic)
2169      {
2170         ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2171      }
2172
2173    eina_stringshare_del(t);
2174    _sizing_eval(obj);
2175 }
2176
2177 /**
2178  * This set's the entry in password mode with out masking the last character entered by user,
2179  * and later masking the character after 2 seconds.
2180  
2181  * @param obj The entry object
2182  * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character" 
2183  * 0 for default).
2184  *
2185  * @ingroup Entry
2186  */
2187 EAPI void         
2188 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2189 {
2190    Widget_Data *wd = elm_widget_data_get(obj);
2191    const char *t;
2192    if (!wd) return;
2193    if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character))  return;
2194    wd->show_last_character = show_last_character;
2195    wd->password = show_last_character;
2196    wd->single_line = EINA_TRUE;
2197    wd->linewrap = EINA_FALSE;
2198    wd->char_linewrap = EINA_FALSE;
2199    t = eina_stringshare_add(elm_entry_entry_get(obj));
2200     _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2201    elm_entry_entry_set(obj, t);
2202    eina_stringshare_del(t);
2203    _sizing_eval(obj);
2204 }
2205
2206 /**
2207  * This returns whether password mode is enabled.
2208  * See also elm_entry_password_set().
2209  *
2210  * @param obj The entry object
2211  * @return If true, the entry is set to display all characters
2212  * as asterisks (*).
2213  *
2214  * @ingroup Entry
2215  */
2216 EAPI Eina_Bool
2217 elm_entry_password_get(const Evas_Object *obj)
2218 {
2219    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2220    Widget_Data *wd = elm_widget_data_get(obj);
2221    if (!wd) return EINA_FALSE;
2222    return wd->password;
2223 }
2224
2225 /**
2226  * This sets the text displayed within the entry to @p entry.
2227  *
2228  * @param obj The entry object
2229  * @param entry The text to be displayed
2230  *
2231  * @ingroup Entry
2232  */
2233 EAPI void
2234 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2235 {
2236    ELM_CHECK_WIDTYPE(obj, widtype);
2237    Widget_Data *wd = elm_widget_data_get(obj);
2238    if (!wd) return;
2239    if (!entry) entry = "";
2240    if(wd->max_no_of_bytes)
2241      {
2242        int len = strlen(entry);
2243        if(len > wd->max_no_of_bytes)
2244        {
2245          ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2246          return;
2247        }
2248      }
2249    edje_object_part_text_set(wd->ent, "elm.text", entry);
2250    if (wd->text) eina_stringshare_del(wd->text);
2251    wd->text = NULL;
2252    wd->changed = EINA_TRUE;
2253    _sizing_eval(obj);
2254 }
2255
2256 /**
2257  * This returns the text currently shown in object @p entry.
2258  * See also elm_entry_entry_set().
2259  *
2260  * @param obj The entry object
2261  * @return The currently displayed text or NULL on failure
2262  *
2263  * @ingroup Entry
2264  */
2265 EAPI const char *
2266 elm_entry_entry_get(const Evas_Object *obj)
2267 {
2268    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2269    Widget_Data *wd = elm_widget_data_get(obj);
2270    const char *text;
2271    if (!wd) return NULL;
2272    if (wd->text) return wd->text;
2273    text = edje_object_part_text_get(wd->ent, "elm.text");
2274    if (!text)
2275      {
2276         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2277         return NULL;
2278      }
2279    eina_stringshare_replace(&wd->text, text);
2280    return wd->text;
2281 }
2282
2283 /**
2284  * This returns all selected text within the entry.
2285  *
2286  * @param obj The entry object
2287  * @return The selected text within the entry or NULL on failure
2288  *
2289  * @ingroup Entry
2290  */
2291 EAPI const char *
2292 elm_entry_selection_get(const Evas_Object *obj)
2293 {
2294    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2295    Widget_Data *wd = elm_widget_data_get(obj);
2296    if (!wd) return NULL;
2297    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2298 }
2299
2300 /**
2301  * This inserts text in @p entry at the beginning of the entry
2302  * object.
2303  *
2304  * @param obj The entry object
2305  * @param entry The text to insert
2306  *
2307  * @ingroup Entry
2308  */
2309 EAPI void
2310 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2311 {
2312    ELM_CHECK_WIDTYPE(obj, widtype);
2313    Widget_Data *wd = elm_widget_data_get(obj);
2314    if (!wd) return;
2315    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2316    wd->changed = EINA_TRUE;
2317    _sizing_eval(obj);
2318 }
2319
2320 /**
2321  * This enables word line wrapping in the entry object.  It is the opposite
2322  * of elm_entry_single_line_set().  Additionally, setting this disables
2323  * character line wrapping.
2324  * See also elm_entry_line_char_wrap_set().
2325  *
2326  * @param obj The entry object
2327  * @param wrap If true, the entry will be wrapped once it reaches the end
2328  * of the object. Wrapping will occur at the end of the word before the end of the
2329  * object.
2330  *
2331  * @ingroup Entry
2332  */
2333 EAPI void
2334 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2335 {
2336    ELM_CHECK_WIDTYPE(obj, widtype);
2337    Widget_Data *wd = elm_widget_data_get(obj);
2338    const char *t;
2339    if (!wd) return;
2340    if (wd->linewrap == wrap) return;
2341    wd->linewrap = wrap;
2342    if(wd->linewrap)
2343        wd->char_linewrap = EINA_FALSE;
2344    t = eina_stringshare_add(elm_entry_entry_get(obj));
2345    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2346    elm_entry_entry_set(obj, t);
2347    eina_stringshare_del(t);
2348    _sizing_eval(obj);
2349 }
2350
2351 /**
2352  * Set wrap width of the entry
2353  *
2354  * @param obj The entry object
2355  * @param w The wrap width in pixels at a minimum where words need to wrap
2356  * @ingroup Entry
2357  */
2358 EAPI void
2359 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2360 {
2361    Widget_Data *wd = elm_widget_data_get(obj);
2362    if (wd->wrap_w == w) return;
2363    wd->wrap_w = w;
2364    _sizing_eval(obj);
2365 }
2366
2367 /**
2368  * get wrap width of the entry
2369  *
2370  * @param obj The entry object
2371  * @return The wrap width in pixels at a minimum where words need to wrap
2372  * @ingroup Entry
2373  */
2374 EAPI Evas_Coord
2375 elm_entry_wrap_width_get(const Evas_Object *obj)
2376 {
2377    Widget_Data *wd = elm_widget_data_get(obj);
2378    return wd->wrap_w;
2379 }
2380
2381 /**
2382  * This enables character line wrapping in the entry object.  It is the opposite
2383  * of elm_entry_single_line_set().  Additionally, setting this disables
2384  * word line wrapping.
2385  * See also elm_entry_line_wrap_set().
2386  *
2387  * @param obj The entry object
2388  * @param wrap If true, the entry will be wrapped once it reaches the end
2389  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2390  *
2391  * @ingroup Entry
2392  */
2393 EAPI void
2394 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2395 {
2396    ELM_CHECK_WIDTYPE(obj, widtype);
2397    Widget_Data *wd = elm_widget_data_get(obj);
2398    const char *t;
2399    if (!wd) return;
2400    if (wd->char_linewrap == wrap) return;
2401    wd->char_linewrap = wrap;
2402    if(wd->char_linewrap)
2403        wd->linewrap = EINA_FALSE;
2404    t = eina_stringshare_add(elm_entry_entry_get(obj));
2405    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2406    elm_entry_entry_set(obj, t);
2407    eina_stringshare_del(t);
2408    _sizing_eval(obj);
2409 }
2410
2411 /**
2412  * This sets the editable attribute of the entry.
2413  *
2414  * @param obj The entry object
2415  * @param editable If true, the entry will be editable by the user.
2416  * If false, it will be set to the disabled state.
2417  *
2418  * @ingroup Entry
2419  */
2420 EAPI void
2421 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2422 {
2423    ELM_CHECK_WIDTYPE(obj, widtype);
2424    Widget_Data *wd = elm_widget_data_get(obj);
2425    const char *t;
2426    if (!wd) return;
2427    if (wd->editable == editable) return;
2428    wd->editable = editable;
2429    t = eina_stringshare_add(elm_entry_entry_get(obj));
2430    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2431    elm_entry_entry_set(obj, t);
2432    eina_stringshare_del(t);
2433    _sizing_eval(obj);
2434
2435 #ifdef HAVE_ELEMENTARY_X
2436    if (editable)
2437       elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2438    else
2439       elm_drop_target_del(obj);
2440 #endif
2441 }
2442
2443 /**
2444  * This gets the editable attribute of the entry.
2445  * See also elm_entry_editable_set().
2446  *
2447  * @param obj The entry object
2448  * @return If true, the entry is editable by the user.
2449  * If false, it is not editable by the user
2450  *
2451  * @ingroup Entry
2452  */
2453 EAPI Eina_Bool
2454 elm_entry_editable_get(const Evas_Object *obj)
2455 {
2456    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2457    Widget_Data *wd = elm_widget_data_get(obj);
2458    if (!wd) return EINA_FALSE;
2459    return wd->editable;
2460 }
2461
2462 /**
2463  * This drops any existing text selection within the entry.
2464  *
2465  * @param obj The entry object
2466  *
2467  * @ingroup Entry
2468  */
2469 EAPI void
2470 elm_entry_select_none(Evas_Object *obj)
2471 {
2472    ELM_CHECK_WIDTYPE(obj, widtype);
2473    Widget_Data *wd = elm_widget_data_get(obj);
2474    if (!wd) return;
2475    if (wd->selmode)
2476      {
2477         wd->selmode = EINA_FALSE;
2478         edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2479         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2480      }
2481    wd->have_selection = EINA_FALSE;
2482    edje_object_part_text_select_none(wd->ent, "elm.text");
2483 }
2484
2485 /**
2486  * This selects all text within the entry.
2487  *
2488  * @param obj The entry object
2489  *
2490  * @ingroup Entry
2491  */
2492 EAPI void
2493 elm_entry_select_all(Evas_Object *obj)
2494 {
2495    ELM_CHECK_WIDTYPE(obj, widtype);
2496    Widget_Data *wd = elm_widget_data_get(obj);
2497    if (!wd) return;
2498    if (wd->selmode)
2499      {
2500         wd->selmode = EINA_FALSE;
2501         edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2502         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2503      }
2504    wd->have_selection = EINA_TRUE;
2505    edje_object_part_text_select_all(wd->ent, "elm.text");
2506 }
2507
2508 /**
2509  * This moves the cursor one place to the right within the entry.
2510  *
2511  * @param obj The entry object
2512  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2513  *
2514  * @ingroup Entry
2515  */
2516 EAPI Eina_Bool
2517 elm_entry_cursor_next(Evas_Object *obj)
2518 {
2519    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2520    Widget_Data *wd = elm_widget_data_get(obj);
2521    if (!wd) return EINA_FALSE;
2522    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2523 }
2524
2525 /**
2526  * This moves the cursor one place to the left within the entry.
2527  *
2528  * @param obj The entry object
2529  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2530  *
2531  * @ingroup Entry
2532  */
2533 EAPI Eina_Bool
2534 elm_entry_cursor_prev(Evas_Object *obj)
2535 {
2536    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2537    Widget_Data *wd = elm_widget_data_get(obj);
2538    if (!wd) return EINA_FALSE;
2539    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2540 }
2541
2542 /**
2543  * This moves the cursor one line up within the entry.
2544  *
2545  * @param obj The entry object
2546  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2547  *
2548  * @ingroup Entry
2549  */
2550 EAPI Eina_Bool
2551 elm_entry_cursor_up(Evas_Object *obj)
2552 {
2553    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2554    Widget_Data *wd = elm_widget_data_get(obj);
2555    if (!wd) return EINA_FALSE;
2556    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2557 }
2558
2559 /**
2560  * This moves the cursor one line down within the entry.
2561  *
2562  * @param obj The entry object
2563  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2564  *
2565  * @ingroup Entry
2566  */
2567 EAPI Eina_Bool
2568 elm_entry_cursor_down(Evas_Object *obj)
2569 {
2570    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2571    Widget_Data *wd = elm_widget_data_get(obj);
2572    if (!wd) return EINA_FALSE;
2573    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2574 }
2575
2576 /**
2577  * This moves the cursor to the beginning of the entry.
2578  *
2579  * @param obj The entry object
2580  *
2581  * @ingroup Entry
2582  */
2583 EAPI void
2584 elm_entry_cursor_begin_set(Evas_Object *obj)
2585 {
2586    ELM_CHECK_WIDTYPE(obj, widtype);
2587    Widget_Data *wd = elm_widget_data_get(obj);
2588    if (!wd) return;
2589    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2590 }
2591
2592 /**
2593  * This moves the cursor to the end of the entry.
2594  *
2595  * @param obj The entry object
2596  *
2597  * @ingroup Entry
2598  */
2599 EAPI void
2600 elm_entry_cursor_end_set(Evas_Object *obj)
2601 {
2602    ELM_CHECK_WIDTYPE(obj, widtype);
2603    Widget_Data *wd = elm_widget_data_get(obj);
2604    if (!wd) return;
2605    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2606 }
2607
2608 /**
2609  * This moves the cursor to the beginning of the current line.
2610  *
2611  * @param obj The entry object
2612  *
2613  * @ingroup Entry
2614  */
2615 EAPI void
2616 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2617 {
2618    ELM_CHECK_WIDTYPE(obj, widtype);
2619    Widget_Data *wd = elm_widget_data_get(obj);
2620    if (!wd) return;
2621    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2622 }
2623
2624 /**
2625  * This moves the cursor to the end of the current line.
2626  *
2627  * @param obj The entry object
2628  *
2629  * @ingroup Entry
2630  */
2631 EAPI void
2632 elm_entry_cursor_line_end_set(Evas_Object *obj)
2633 {
2634    ELM_CHECK_WIDTYPE(obj, widtype);
2635    Widget_Data *wd = elm_widget_data_get(obj);
2636    if (!wd) return;
2637    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2638 }
2639
2640 /**
2641  * This begins a selection within the entry as though
2642  * the user were holding down the mouse button to make a selection.
2643  *
2644  * @param obj The entry object
2645  *
2646  * @ingroup Entry
2647  */
2648 EAPI void
2649 elm_entry_cursor_selection_begin(Evas_Object *obj)
2650 {
2651    ELM_CHECK_WIDTYPE(obj, widtype);
2652    Widget_Data *wd = elm_widget_data_get(obj);
2653    if (!wd) return;
2654    edje_object_part_text_select_begin(wd->ent, "elm.text");
2655 }
2656
2657 /**
2658  * This ends a selection within the entry as though
2659  * the user had just released the mouse button while making a selection.
2660  *
2661  * @param obj The entry object
2662  *
2663  * @ingroup Entry
2664  */
2665 EAPI void
2666 elm_entry_cursor_selection_end(Evas_Object *obj)
2667 {
2668    ELM_CHECK_WIDTYPE(obj, widtype);
2669    Widget_Data *wd = elm_widget_data_get(obj);
2670    if (!wd) return;
2671    edje_object_part_text_select_extend(wd->ent, "elm.text");
2672 }
2673
2674 /**
2675  * TODO: fill this in
2676  *
2677  * @param obj The entry object
2678  * @return TODO: fill this in
2679  *
2680  * @ingroup Entry
2681  */
2682 EAPI Eina_Bool
2683 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2684 {
2685    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2686    Widget_Data *wd = elm_widget_data_get(obj);
2687    if (!wd) return EINA_FALSE;
2688    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2689 }
2690
2691 /**
2692  * This returns whether the cursor is visible.
2693  *
2694  * @param obj The entry object
2695  * @return If true, the cursor is visible.
2696  *
2697  * @ingroup Entry
2698  */
2699 EAPI Eina_Bool
2700 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2701 {
2702    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2703    Widget_Data *wd = elm_widget_data_get(obj);
2704    if (!wd) return EINA_FALSE;
2705    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2706 }
2707
2708 /**
2709  * TODO: fill this in
2710  *
2711  * @param obj The entry object
2712  * @return TODO: fill this in
2713  *
2714  * @ingroup Entry
2715  */
2716 EAPI const char *
2717 elm_entry_cursor_content_get(const Evas_Object *obj)
2718 {
2719    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2720    Widget_Data *wd = elm_widget_data_get(obj);
2721    if (!wd) return NULL;
2722    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2723 }
2724
2725 /**
2726  * This executes a "cut" action on the selected text in the entry.
2727  *
2728  * @param obj The entry object
2729  *
2730  * @ingroup Entry
2731  */
2732 EAPI void
2733 elm_entry_selection_cut(Evas_Object *obj)
2734 {
2735    ELM_CHECK_WIDTYPE(obj, widtype);
2736    Widget_Data *wd = elm_widget_data_get(obj);
2737    if (!wd) return;
2738    _cut(obj, NULL, NULL);
2739 }
2740
2741 /**
2742  * This executes a "copy" action on the selected text in the entry.
2743  *
2744  * @param obj The entry object
2745  *
2746  * @ingroup Entry
2747  */
2748 EAPI void
2749 elm_entry_selection_copy(Evas_Object *obj)
2750 {
2751    ELM_CHECK_WIDTYPE(obj, widtype);
2752    Widget_Data *wd = elm_widget_data_get(obj);
2753    if (!wd) return;
2754    _copy(obj, NULL, NULL);
2755 }
2756
2757 /**
2758  * This executes a "paste" action in the entry.
2759  *
2760  * @param obj The entry object
2761  *
2762  * @ingroup Entry
2763  */
2764 EAPI void
2765 elm_entry_selection_paste(Evas_Object *obj)
2766 {
2767    ELM_CHECK_WIDTYPE(obj, widtype);
2768    Widget_Data *wd = elm_widget_data_get(obj);
2769    if (!wd) return;
2770    _paste(obj, NULL, NULL);
2771 }
2772
2773 /**
2774  * This clears and frees the items in a entry's contextual (right click) menu.
2775  *
2776  * @param obj The entry object
2777  *
2778  * @ingroup Entry
2779  */
2780 EAPI void
2781 elm_entry_context_menu_clear(Evas_Object *obj)
2782 {
2783    ELM_CHECK_WIDTYPE(obj, widtype);
2784    Widget_Data *wd = elm_widget_data_get(obj);
2785    Elm_Entry_Context_Menu_Item *it;
2786    if (!wd) return;
2787    EINA_LIST_FREE(wd->items, it)
2788      {
2789         eina_stringshare_del(it->label);
2790         eina_stringshare_del(it->icon_file);
2791         eina_stringshare_del(it->icon_group);
2792         free(it);
2793      }
2794 }
2795
2796 /**
2797  * This adds an item to the entry's contextual menu.
2798  *
2799  * @param obj The entry object
2800  * @param label The item's text label
2801  * @param icon_file The item's icon file
2802  * @param icon_type The item's icon type
2803  * @param func The callback to execute when the item is clicked
2804  * @param data The data to associate with the item for related functions
2805  *
2806  * @ingroup Entry
2807  */
2808 EAPI void
2809 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)
2810 {
2811    ELM_CHECK_WIDTYPE(obj, widtype);
2812    Widget_Data *wd = elm_widget_data_get(obj);
2813    Elm_Entry_Context_Menu_Item *it;
2814    if (!wd) return;
2815    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2816    if (!it) return;
2817    wd->items = eina_list_append(wd->items, it);
2818    it->obj = obj;
2819    it->label = eina_stringshare_add(label);
2820    it->icon_file = eina_stringshare_add(icon_file);
2821    it->icon_type = icon_type;
2822    it->func = func;
2823    it->data = (void *)data;
2824 }
2825
2826 /**
2827  * This disables the entry's contextual (right click) menu.
2828  *
2829  * @param obj The entry object
2830  * @param disabled If true, the menu is disabled
2831  *
2832  * @ingroup Entry
2833  */
2834 EAPI void
2835 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2836 {
2837    ELM_CHECK_WIDTYPE(obj, widtype);
2838    Widget_Data *wd = elm_widget_data_get(obj);
2839    if (!wd) return;
2840    if (wd->context_menu == !disabled) return;
2841    wd->context_menu = !disabled;
2842 }
2843
2844 /**
2845  * This returns whether the entry's contextual (right click) menu is disabled.
2846  *
2847  * @param obj The entry object
2848  * @return If true, the menu is disabled
2849  *
2850  * @ingroup Entry
2851  */
2852 EAPI Eina_Bool
2853 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2854 {
2855    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2856    Widget_Data *wd = elm_widget_data_get(obj);
2857    if (!wd) return EINA_FALSE;
2858    return !wd->context_menu;
2859 }
2860
2861 /**
2862  * This appends a custom item provider to the list for that entry
2863  *
2864  * This appends the given callback. The list is walked from beginning to end
2865  * with each function called given the item href string in the text. If the
2866  * function returns an object handle other than NULL (it should create an
2867  * and object to do this), then this object is used to replace that item. If
2868  * not the next provider is called until one provides an item object, or the
2869  * default provider in entry does.
2870  * 
2871  * @param obj The entry object
2872  * @param func The function called to provide the item object
2873  * @param data The data passed to @p func
2874  *
2875  * @ingroup Entry
2876  */
2877 EAPI void
2878 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2879 {
2880    ELM_CHECK_WIDTYPE(obj, widtype);
2881    Widget_Data *wd = elm_widget_data_get(obj);
2882    if (!wd) return;
2883    if (!func) return;
2884    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2885    if (!ip) return;
2886    ip->func = func;
2887    ip->data = data;
2888    wd->item_providers = eina_list_append(wd->item_providers, ip);
2889 }
2890
2891 /**
2892  * This prepends a custom item provider to the list for that entry
2893  *
2894  * This prepends the given callback. See elm_entry_item_provider_append() for
2895  * more information
2896  * 
2897  * @param obj The entry object
2898  * @param func The function called to provide the item object
2899  * @param data The data passed to @p func
2900  *
2901  * @ingroup Entry
2902  */
2903 EAPI void
2904 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2905 {
2906    ELM_CHECK_WIDTYPE(obj, widtype);
2907    Widget_Data *wd = elm_widget_data_get(obj);
2908    if (!wd) return;
2909    if (!func) return;
2910    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2911    if (!ip) return;
2912    ip->func = func;
2913    ip->data = data;
2914    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2915 }
2916
2917 /**
2918  * This removes a custom item provider to the list for that entry
2919  *
2920  * This removes the given callback. See elm_entry_item_provider_append() for
2921  * more information
2922  * 
2923  * @param obj The entry object
2924  * @param func The function called to provide the item object
2925  * @param data The data passed to @p func
2926  *
2927  * @ingroup Entry
2928  */
2929 EAPI void
2930 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2931 {
2932    ELM_CHECK_WIDTYPE(obj, widtype);
2933    Widget_Data *wd = elm_widget_data_get(obj);
2934    Eina_List *l;
2935    Elm_Entry_Item_Provider *ip;
2936    if (!wd) return;
2937    if (!func) return;
2938    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2939      {
2940         if ((ip->func == func) && (ip->data == data))
2941           {
2942              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2943              free(ip);
2944              return;
2945           }
2946      }
2947 }
2948
2949 /**
2950  * This converts a markup (HTML-like) string into UTF-8.
2951  *
2952  * @param s The string (in markup) to be converted
2953  * @return The converted string (in UTF-8)
2954  *
2955  * @ingroup Entry
2956  */
2957 EAPI char *
2958 elm_entry_markup_to_utf8(const char *s)
2959 {
2960    char *ss = _mkup_to_text(s);
2961    if (!ss) ss = strdup("");
2962    return ss;
2963 }
2964
2965 /**
2966  * This converts a UTF-8 string into markup (HTML-like).
2967  *
2968  * @param s The string (in UTF-8) to be converted
2969  * @return The converted string (in markup)
2970  *
2971  * @ingroup Entry
2972  */
2973 EAPI char *
2974 elm_entry_utf8_to_markup(const char *s)
2975 {
2976    char *ss = _text_to_mkup(s);
2977    if (!ss) ss = strdup("");
2978    return ss;
2979 }
2980
2981 /**
2982  * Get the input method context in the entry widget
2983  *
2984  * @param obj The entry object
2985  * @return The input method context
2986  *
2987  * @ingroup Entry
2988  */
2989 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2990 {
2991    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2992    Widget_Data *wd = elm_widget_data_get(obj);
2993    if (!wd || !wd->ent) return NULL;
2994   
2995    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2996 }
2997
2998 /**
2999  * Set whether entry should enable the return key on soft keyboard automatically
3000  *
3001  * @param obj The entry object
3002  * @param on If true, entry enables the return key on soft keyboard automatically.
3003  *
3004  * @ingroup Entry
3005  */
3006 EAPI void 
3007 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3008 {
3009    ELM_CHECK_WIDTYPE(obj, widtype);
3010    Widget_Data *wd = elm_widget_data_get(obj);
3011    if (!wd) return;
3012
3013    wd->autoreturnkey = on;
3014    _check_enable_returnkey(obj);
3015 }
3016
3017 /**
3018  * Set whether entry should support auto capitalization
3019  *
3020  * @param obj The entry object
3021  * @param on If true, entry suports auto capitalization.
3022  *
3023  * @ingroup Entry
3024  */
3025 EAPI void 
3026 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3027 {
3028    ELM_CHECK_WIDTYPE(obj, widtype);
3029    Widget_Data *wd = elm_widget_data_get(obj);
3030    if (!wd) return;
3031
3032    if (wd->password)
3033        wd->autocapitalize = EINA_FALSE;
3034    else
3035        wd->autocapitalize = autocap;
3036
3037    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
3038 }
3039
3040 /**
3041  * Set whether entry should support auto period
3042  *
3043  * @param obj The entry object
3044  * @param on If true, entry suports auto period.
3045  *
3046  * @ingroup Entry
3047  */
3048 EAPI void 
3049 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3050 {
3051    ELM_CHECK_WIDTYPE(obj, widtype);
3052    Widget_Data *wd = elm_widget_data_get(obj);
3053    if (!wd) return;
3054
3055    if (wd->password)
3056        wd->autoperiod = EINA_FALSE;
3057    else
3058        wd->autoperiod = autoperiod;
3059
3060    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3061 }
3062
3063 /**
3064  * Set the font size on the entry object
3065  *
3066  * @param obj The entry object
3067  * @param size font size
3068  *
3069  * @ingroup Entry
3070  */
3071 EAPI void
3072 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3073 {
3074    ELM_CHECK_WIDTYPE(obj, widtype);
3075    Widget_Data *wd = elm_widget_data_get(obj);
3076    Eina_Strbuf *fontbuf = NULL;
3077    int removeflag = 0;
3078    const char *t;
3079
3080    if (!wd) return;
3081    t = eina_stringshare_add(elm_entry_entry_get(obj));
3082    fontbuf = eina_strbuf_new();
3083    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3084
3085    if (fontsize == 0) removeflag = 1; // remove fontsize tag
3086
3087    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3088      {
3089        elm_entry_entry_set(obj, t);
3090        wd->changed = 1;
3091        _sizing_eval(obj);
3092      }
3093    eina_strbuf_free(fontbuf);
3094    eina_stringshare_del(t);
3095 }
3096
3097 /**
3098  * Set the text align on the entry object
3099  *
3100  * @param obj The entry object
3101  * @param align align mode
3102  *
3103  * @ingroup Entry
3104  */
3105 EAPI void
3106 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3107 {
3108    ELM_CHECK_WIDTYPE(obj, widtype);
3109    Widget_Data *wd = elm_widget_data_get(obj);
3110    int len;
3111    const char *t;
3112
3113    if (!wd) return;
3114    t = eina_stringshare_add(elm_entry_entry_get(obj));
3115    len = strlen(t);
3116    if (len <= 0) return;
3117
3118    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3119      elm_entry_entry_set(obj, t);
3120
3121    wd->changed = 1;
3122    _sizing_eval(obj);
3123    eina_stringshare_del(t);
3124 }
3125
3126 /**
3127  * Set the text color on the entry object
3128  *
3129  * @param obj The entry object
3130  * @param r Red property background color of The entry object 
3131  * @param g Green property background color of The entry object 
3132  * @param b Blue property background color of The entry object 
3133  * @param a Alpha property background alpha of The entry object 
3134  *
3135  * @ingroup Entry
3136  */
3137 EAPI void
3138 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3139 {
3140    ELM_CHECK_WIDTYPE(obj, widtype);
3141    Widget_Data *wd = elm_widget_data_get(obj);
3142    Eina_Strbuf *colorbuf = NULL;
3143    const char *t;
3144    int len;
3145
3146    if (!wd) return;
3147    t = eina_stringshare_add(elm_entry_entry_get(obj));
3148    len = strlen(t);
3149    if (len <= 0) return;
3150    colorbuf = eina_strbuf_new();
3151    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3152
3153    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3154      {
3155        elm_entry_entry_set(obj, t);
3156        wd->changed = 1;
3157        _sizing_eval(obj);
3158      }
3159    eina_strbuf_free(colorbuf);
3160    eina_stringshare_del(t);
3161 }
3162
3163
3164 /**
3165  * Set background color of the entry
3166  *
3167  * @param obj The entry object
3168  * @param r Red property background color of The entry object 
3169  * @param g Green property background color of The entry object 
3170  * @param b Blue property background color of The entry object 
3171  * @param a Alpha property background alpha of The entry object 
3172  * @ingroup Entry
3173  */
3174 EAPI void
3175 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3176 {
3177    ELM_CHECK_WIDTYPE(obj, widtype);
3178    Widget_Data *wd = elm_widget_data_get(obj);
3179    evas_object_color_set(wd->bg, r, g, b, a);
3180
3181    if (wd->bgcolor == EINA_FALSE)
3182      {
3183        wd->bgcolor = 1;
3184        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3185      }
3186 }
3187
3188 /**
3189  * Set the ellipsis behavior of the entry
3190  *
3191  * @param obj The entry object
3192  * @param ellipsis To ellipsis text or not
3193  * @ingroup Entry
3194  */
3195 EAPI void
3196 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3197 {
3198    ELM_CHECK_WIDTYPE(obj, widtype);
3199    Widget_Data *wd = elm_widget_data_get(obj);
3200    if (wd->ellipsis == ellipsis) return;
3201    wd->ellipsis = ellipsis;
3202    wd->changed = 1;
3203    _sizing_eval(obj);
3204 }
3205
3206 /**
3207  * This sets the attribute to show the input panel automatically.
3208  *
3209  * @param obj The entry object
3210  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3211  *
3212  * @ingroup Entry
3213  */
3214 EAPI void
3215 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3216 {
3217    ELM_CHECK_WIDTYPE(obj, widtype);
3218    Widget_Data *wd = elm_widget_data_get(obj);
3219    if (!wd) return;
3220
3221    wd->input_panel_enable = enabled;
3222    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3223 }
3224
3225 /**
3226  * Set the input panel layout of the entry
3227  *
3228  * @param obj The entry object
3229  * @param layout the layout to set
3230  *
3231  * @ingroup Entry
3232  */
3233 EAPI void
3234 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3235 {
3236    ELM_CHECK_WIDTYPE(obj, widtype);
3237    Widget_Data *wd = elm_widget_data_get(obj);
3238    if (!wd) return;
3239    
3240    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3241    if (!ic) return;
3242
3243    wd->input_panel_layout = layout;
3244    
3245    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3246 }
3247
3248 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/