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