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