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