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