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