[Merge with upstream] core files are merged
[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 Eina_Bool *_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), void *data)
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                  replocater++;
1741
1742                 while (*replocater && *replocater != ' ' && *replocater != '>')
1743                   replocater++;
1744
1745                if (replocater-curlocater > strlen(key)+1)
1746                  {
1747                    replocater--;
1748                    eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1749                  }
1750                else
1751                  insertflag = 1;
1752              }
1753            else
1754              {
1755                insertflag = 1;
1756              }
1757            eina_strbuf_reset(repbuf);
1758          }
1759        else
1760          {
1761            insertflag = 1;
1762          }
1763      }
1764
1765    if (repbuf == NULL) repbuf = eina_strbuf_new();
1766    if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1767
1768    if (insertflag)
1769      {
1770        eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1771        eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1772      }
1773    else
1774      {
1775         if (deleteflag)
1776           {
1777             eina_strbuf_prepend(diffbuf, "<");
1778             eina_strbuf_append(diffbuf, ">");
1779             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1780           }
1781         else
1782           {
1783             eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1784             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1785           }
1786      }
1787
1788    if (repbuf) eina_strbuf_free(repbuf);
1789    if (diffbuf) eina_strbuf_free(diffbuf);
1790
1791    return 0;
1792 }
1793
1794 static int
1795 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1796 {
1797    Eina_Strbuf *sharebuf = NULL;
1798
1799    sharebuf = eina_strbuf_new();
1800    eina_strbuf_append(sharebuf, *srcstring);
1801    _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1802    eina_stringshare_del(*srcstring);
1803    *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1804    eina_strbuf_free(sharebuf);
1805
1806    return 0;
1807 }
1808
1809 static int
1810 _is_width_over(Evas_Object *obj)
1811 {
1812    Evas_Coord x, y, w, h;
1813    Evas_Coord vx, vy, vw, vh;
1814    Widget_Data *wd = elm_widget_data_get(obj);
1815
1816    if (!wd) return 0;
1817
1818    edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1819
1820    evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1821
1822    if (x >= 0 && y >= 0)
1823            return 0;
1824
1825    if (4 < wd->wrap_w && w > wd->wrap_w)
1826            return 1;
1827
1828    return 0;
1829 }
1830
1831 static void
1832 _reverse_ellipsis_entry(Evas_Object *obj)
1833 {
1834    Widget_Data *wd = elm_widget_data_get(obj);
1835    int cur_fontsize = 0;
1836    Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1837    char *kvalue = NULL;
1838    const char *minfont, *deffont, *maxfont;
1839    const char *ellipsis_string = "...";
1840    int minfontsize, maxfontsize, minshowcount;
1841
1842    minshowcount = strlen(ellipsis_string) + 1;
1843    minfont = edje_object_data_get(wd->ent, "min_font_size");
1844    if (minfont) minfontsize = atoi(minfont);
1845    else minfontsize = 1;
1846    maxfont = edje_object_data_get(wd->ent, "max_font_size");
1847    if (maxfont) maxfontsize = atoi(maxfont);
1848    else maxfontsize = 1;
1849    deffont = edje_object_data_get(wd->ent, "default_font_size");
1850    if (deffont) cur_fontsize = atoi(deffont);
1851    else cur_fontsize = 1;
1852    if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1853    if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1854
1855    if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1856      {
1857        if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1858      }
1859
1860    txtbuf = eina_strbuf_new();
1861    eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1862
1863    if (cur_fontsize >= atoi(deffont))
1864      {
1865        if (txtbuf) eina_strbuf_free(txtbuf);
1866        return;
1867      }
1868
1869    if (_is_width_over(obj) != 1)
1870      {
1871        int rev_fontsize = cur_fontsize;
1872
1873        do {
1874            rev_fontsize++;
1875            if (rev_fontsize > atoi(deffont))
1876              break;
1877
1878            if (fontbuf != NULL)
1879              {
1880                eina_strbuf_free(fontbuf);
1881                fontbuf = NULL;
1882              }
1883            fontbuf = eina_strbuf_new();
1884            eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1885            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1886            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1887
1888            eina_strbuf_free(fontbuf);
1889            fontbuf = NULL;
1890          } while (_is_width_over(obj) != 1);
1891
1892        while (_is_width_over(obj))
1893          {
1894            rev_fontsize--;
1895            if (rev_fontsize < atoi(deffont))
1896              break;
1897
1898            if (fontbuf != NULL)
1899              {
1900                eina_strbuf_free(fontbuf);
1901                fontbuf = NULL;
1902              }
1903            fontbuf = eina_strbuf_new();
1904            eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1905            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1906            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1907            eina_strbuf_free(fontbuf);
1908            fontbuf = NULL;
1909          }
1910      }
1911
1912    if (txtbuf) eina_strbuf_free(txtbuf);
1913    wd->changed = 1;
1914    _sizing_eval(obj);
1915 }
1916
1917 static void
1918 _ellipsis_entry_to_width(Evas_Object *obj)
1919 {
1920    Widget_Data *wd = elm_widget_data_get(obj);
1921    int cur_fontsize = 0, len, jumpcount;
1922    Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1923    char *kvalue = NULL;
1924    const char *minfont, *deffont, *maxfont;
1925    const char *ellipsis_string = "...";
1926    int minfontsize, maxfontsize, minshowcount;
1927    int i, tagend, cur_len;
1928    char *cur_str;
1929
1930    minshowcount = strlen(ellipsis_string) + 1;
1931    minfont = edje_object_data_get(wd->ent, "min_font_size");
1932    if (minfont) minfontsize = atoi(minfont);
1933    else minfontsize = 1;
1934    maxfont = edje_object_data_get(wd->ent, "max_font_size");
1935    if (maxfont) maxfontsize = atoi(maxfont);
1936    else maxfontsize = 1;
1937    deffont = edje_object_data_get(wd->ent, "default_font_size");
1938    if (deffont) cur_fontsize = atoi(deffont);
1939    else cur_fontsize = 1;
1940    if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1941    if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1942
1943    if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1944      {
1945        if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1946      }
1947
1948    txtbuf = eina_strbuf_new();
1949    eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1950
1951    while (_is_width_over(obj))
1952      {
1953        if (wd->ellipsis_threshold == 0)
1954          wd->ellipsis_threshold = _entry_length_get(obj);
1955        if (cur_fontsize > minfontsize)
1956          {
1957            cur_fontsize--;
1958            if (fontbuf != NULL)
1959              {
1960                eina_strbuf_free(fontbuf);
1961                fontbuf = NULL;
1962              }
1963            fontbuf = eina_strbuf_new();
1964            eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1965            _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1966            edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1967            eina_strbuf_free(fontbuf);
1968            fontbuf = NULL;
1969                    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1970          }
1971        else
1972          {
1973            len = _entry_length_get(obj);
1974            cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1975            cur_len = strlen(cur_str);
1976            tagend = 0;
1977            for (i = 0; i < len; i++)
1978              {
1979                if(cur_str[i] == '>' && cur_str[i+1] != '\0' &&
1980                   cur_str[i+1] != '<')
1981                  {
1982                    tagend = i;
1983                    break;
1984                  }
1985              }
1986            jumpcount = 0;
1987            while (jumpcount < len-strlen(ellipsis_string))
1988              {
1989                cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1990
1991                if (txtbuf != NULL)
1992                  {
1993                    eina_strbuf_free(txtbuf);
1994                    txtbuf = NULL;
1995                  }
1996                txtbuf = eina_strbuf_new();
1997                eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1998                eina_strbuf_append(txtbuf, ellipsis_string);
1999                eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
2000                edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
2001                edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2002
2003                if (_is_width_over(obj))
2004                  jumpcount++;
2005                else
2006                  break;
2007              }
2008          }
2009      }
2010
2011    if (txtbuf) eina_strbuf_free(txtbuf);
2012    wd->changed = 1;
2013    _sizing_eval(obj);
2014 }
2015
2016 static Eina_Bool *_textinput_control_function(void *data,void *input_data)
2017 {
2018    /* calculate character count */
2019    Evas_Object *entry = (Evas_Object *)data;
2020    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
2021    char buf[10]="\0";
2022    size_t byte_len;
2023    size_t insert_text_len=0;
2024    char *text = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2025    char *insert_text;
2026    size_t remain_bytes;
2027    if (text != NULL)
2028      {
2029         byte_len = strlen(text); /* no of bytes */
2030         remain_bytes = wd->max_no_of_bytes - byte_len;
2031         sprintf(buf,"%d",remain_bytes);
2032         //edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
2033         if (input_data)
2034           {
2035              insert_text =  (char *)input_data;
2036              insert_text_len = strlen(insert_text);
2037              if (remain_bytes < insert_text_len)
2038                {
2039                   evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2040                   return EINA_TRUE;
2041                }
2042              if (byte_len >= wd->max_no_of_bytes)
2043                {
2044                   evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2045                   return EINA_TRUE;
2046                }
2047           }
2048      }
2049    return EINA_FALSE;
2050 }
2051
2052 /**
2053  * This adds an entry to @p parent object.
2054  *
2055  * @param parent The parent object
2056  * @return The new object or NULL if it cannot be created
2057  *
2058  * @ingroup Entry
2059  */
2060 EAPI Evas_Object *
2061 elm_entry_add(Evas_Object *parent)
2062 {
2063    Evas_Object *obj, *top;
2064    Evas *e;
2065    Widget_Data *wd;
2066
2067    wd = ELM_NEW(Widget_Data);
2068    e = evas_object_evas_get(parent);
2069    wd->bgcolor = EINA_FALSE;
2070    wd->bg = evas_object_rectangle_add(e);
2071    evas_object_color_set(wd->bg, 0, 0, 0, 0);
2072    obj = elm_widget_add(e);
2073    ELM_SET_WIDTYPE(widtype, "entry");
2074    elm_widget_type_set(obj, "entry");
2075    elm_widget_sub_object_add(parent, obj);
2076    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2077    elm_widget_data_set(obj, wd);
2078    elm_widget_del_hook_set(obj, _del_hook);
2079    elm_widget_theme_hook_set(obj, _theme_hook);
2080    elm_widget_disable_hook_set(obj, _disable_hook);
2081    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2082    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2083    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2084    elm_widget_can_focus_set(obj, EINA_TRUE);
2085
2086    wd->linewrap     = EINA_TRUE;
2087    wd->ellipsis     = EINA_FALSE;
2088    wd->char_linewrap= EINA_FALSE;
2089    wd->editable     = EINA_TRUE;
2090    wd->disabled     = EINA_FALSE;
2091    wd->context_menu = EINA_TRUE;
2092    wd->autoperiod   = EINA_TRUE;
2093
2094    wd->ellipsis_threshold = 0;
2095
2096    wd->ent = edje_object_add(e);
2097    edje_object_item_provider_set(wd->ent, _get_item, obj);
2098    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2099    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2100    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2101                                   _mouse_down, obj);
2102    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2103                                   _mouse_up, obj);
2104    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2105                                   _mouse_move, obj);
2106
2107    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2108    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2109                                    _signal_entry_changed, obj);
2110    edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2111                                    _signal_handler_move_start, obj);
2112    edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2113                                    _signal_handler_move_end, obj);
2114    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2115                                    _signal_selection_start, obj);
2116    edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2117                                    _signal_selection_end, obj);
2118    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2119                                    _signal_selection_changed, obj);
2120    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2121                                    _signal_selection_cleared, obj);
2122    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2123                                    _signal_entry_paste_request, obj);
2124    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2125                                    _signal_entry_copy_notify, obj);
2126    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2127                                    _signal_entry_cut_notify, obj);
2128    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2129                                    _signal_cursor_changed, obj);
2130    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2131                                    _signal_anchor_down, obj);
2132    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2133                                    _signal_anchor_up, obj);
2134    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2135                                    _signal_anchor_move, obj);
2136    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2137                                    _signal_anchor_in, obj);
2138    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2139                                    _signal_anchor_out, obj);
2140    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2141                                    _signal_key_enter, obj);
2142    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2143                                    _signal_mouse_down, obj);
2144    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2145                                    _signal_mouse_clicked, obj);
2146    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2147                                    _signal_mouse_double, obj);
2148    edje_object_part_text_set(wd->ent, "elm.text", "");
2149    elm_widget_resize_object_set(obj, wd->ent);
2150    _sizing_eval(obj);
2151
2152    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2153
2154 #ifdef HAVE_ELEMENTARY_X
2155    top = elm_widget_top_get(obj);
2156    if ((top) && (elm_win_xwindow_get(top)))
2157      {
2158         wd->sel_notify_handler =
2159           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2160                                   _event_selection_notify, obj);
2161         wd->sel_clear_handler =
2162           ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2163                                   _event_selection_clear, obj);
2164      }
2165
2166    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2167 #endif
2168
2169    entries = eina_list_prepend(entries, obj);
2170
2171    // module - find module for entry
2172    wd->api = _module(obj);
2173    // if found - hook in
2174    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2175
2176    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2177    // TODO: and save some bytes, making descriptions per-class and not instance!
2178    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2179    return obj;
2180 }
2181
2182 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2183 {
2184    ELM_CHECK_WIDTYPE(obj, widtype);
2185    Widget_Data *wd = elm_widget_data_get(obj);
2186    if (!wd) return;
2187    ext_mod->cancel = _cancel;
2188    ext_mod->copy = _copy;
2189    ext_mod->cut = _cut;
2190    ext_mod->paste = _paste;
2191    ext_mod->select = _select;
2192    ext_mod->selectall = _selectall;
2193    ext_mod->ent = wd->ent;
2194    ext_mod->items = wd->items;
2195    ext_mod->longpress_timer = wd->longpress_timer;
2196    ext_mod->editable = wd->editable;
2197    ext_mod->have_selection = wd->have_selection;
2198    ext_mod->password = wd->password;
2199    ext_mod->selmode = wd->selmode;
2200    ext_mod->cnpinit = _cnpinit;
2201    ext_mod->context_menu = wd->context_menu;
2202 }
2203
2204 /**
2205  * This sets the entry object not to line wrap.  All input will
2206  * be on a single line, and the entry box will extend with user input.
2207  *
2208  * @param obj The entry object
2209  * @param single_line If true, the text in the entry
2210  * will be on a single line.
2211  *
2212  * @ingroup Entry
2213  */
2214 EAPI void
2215 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2216 {
2217    ELM_CHECK_WIDTYPE(obj, widtype);
2218    Widget_Data *wd = elm_widget_data_get(obj);
2219    const char *t;
2220    Ecore_IMF_Context *ic;
2221    if (!wd) return;
2222    if (wd->single_line == single_line) return;
2223    wd->single_line = single_line;
2224    wd->linewrap = EINA_FALSE;
2225    wd->char_linewrap = EINA_FALSE;
2226    t = eina_stringshare_add(elm_entry_entry_get(obj));
2227    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2228    elm_entry_entry_set(obj, t);
2229    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2230    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2231    ic = elm_entry_imf_context_get(obj);
2232    if (ic)
2233      {
2234         ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2235      }
2236
2237    eina_stringshare_del(t);
2238    _sizing_eval(obj);
2239 }
2240
2241 /**
2242  * This returns true if the entry has been set to single line mode.
2243  * See also elm_entry_single_line_set().
2244  *
2245  * @param obj The entry object
2246  * @return single_line If true, the text in the entry is set to display
2247  * on a single line.
2248  *
2249  * @ingroup Entry
2250  */
2251 EAPI Eina_Bool
2252 elm_entry_single_line_get(const Evas_Object *obj)
2253 {
2254    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2255    Widget_Data *wd = elm_widget_data_get(obj);
2256    if (!wd) return EINA_FALSE;
2257    return wd->single_line;
2258 }
2259
2260 /**
2261  * This set's the maximum bytes that can be added in entry.
2262  *
2263  * @param obj The entry object
2264  * @param max_no_of_bytes Maximum number of bytes entry can have.
2265  * 
2266  * @ingroup Entry
2267  */
2268 EAPI void
2269 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2270 {
2271    Widget_Data *wd = elm_widget_data_get(obj);
2272
2273    wd->max_no_of_bytes = max_no_of_bytes;
2274    edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
2275    edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2276 }
2277
2278
2279 /**
2280  * This sets the entry object to password mode.  All text entered
2281  * and/or displayed within the widget will be replaced with asterisks (*).
2282  *
2283  * @param obj The entry object
2284  * @param password If true, password mode is enabled.
2285  *
2286  * @ingroup Entry
2287  */
2288 EAPI void
2289 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2290 {
2291    ELM_CHECK_WIDTYPE(obj, widtype);
2292    Widget_Data *wd = elm_widget_data_get(obj);
2293    Ecore_IMF_Context *ic;
2294    const char *t;
2295    if (!wd) return;
2296    if (wd->password == password) return;
2297    wd->password = password;
2298    wd->single_line = EINA_TRUE;
2299    wd->linewrap = EINA_FALSE;
2300    wd->char_linewrap = EINA_FALSE;
2301    if (_elm_config->password_show_last_character)
2302      wd->show_last_character = EINA_TRUE;
2303    t = eina_stringshare_add(elm_entry_entry_get(obj));
2304    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2305    elm_entry_entry_set(obj, t);
2306
2307    if (password)
2308      {
2309         if (wd->autoperiod)
2310            elm_entry_autoperiod_set(obj, EINA_FALSE);
2311
2312         if (wd->autocapital)
2313            elm_entry_autocapitalization_set(obj, EINA_FALSE);
2314      }
2315
2316    ic = elm_entry_imf_context_get(obj);
2317    if (ic)
2318       ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2319
2320    eina_stringshare_del(t);
2321    _sizing_eval(obj);
2322 }
2323
2324 /**
2325  * This set's the entry in password mode with out masking the last character entered by user,
2326  * and later masking the character after 2 seconds.
2327  
2328  * @param obj The entry object
2329  * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character" 
2330  * 0 for default).
2331  *
2332  * @ingroup Entry
2333  */
2334 EAPI void
2335 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2336 {
2337    Widget_Data *wd = elm_widget_data_get(obj);
2338    const char *t;
2339    if (!wd) return;
2340    if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character))  return;
2341    wd->show_last_character = show_last_character;
2342    wd->password = show_last_character;
2343    wd->single_line = EINA_TRUE;
2344    wd->linewrap = EINA_FALSE;
2345    wd->char_linewrap = EINA_FALSE;
2346    t = eina_stringshare_add(elm_entry_entry_get(obj));
2347    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2348    elm_entry_entry_set(obj, t);
2349    eina_stringshare_del(t);
2350    _sizing_eval(obj);
2351 }
2352
2353 /**
2354  * This returns whether password mode is enabled.
2355  * See also elm_entry_password_set().
2356  *
2357  * @param obj The entry object
2358  * @return If true, the entry is set to display all characters
2359  * as asterisks (*).
2360  *
2361  * @ingroup Entry
2362  */
2363 EAPI Eina_Bool
2364 elm_entry_password_get(const Evas_Object *obj)
2365 {
2366    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2367    Widget_Data *wd = elm_widget_data_get(obj);
2368    if (!wd) return EINA_FALSE;
2369    return wd->password;
2370 }
2371
2372 /**
2373  * This sets the text displayed within the entry to @p entry.
2374  *
2375  * @param obj The entry object
2376  * @param entry The text to be displayed
2377  *
2378  * @ingroup Entry
2379  */
2380 EAPI void
2381 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2382 {
2383    ELM_CHECK_WIDTYPE(obj, widtype);
2384    Widget_Data *wd = elm_widget_data_get(obj);
2385    if (!wd) return;
2386    if (!entry) entry = "";
2387    if(wd->max_no_of_bytes)
2388      {
2389        int len = strlen(entry);
2390        if(len > wd->max_no_of_bytes)
2391        {
2392          ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2393          return;
2394        }
2395      }
2396    edje_object_part_text_set(wd->ent, "elm.text", entry);
2397    if (wd->text) eina_stringshare_del(wd->text);
2398    wd->text = NULL;
2399    wd->changed = EINA_TRUE;
2400    _sizing_eval(obj);
2401 }
2402
2403 /**
2404  * This returns the text currently shown in object @p entry.
2405  * See also elm_entry_entry_set().
2406  *
2407  * @param obj The entry object
2408  * @return The currently displayed text or NULL on failure
2409  *
2410  * @ingroup Entry
2411  */
2412 EAPI const char *
2413 elm_entry_entry_get(const Evas_Object *obj)
2414 {
2415    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2416    Widget_Data *wd = elm_widget_data_get(obj);
2417    const char *text;
2418    if (!wd) return NULL;
2419
2420    if ((wd->text)&&(wd->password))
2421    return elm_entry_markup_to_utf8(wd->text);
2422
2423    if (wd->text) return wd->text;
2424    text = edje_object_part_text_get(wd->ent, "elm.text");
2425    if (!text)
2426      {
2427         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2428         return NULL;
2429      }
2430    eina_stringshare_replace(&wd->text, text);
2431    if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2432    return wd->text;
2433 }
2434
2435 /**
2436  * This returns all selected text within the entry.
2437  *
2438  * @param obj The entry object
2439  * @return The selected text within the entry or NULL on failure
2440  *
2441  * @ingroup Entry
2442  */
2443 EAPI const char *
2444 elm_entry_selection_get(const Evas_Object *obj)
2445 {
2446    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2447    Widget_Data *wd = elm_widget_data_get(obj);
2448    if (!wd) return NULL;
2449    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2450 }
2451
2452 /**
2453  * This inserts text in @p entry at the beginning of the entry
2454  * object.
2455  *
2456  * @param obj The entry object
2457  * @param entry The text to insert
2458  *
2459  * @ingroup Entry
2460  */
2461 EAPI void
2462 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2463 {
2464    ELM_CHECK_WIDTYPE(obj, widtype);
2465    Widget_Data *wd = elm_widget_data_get(obj);
2466    if (!wd) return;
2467    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2468    // start for cbhm
2469    if (cnpwidgetdata == obj)
2470       ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2471    // end for cbhm
2472    wd->changed = EINA_TRUE;
2473    _sizing_eval(obj);
2474 }
2475
2476 /**
2477  * This enables word line wrapping in the entry object.  It is the opposite
2478  * of elm_entry_single_line_set().  Additionally, setting this disables
2479  * character line wrapping.
2480  * See also elm_entry_line_char_wrap_set().
2481  *
2482  * @param obj The entry object
2483  * @param wrap If true, the entry will be wrapped once it reaches the end
2484  * of the object. Wrapping will occur at the end of the word before the end of the
2485  * object.
2486  *
2487  * @ingroup Entry
2488  */
2489 EAPI void
2490 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2491 {
2492    ELM_CHECK_WIDTYPE(obj, widtype);
2493    Widget_Data *wd = elm_widget_data_get(obj);
2494    const char *t;
2495    if (!wd) return;
2496    if (wd->linewrap == wrap) return;
2497    wd->linewrap = wrap;
2498    if(wd->linewrap)
2499        wd->char_linewrap = EINA_FALSE;
2500    t = eina_stringshare_add(elm_entry_entry_get(obj));
2501    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2502    elm_entry_entry_set(obj, t);
2503    eina_stringshare_del(t);
2504    _sizing_eval(obj);
2505 }
2506
2507 /**
2508  * Set wrap width of the entry
2509  *
2510  * @param obj The entry object
2511  * @param w The wrap width in pixels at a minimum where words need to wrap
2512  * @ingroup Entry
2513  */
2514 EAPI void
2515 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2516 {
2517    Widget_Data *wd = elm_widget_data_get(obj);
2518    if (wd->wrap_w == w) return;
2519    wd->wrap_w = w;
2520    _sizing_eval(obj);
2521 }
2522
2523 /**
2524  * get wrap width of the entry
2525  *
2526  * @param obj The entry object
2527  * @return The wrap width in pixels at a minimum where words need to wrap
2528  * @ingroup Entry
2529  */
2530 EAPI Evas_Coord
2531 elm_entry_wrap_width_get(const Evas_Object *obj)
2532 {
2533    Widget_Data *wd = elm_widget_data_get(obj);
2534    return wd->wrap_w;
2535 }
2536
2537 /**
2538  * This enables character line wrapping in the entry object.  It is the opposite
2539  * of elm_entry_single_line_set().  Additionally, setting this disables
2540  * word line wrapping.
2541  * See also elm_entry_line_wrap_set().
2542  *
2543  * @param obj The entry object
2544  * @param wrap If true, the entry will be wrapped once it reaches the end
2545  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2546  *
2547  * @ingroup Entry
2548  */
2549 EAPI void
2550 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2551 {
2552    ELM_CHECK_WIDTYPE(obj, widtype);
2553    Widget_Data *wd = elm_widget_data_get(obj);
2554    const char *t;
2555    if (!wd) return;
2556    if (wd->char_linewrap == wrap) return;
2557    wd->char_linewrap = wrap;
2558    if(wd->char_linewrap)
2559        wd->linewrap = EINA_FALSE;
2560    t = eina_stringshare_add(elm_entry_entry_get(obj));
2561    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2562    elm_entry_entry_set(obj, t);
2563    eina_stringshare_del(t);
2564    _sizing_eval(obj);
2565 }
2566
2567 /**
2568  * This sets the editable attribute of the entry.
2569  *
2570  * @param obj The entry object
2571  * @param editable If true, the entry will be editable by the user.
2572  * If false, it will be set to the disabled state.
2573  *
2574  * @ingroup Entry
2575  */
2576 EAPI void
2577 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2578 {
2579    ELM_CHECK_WIDTYPE(obj, widtype);
2580    Widget_Data *wd = elm_widget_data_get(obj);
2581    const char *t;
2582    if (!wd) return;
2583    if (wd->editable == editable) return;
2584    wd->editable = editable;
2585    t = eina_stringshare_add(elm_entry_entry_get(obj));
2586    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2587    elm_entry_entry_set(obj, t);
2588    eina_stringshare_del(t);
2589    _sizing_eval(obj);
2590
2591 #ifdef HAVE_ELEMENTARY_X
2592    if (editable)
2593       elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2594    else
2595       elm_drop_target_del(obj);
2596 #endif
2597 }
2598
2599 /**
2600  * This gets the editable attribute of the entry.
2601  * See also elm_entry_editable_set().
2602  *
2603  * @param obj The entry object
2604  * @return If true, the entry is editable by the user.
2605  * If false, it is not editable by the user
2606  *
2607  * @ingroup Entry
2608  */
2609 EAPI Eina_Bool
2610 elm_entry_editable_get(const Evas_Object *obj)
2611 {
2612    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2613    Widget_Data *wd = elm_widget_data_get(obj);
2614    if (!wd) return EINA_FALSE;
2615    return wd->editable;
2616 }
2617
2618 /**
2619  * This drops any existing text selection within the entry.
2620  *
2621  * @param obj The entry object
2622  *
2623  * @ingroup Entry
2624  */
2625 EAPI void
2626 elm_entry_select_none(Evas_Object *obj)
2627 {
2628    ELM_CHECK_WIDTYPE(obj, widtype);
2629    Widget_Data *wd = elm_widget_data_get(obj);
2630    if (!wd) return;
2631    if (wd->selmode)
2632      {
2633         wd->selmode = EINA_FALSE;
2634         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2635         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2636      }
2637    wd->have_selection = EINA_FALSE;
2638    edje_object_part_text_select_none(wd->ent, "elm.text");
2639 }
2640
2641 /**
2642  * This selects all text within the entry.
2643  *
2644  * @param obj The entry object
2645  *
2646  * @ingroup Entry
2647  */
2648 EAPI void
2649 elm_entry_select_all(Evas_Object *obj)
2650 {
2651    ELM_CHECK_WIDTYPE(obj, widtype);
2652    Widget_Data *wd = elm_widget_data_get(obj);
2653    if (!wd) return;
2654    if (wd->selmode)
2655      {
2656         wd->selmode = EINA_FALSE;
2657         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2658         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2659      }
2660    wd->have_selection = EINA_TRUE;
2661    edje_object_part_text_select_all(wd->ent, "elm.text");
2662 }
2663
2664 /**
2665  * This moves the cursor one place to the right within the entry.
2666  *
2667  * @param obj The entry object
2668  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2669  *
2670  * @ingroup Entry
2671  */
2672 EAPI Eina_Bool
2673 elm_entry_cursor_next(Evas_Object *obj)
2674 {
2675    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2676    Widget_Data *wd = elm_widget_data_get(obj);
2677    if (!wd) return EINA_FALSE;
2678    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2679 }
2680
2681 /**
2682  * This moves the cursor one place to the left within the entry.
2683  *
2684  * @param obj The entry object
2685  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2686  *
2687  * @ingroup Entry
2688  */
2689 EAPI Eina_Bool
2690 elm_entry_cursor_prev(Evas_Object *obj)
2691 {
2692    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2693    Widget_Data *wd = elm_widget_data_get(obj);
2694    if (!wd) return EINA_FALSE;
2695    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2696 }
2697
2698 /**
2699  * This moves the cursor one line up within the entry.
2700  *
2701  * @param obj The entry object
2702  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2703  *
2704  * @ingroup Entry
2705  */
2706 EAPI Eina_Bool
2707 elm_entry_cursor_up(Evas_Object *obj)
2708 {
2709    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2710    Widget_Data *wd = elm_widget_data_get(obj);
2711    if (!wd) return EINA_FALSE;
2712    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2713 }
2714
2715 /**
2716  * This moves the cursor one line down within the entry.
2717  *
2718  * @param obj The entry object
2719  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2720  *
2721  * @ingroup Entry
2722  */
2723 EAPI Eina_Bool
2724 elm_entry_cursor_down(Evas_Object *obj)
2725 {
2726    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2727    Widget_Data *wd = elm_widget_data_get(obj);
2728    if (!wd) return EINA_FALSE;
2729    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2730 }
2731
2732 /**
2733  * This moves the cursor to the beginning of the entry.
2734  *
2735  * @param obj The entry object
2736  *
2737  * @ingroup Entry
2738  */
2739 EAPI void
2740 elm_entry_cursor_begin_set(Evas_Object *obj)
2741 {
2742    ELM_CHECK_WIDTYPE(obj, widtype);
2743    Widget_Data *wd = elm_widget_data_get(obj);
2744    if (!wd) return;
2745    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2746 }
2747
2748 /**
2749  * This moves the cursor to the end of the entry.
2750  *
2751  * @param obj The entry object
2752  *
2753  * @ingroup Entry
2754  */
2755 EAPI void
2756 elm_entry_cursor_end_set(Evas_Object *obj)
2757 {
2758    ELM_CHECK_WIDTYPE(obj, widtype);
2759    Widget_Data *wd = elm_widget_data_get(obj);
2760    if (!wd) return;
2761    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2762 }
2763
2764 /**
2765  * This moves the cursor to the beginning of the current line.
2766  *
2767  * @param obj The entry object
2768  *
2769  * @ingroup Entry
2770  */
2771 EAPI void
2772 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2773 {
2774    ELM_CHECK_WIDTYPE(obj, widtype);
2775    Widget_Data *wd = elm_widget_data_get(obj);
2776    if (!wd) return;
2777    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2778 }
2779
2780 /**
2781  * This moves the cursor to the end of the current line.
2782  *
2783  * @param obj The entry object
2784  *
2785  * @ingroup Entry
2786  */
2787 EAPI void
2788 elm_entry_cursor_line_end_set(Evas_Object *obj)
2789 {
2790    ELM_CHECK_WIDTYPE(obj, widtype);
2791    Widget_Data *wd = elm_widget_data_get(obj);
2792    if (!wd) return;
2793    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2794 }
2795
2796 /**
2797  * This begins a selection within the entry as though
2798  * the user were holding down the mouse button to make a selection.
2799  *
2800  * @param obj The entry object
2801  *
2802  * @ingroup Entry
2803  */
2804 EAPI void
2805 elm_entry_cursor_selection_begin(Evas_Object *obj)
2806 {
2807    ELM_CHECK_WIDTYPE(obj, widtype);
2808    Widget_Data *wd = elm_widget_data_get(obj);
2809    if (!wd) return;
2810    edje_object_part_text_select_begin(wd->ent, "elm.text");
2811 }
2812
2813 /**
2814  * This ends a selection within the entry as though
2815  * the user had just released the mouse button while making a selection.
2816  *
2817  * @param obj The entry object
2818  *
2819  * @ingroup Entry
2820  */
2821 EAPI void
2822 elm_entry_cursor_selection_end(Evas_Object *obj)
2823 {
2824    ELM_CHECK_WIDTYPE(obj, widtype);
2825    Widget_Data *wd = elm_widget_data_get(obj);
2826    if (!wd) return;
2827    edje_object_part_text_select_extend(wd->ent, "elm.text");
2828 }
2829
2830 /**
2831  * TODO: fill this in
2832  *
2833  * @param obj The entry object
2834  * @return TODO: fill this in
2835  *
2836  * @ingroup Entry
2837  */
2838 EAPI Eina_Bool
2839 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2840 {
2841    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2842    Widget_Data *wd = elm_widget_data_get(obj);
2843    if (!wd) return EINA_FALSE;
2844    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2845 }
2846
2847 /**
2848  * This returns whether the cursor is visible.
2849  *
2850  * @param obj The entry object
2851  * @return If true, the cursor is visible.
2852  *
2853  * @ingroup Entry
2854  */
2855 EAPI Eina_Bool
2856 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2857 {
2858    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2859    Widget_Data *wd = elm_widget_data_get(obj);
2860    if (!wd) return EINA_FALSE;
2861    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2862 }
2863
2864 /**
2865  * TODO: fill this in
2866  *
2867  * @param obj The entry object
2868  * @return TODO: fill this in
2869  *
2870  * @ingroup Entry
2871  */
2872 EAPI const char *
2873 elm_entry_cursor_content_get(const Evas_Object *obj)
2874 {
2875    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2876    Widget_Data *wd = elm_widget_data_get(obj);
2877    if (!wd) return NULL;
2878    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2879 }
2880
2881 /**
2882  * This executes a "cut" action on the selected text in the entry.
2883  *
2884  * @param obj The entry object
2885  *
2886  * @ingroup Entry
2887  */
2888 EAPI void
2889 elm_entry_selection_cut(Evas_Object *obj)
2890 {
2891    ELM_CHECK_WIDTYPE(obj, widtype);
2892    Widget_Data *wd = elm_widget_data_get(obj);
2893    if (!wd) return;
2894    _cut(obj, NULL, NULL);
2895 }
2896
2897 /**
2898  * This executes a "copy" action on the selected text in the entry.
2899  *
2900  * @param obj The entry object
2901  *
2902  * @ingroup Entry
2903  */
2904 EAPI void
2905 elm_entry_selection_copy(Evas_Object *obj)
2906 {
2907    ELM_CHECK_WIDTYPE(obj, widtype);
2908    Widget_Data *wd = elm_widget_data_get(obj);
2909    if (!wd) return;
2910    _copy(obj, NULL, NULL);
2911 }
2912
2913 /**
2914  * This executes a "paste" action in the entry.
2915  *
2916  * @param obj The entry object
2917  *
2918  * @ingroup Entry
2919  */
2920 EAPI void
2921 elm_entry_selection_paste(Evas_Object *obj)
2922 {
2923    ELM_CHECK_WIDTYPE(obj, widtype);
2924    Widget_Data *wd = elm_widget_data_get(obj);
2925    if (!wd) return;
2926    _paste(obj, NULL, NULL);
2927 }
2928
2929 /**
2930  * This clears and frees the items in a entry's contextual (right click) menu.
2931  *
2932  * @param obj The entry object
2933  *
2934  * @ingroup Entry
2935  */
2936 EAPI void
2937 elm_entry_context_menu_clear(Evas_Object *obj)
2938 {
2939    ELM_CHECK_WIDTYPE(obj, widtype);
2940    Widget_Data *wd = elm_widget_data_get(obj);
2941    Elm_Entry_Context_Menu_Item *it;
2942    if (!wd) return;
2943    EINA_LIST_FREE(wd->items, it)
2944      {
2945         eina_stringshare_del(it->label);
2946         eina_stringshare_del(it->icon_file);
2947         eina_stringshare_del(it->icon_group);
2948         free(it);
2949      }
2950 }
2951
2952 /**
2953  * This adds an item to the entry's contextual menu.
2954  *
2955  * @param obj The entry object
2956  * @param label The item's text label
2957  * @param icon_file The item's icon file
2958  * @param icon_type The item's icon type
2959  * @param func The callback to execute when the item is clicked
2960  * @param data The data to associate with the item for related functions
2961  *
2962  * @ingroup Entry
2963  */
2964 EAPI void
2965 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)
2966 {
2967    ELM_CHECK_WIDTYPE(obj, widtype);
2968    Widget_Data *wd = elm_widget_data_get(obj);
2969    Elm_Entry_Context_Menu_Item *it;
2970    if (!wd) return;
2971    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2972    if (!it) return;
2973    wd->items = eina_list_append(wd->items, it);
2974    it->obj = obj;
2975    it->label = eina_stringshare_add(label);
2976    it->icon_file = eina_stringshare_add(icon_file);
2977    it->icon_type = icon_type;
2978    it->func = func;
2979    it->data = (void *)data;
2980 }
2981
2982 /**
2983  * This disables the entry's contextual (right click) menu.
2984  *
2985  * @param obj The entry object
2986  * @param disabled If true, the menu is disabled
2987  *
2988  * @ingroup Entry
2989  */
2990 EAPI void
2991 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2992 {
2993    ELM_CHECK_WIDTYPE(obj, widtype);
2994    Widget_Data *wd = elm_widget_data_get(obj);
2995    if (!wd) return;
2996    if (wd->context_menu == !disabled) return;
2997    wd->context_menu = !disabled;
2998 }
2999
3000 /**
3001  * This returns whether the entry's contextual (right click) menu is disabled.
3002  *
3003  * @param obj The entry object
3004  * @return If true, the menu is disabled
3005  *
3006  * @ingroup Entry
3007  */
3008 EAPI Eina_Bool
3009 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3010 {
3011    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3012    Widget_Data *wd = elm_widget_data_get(obj);
3013    if (!wd) return EINA_FALSE;
3014    return !wd->context_menu;
3015 }
3016
3017 /**
3018  * This appends a custom item provider to the list for that entry
3019  *
3020  * This appends the given callback. The list is walked from beginning to end
3021  * with each function called given the item href string in the text. If the
3022  * function returns an object handle other than NULL (it should create an
3023  * and object to do this), then this object is used to replace that item. If
3024  * not the next provider is called until one provides an item object, or the
3025  * default provider in entry does.
3026  * 
3027  * @param obj The entry object
3028  * @param func The function called to provide the item object
3029  * @param data The data passed to @p func
3030  *
3031  * @ingroup Entry
3032  */
3033 EAPI void
3034 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3035 {
3036    ELM_CHECK_WIDTYPE(obj, widtype);
3037    Widget_Data *wd = elm_widget_data_get(obj);
3038    if (!wd) return;
3039    if (!func) return;
3040    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3041    if (!ip) return;
3042    ip->func = func;
3043    ip->data = data;
3044    wd->item_providers = eina_list_append(wd->item_providers, ip);
3045 }
3046
3047 /**
3048  * This prepends a custom item provider to the list for that entry
3049  *
3050  * This prepends the given callback. See elm_entry_item_provider_append() for
3051  * more information
3052  * 
3053  * @param obj The entry object
3054  * @param func The function called to provide the item object
3055  * @param data The data passed to @p func
3056  *
3057  * @ingroup Entry
3058  */
3059 EAPI void
3060 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3061 {
3062    ELM_CHECK_WIDTYPE(obj, widtype);
3063    Widget_Data *wd = elm_widget_data_get(obj);
3064    if (!wd) return;
3065    if (!func) return;
3066    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3067    if (!ip) return;
3068    ip->func = func;
3069    ip->data = data;
3070    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3071 }
3072
3073 /**
3074  * This removes a custom item provider to the list for that entry
3075  *
3076  * This removes the given callback. See elm_entry_item_provider_append() for
3077  * more information
3078  * 
3079  * @param obj The entry object
3080  * @param func The function called to provide the item object
3081  * @param data The data passed to @p func
3082  *
3083  * @ingroup Entry
3084  */
3085 EAPI void
3086 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3087 {
3088    ELM_CHECK_WIDTYPE(obj, widtype);
3089    Widget_Data *wd = elm_widget_data_get(obj);
3090    Eina_List *l;
3091    Elm_Entry_Item_Provider *ip;
3092    if (!wd) return;
3093    if (!func) return;
3094    EINA_LIST_FOREACH(wd->item_providers, l, ip)
3095      {
3096         if ((ip->func == func) && (ip->data == data))
3097           {
3098              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3099              free(ip);
3100              return;
3101           }
3102      }
3103 }
3104
3105 /**
3106  * This converts a markup (HTML-like) string into UTF-8.
3107  *
3108  * @param s The string (in markup) to be converted
3109  * @return The converted string (in UTF-8)
3110  *
3111  * @ingroup Entry
3112  */
3113 EAPI char *
3114 elm_entry_markup_to_utf8(const char *s)
3115 {
3116    char *ss = _mkup_to_text(s);
3117    if (!ss) ss = strdup("");
3118    return ss;
3119 }
3120
3121 /**
3122  * This converts a UTF-8 string into markup (HTML-like).
3123  *
3124  * @param s The string (in UTF-8) to be converted
3125  * @return The converted string (in markup)
3126  *
3127  * @ingroup Entry
3128  */
3129 EAPI char *
3130 elm_entry_utf8_to_markup(const char *s)
3131 {
3132    char *ss = _text_to_mkup(s);
3133    if (!ss) ss = strdup("");
3134    return ss;
3135 }
3136
3137 /**
3138  * Get the input method context in the entry widget
3139  *
3140  * @param obj The entry object
3141  * @return The input method context
3142  *
3143  * @ingroup Entry
3144  */
3145 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3146 {
3147    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3148    Widget_Data *wd = elm_widget_data_get(obj);
3149    if (!wd || !wd->ent) return NULL;
3150
3151    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3152 }
3153
3154 /**
3155  * Set whether entry should enable the return key on soft keyboard automatically
3156  *
3157  * @param obj The entry object
3158  * @param on If true, entry enables the return key on soft keyboard automatically.
3159  *
3160  * @ingroup Entry
3161  */
3162 EAPI void
3163 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3164 {
3165    ELM_CHECK_WIDTYPE(obj, widtype);
3166    Widget_Data *wd = elm_widget_data_get(obj);
3167    if (!wd) return;
3168
3169    wd->autoreturnkey = on;
3170    _check_enable_returnkey(obj);
3171 }
3172
3173 /**
3174  * Set whether entry should support auto capitalization
3175  *
3176  * @param obj The entry object
3177  * @param on If true, entry suports auto capitalization.
3178  *
3179  * @ingroup Entry
3180  */
3181 EAPI void
3182 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3183 {
3184    ELM_CHECK_WIDTYPE(obj, widtype);
3185    Widget_Data *wd = elm_widget_data_get(obj);
3186    if (!wd) return;
3187
3188    if (wd->password)
3189        wd->autocapital = EINA_FALSE;
3190    else
3191        wd->autocapital = autocap;
3192
3193    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3194        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3195        wd->autocapital = EINA_FALSE;
3196
3197    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3198 }
3199
3200 /**
3201  * Set whether entry should support auto period
3202  *
3203  * @param obj The entry object
3204  * @param on If true, entry suports auto period.
3205  *
3206  * @ingroup Entry
3207  */
3208 EAPI void
3209 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3210 {
3211    ELM_CHECK_WIDTYPE(obj, widtype);
3212    Widget_Data *wd = elm_widget_data_get(obj);
3213    if (!wd) return;
3214
3215    if (wd->password)
3216        wd->autoperiod = EINA_FALSE;
3217    else
3218        wd->autoperiod = autoperiod;
3219
3220    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3221        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3222        wd->autoperiod = EINA_FALSE;
3223
3224    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3225 }
3226
3227 /**
3228  * Set the font size on the entry object
3229  *
3230  * @param obj The entry object
3231  * @param size font size
3232  *
3233  * @ingroup Entry
3234  */
3235 EAPI void
3236 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3237 {
3238    ELM_CHECK_WIDTYPE(obj, widtype);
3239    Widget_Data *wd = elm_widget_data_get(obj);
3240    Eina_Strbuf *fontbuf = NULL;
3241    int removeflag = 0;
3242    const char *t;
3243
3244    if (!wd) return;
3245    t = eina_stringshare_add(elm_entry_entry_get(obj));
3246    fontbuf = eina_strbuf_new();
3247    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3248
3249    if (fontsize == 0) removeflag = 1; // remove fontsize tag
3250
3251    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3252      {
3253        elm_entry_entry_set(obj, t);
3254        wd->changed = 1;
3255        _sizing_eval(obj);
3256      }
3257    eina_strbuf_free(fontbuf);
3258    eina_stringshare_del(t);
3259 }
3260
3261 /**
3262  * Set the text align on the entry object
3263  *
3264  * @param obj The entry object
3265  * @param align align mode
3266  *
3267  * @ingroup Entry
3268  */
3269 EAPI void
3270 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3271 {
3272    ELM_CHECK_WIDTYPE(obj, widtype);
3273    Widget_Data *wd = elm_widget_data_get(obj);
3274    int len;
3275    const char *t;
3276
3277    if (!wd) return;
3278    t = eina_stringshare_add(elm_entry_entry_get(obj));
3279    len = strlen(t);
3280    if (len <= 0) return;
3281
3282    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3283      elm_entry_entry_set(obj, t);
3284
3285    wd->changed = 1;
3286    _sizing_eval(obj);
3287    eina_stringshare_del(t);
3288 }
3289
3290 /**
3291  * Set the text color on the entry object
3292  *
3293  * @param obj The entry object
3294  * @param r Red property background color of The entry object 
3295  * @param g Green property background color of The entry object 
3296  * @param b Blue property background color of The entry object 
3297  * @param a Alpha property background alpha of The entry object 
3298  *
3299  * @ingroup Entry
3300  */
3301 EAPI void
3302 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3303 {
3304    ELM_CHECK_WIDTYPE(obj, widtype);
3305    Widget_Data *wd = elm_widget_data_get(obj);
3306    Eina_Strbuf *colorbuf = NULL;
3307    const char *t;
3308    int len;
3309
3310    if (!wd) return;
3311    t = eina_stringshare_add(elm_entry_entry_get(obj));
3312    len = strlen(t);
3313    if (len <= 0) return;
3314    colorbuf = eina_strbuf_new();
3315    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3316
3317    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3318      {
3319        elm_entry_entry_set(obj, t);
3320        wd->changed = 1;
3321        _sizing_eval(obj);
3322      }
3323    eina_strbuf_free(colorbuf);
3324    eina_stringshare_del(t);
3325 }
3326
3327 /**
3328  * Set background color of the entry
3329  *
3330  * @param obj The entry object
3331  * @param r Red property background color of The entry object 
3332  * @param g Green property background color of The entry object 
3333  * @param b Blue property background color of The entry object 
3334  * @param a Alpha property background alpha of The entry object 
3335  * @ingroup Entry
3336  */
3337 EAPI void
3338 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3339 {
3340    ELM_CHECK_WIDTYPE(obj, widtype);
3341    Widget_Data *wd = elm_widget_data_get(obj);
3342    evas_object_color_set(wd->bg, r, g, b, a);
3343
3344    if (wd->bgcolor == EINA_FALSE)
3345      {
3346        wd->bgcolor = 1;
3347        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3348      }
3349 }
3350
3351 /**
3352  * Set the ellipsis behavior of the entry
3353  *
3354  * @param obj The entry object
3355  * @param ellipsis To ellipsis text or not
3356  * @ingroup Entry
3357  */
3358 EAPI void
3359 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3360 {
3361    ELM_CHECK_WIDTYPE(obj, widtype);
3362    Widget_Data *wd = elm_widget_data_get(obj);
3363    if (wd->ellipsis == ellipsis) return;
3364    wd->ellipsis = ellipsis;
3365    wd->changed = 1;
3366    _sizing_eval(obj);
3367 }
3368
3369 /**
3370  * This sets the attribute to show the input panel automatically.
3371  *
3372  * @param obj The entry object
3373  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3374  *
3375  * @ingroup Entry
3376  */
3377 EAPI void
3378 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3379 {
3380    ELM_CHECK_WIDTYPE(obj, widtype);
3381    Widget_Data *wd = elm_widget_data_get(obj);
3382    if (!wd) return;
3383
3384    wd->input_panel_enable = enabled;
3385    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3386 }
3387
3388 /**
3389  * Set the input panel layout of the entry
3390  *
3391  * @param obj The entry object
3392  * @param layout the layout to set
3393  *
3394  * @ingroup Entry
3395  */
3396 EAPI void
3397 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3398 {
3399    ELM_CHECK_WIDTYPE(obj, widtype);
3400    Widget_Data *wd = elm_widget_data_get(obj);
3401    if (!wd) return;
3402
3403    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3404    if (!ic) return;
3405
3406    wd->input_panel_layout = layout;
3407
3408    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3409 }
3410
3411 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/