[elm_entry]: maxbyte,reached signal not coming issue resolved in entry.
[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    Evas_Object *entry = (Evas_Object *)data;
1742    Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
1743    char buf[10]="\0";
1744    size_t byte_len;
1745    size_t insert_text_len=0;
1746    char *text = edje_object_part_text_get(wd->ent, "elm.text");
1747    char *insert_text;  
1748    size_t remain_bytes;
1749    if(text!=NULL)
1750      {
1751        byte_len = strlen(text);/*no of bytes*/
1752        remain_bytes = wd->max_no_of_bytes-byte_len;
1753        sprintf(buf,"%d",remain_bytes);
1754        edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
1755        if(input_data)
1756          {
1757            insert_text =  (char *)input_data;
1758            insert_text_len = strlen(insert_text);
1759            if(remain_bytes<insert_text_len)
1760              {
1761                evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1762                return EINA_TRUE;
1763              }
1764            if(byte_len>=wd->max_no_of_bytes)
1765              {
1766                evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
1767                return EINA_TRUE;
1768              }
1769          }
1770      }
1771    return EINA_FALSE;  
1772 }
1773
1774 /**
1775  * This adds an entry to @p parent object.
1776  *
1777  * @param parent The parent object
1778  * @return The new object or NULL if it cannot be created
1779  *
1780  * @ingroup Entry
1781  */
1782 EAPI Evas_Object *
1783 elm_entry_add(Evas_Object *parent)
1784 {
1785    Evas_Object *obj, *top;
1786    Evas *e;
1787    Widget_Data *wd;
1788
1789    wd = ELM_NEW(Widget_Data);
1790    e = evas_object_evas_get(parent);
1791    wd->bgcolor = EINA_FALSE;
1792    wd->bg = evas_object_rectangle_add(e);
1793    evas_object_color_set(wd->bg, 0, 0, 0, 0);
1794    obj = elm_widget_add(e);
1795    ELM_SET_WIDTYPE(widtype, "entry");
1796    elm_widget_type_set(obj, "entry");
1797    elm_widget_sub_object_add(parent, obj);
1798    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1799    elm_widget_data_set(obj, wd);
1800    elm_widget_del_hook_set(obj, _del_hook);
1801    elm_widget_theme_hook_set(obj, _theme_hook);
1802    elm_widget_disable_hook_set(obj, _disable_hook);
1803    elm_widget_can_focus_set(obj, 1);
1804
1805    wd->linewrap     = EINA_TRUE;
1806    wd->ellipsis     = EINA_FALSE;
1807    wd->char_linewrap= EINA_FALSE;
1808    wd->editable     = EINA_TRUE;
1809    wd->disabled     = EINA_FALSE;
1810    wd->context_menu = EINA_TRUE;
1811
1812    wd->ellipsis_threshold = 0;
1813
1814    wd->ent = edje_object_add(e);
1815    edje_object_item_provider_set(wd->ent, _get_item, obj);
1816    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1817    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1818    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1819                                   _mouse_down, obj);
1820    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1821                                   _mouse_up, obj);
1822    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1823                                   _mouse_move, obj);
1824
1825    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1826    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1827                                    _signal_entry_changed, obj);
1828    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1829                                    _signal_selection_start, obj);
1830    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1831                                    _signal_selection_changed, obj);
1832    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1833                                    _signal_selection_cleared, obj);
1834    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1835                                    _signal_entry_paste_request, obj);
1836    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1837                                    _signal_entry_copy_notify, obj);
1838    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1839                                    _signal_entry_cut_notify, obj);
1840    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1841                                    _signal_cursor_changed, obj);
1842    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1843                                    _signal_anchor_down, obj);
1844    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1845                                    _signal_anchor_up, obj);
1846    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1847                                    _signal_anchor_move, obj);
1848    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1849                                    _signal_anchor_in, obj);
1850    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1851                                    _signal_anchor_out, obj);
1852    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1853                                    _signal_key_enter, obj);
1854    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1855                                    _signal_mouse_down, obj);
1856    edje_object_signal_callback_add(wd->ent, "mouse,up,1", "elm.text",
1857                                    _signal_mouse_up, obj);
1858    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1859                                    _signal_mouse_double, obj);
1860    edje_object_part_text_set(wd->ent, "elm.text", "");
1861    elm_widget_resize_object_set(obj, wd->ent);
1862    _sizing_eval(obj);
1863
1864    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
1865
1866 #ifdef HAVE_ELEMENTARY_X
1867    top = elm_widget_top_get(obj);
1868    if ((top) && (elm_win_xwindow_get(top)))
1869      {
1870        wd->sel_notify_handler =
1871          ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1872          _event_selection_notify, obj);
1873        wd->sel_clear_handler =
1874          ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1875          _event_selection_clear, obj);
1876      }
1877 #endif
1878
1879    entries = eina_list_prepend(entries, obj);
1880
1881    // module - find module for entry
1882    wd->api = _module(obj);
1883    // if found - hook in
1884    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1885
1886    // TODO: convert Elementary to subclassing of Evas_Smart_Class
1887    // TODO: and save some bytes, making descriptions per-class and not instance!
1888    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1889    return obj;
1890 }
1891
1892 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
1893 {
1894    ELM_CHECK_WIDTYPE(obj, widtype);
1895    Widget_Data *wd = elm_widget_data_get(obj);
1896    if (!wd) return;
1897    ext_mod->cancel = _cancel;
1898    ext_mod->copy = _copy;
1899    ext_mod->cut = _cut;
1900    ext_mod->paste = _paste;
1901    ext_mod->select = _select;
1902    ext_mod->selectall = NULL; /* to be implemented*/
1903    ext_mod->ent = wd->ent;
1904    ext_mod->items = wd->items;
1905    ext_mod->longpress_timer = wd->longpress_timer;
1906    ext_mod->editable = wd->editable;
1907    ext_mod->have_selection = wd->have_selection;
1908    ext_mod->password = wd->password;
1909    ext_mod->selmode = wd->selmode;
1910 }
1911
1912 /**
1913  * This sets the entry object not to line wrap.  All input will
1914  * be on a single line, and the entry box will extend with user input.
1915  *
1916  * @param obj The entry object
1917  * @param single_line If true, the text in the entry
1918  * will be on a single line.
1919  *
1920  * @ingroup Entry
1921  */
1922 EAPI void
1923 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1924 {
1925    ELM_CHECK_WIDTYPE(obj, widtype);
1926    Widget_Data *wd = elm_widget_data_get(obj);
1927    const char *t;
1928    if (!wd) return;
1929    if (wd->single_line == single_line) return;
1930    wd->single_line = single_line;
1931    wd->linewrap = EINA_FALSE;
1932    wd->char_linewrap = EINA_FALSE;
1933    t = eina_stringshare_add(elm_entry_entry_get(obj));
1934    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1935    elm_entry_entry_set(obj, t);
1936    eina_stringshare_del(t);
1937    _sizing_eval(obj);
1938 }
1939
1940 /**
1941  * This returns true if the entry has been set to single line mode.
1942  * See also elm_entry_single_line_set().
1943  *
1944  * @param obj The entry object
1945  * @return single_line If true, the text in the entry is set to display
1946  * on a single line.
1947  *
1948  * @ingroup Entry
1949  */
1950 EAPI Eina_Bool
1951 elm_entry_single_line_get(const Evas_Object *obj)
1952 {
1953    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1954    Widget_Data *wd = elm_widget_data_get(obj);
1955    if (!wd) return EINA_FALSE;
1956    return wd->single_line;
1957 }
1958
1959 /**
1960  * This set's the maximum bytes that can be added in entry.
1961  *
1962  * @param obj The entry object
1963  * @param max_no_of_bytes Maximum number of bytes entry can have.
1964  * 
1965  * @ingroup Entry
1966  */
1967 EAPI void
1968 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
1969 {
1970    Widget_Data *wd = elm_widget_data_get(obj);
1971
1972    wd->max_no_of_bytes = max_no_of_bytes;
1973    edje_object_signal_emit(wd->ent, "elm,state,remain,bytes,show", "elm");
1974    edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
1975  }
1976
1977
1978 /**
1979  * This sets the entry object to password mode.  All text entered
1980  * and/or displayed within the widget will be replaced with asterisks (*).
1981  *
1982  * @param obj The entry object
1983  * @param password If true, password mode is enabled.
1984  *
1985  * @ingroup Entry
1986  */
1987 EAPI void
1988 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1989 {
1990    ELM_CHECK_WIDTYPE(obj, widtype);
1991    Widget_Data *wd = elm_widget_data_get(obj);
1992    const char *t;
1993    if (!wd) return;
1994    if (wd->password == password) return;
1995    wd->password = password;
1996    wd->show_last_character = EINA_FALSE;
1997    wd->single_line = EINA_TRUE;
1998    wd->linewrap = EINA_FALSE;
1999    wd->char_linewrap = EINA_FALSE;
2000    t = eina_stringshare_add(elm_entry_entry_get(obj));
2001    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2002    elm_entry_entry_set(obj, t);
2003    eina_stringshare_del(t);
2004    _sizing_eval(obj);
2005 }
2006
2007 /**
2008  * This set's the entry in password mode with out masking the last character entered by user,
2009  * and later masking the character after 2 seconds.
2010  
2011  * @param obj The entry object
2012  * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character" 
2013  * 0 for default).
2014  *
2015  * @ingroup Entry
2016  */
2017 EAPI void         
2018 elm_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
2019 {
2020    Widget_Data *wd = elm_widget_data_get(obj);
2021    const char *t;
2022    if (!wd) return;
2023    if ((wd->password == show_last_character)&&(wd->show_last_character ==show_last_character))  return;
2024    wd->show_last_character = show_last_character;
2025    wd->password = show_last_character;
2026    wd->single_line = EINA_TRUE;
2027    wd->linewrap = EINA_FALSE;
2028    wd->char_linewrap = EINA_FALSE;
2029    t = eina_stringshare_add(elm_entry_entry_get(obj));
2030     _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2031    elm_entry_entry_set(obj, t);
2032    eina_stringshare_del(t);
2033    _sizing_eval(obj);
2034 }
2035
2036 /**
2037  * This returns whether password mode is enabled.
2038  * See also elm_entry_password_set().
2039  *
2040  * @param obj The entry object
2041  * @return If true, the entry is set to display all characters
2042  * as asterisks (*).
2043  *
2044  * @ingroup Entry
2045  */
2046 EAPI Eina_Bool
2047 elm_entry_password_get(const Evas_Object *obj)
2048 {
2049    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2050    Widget_Data *wd = elm_widget_data_get(obj);
2051    if (!wd) return EINA_FALSE;
2052    return wd->password;
2053 }
2054
2055 /**
2056  * This sets the text displayed within the entry to @p entry.
2057  *
2058  * @param obj The entry object
2059  * @param entry The text to be displayed
2060  *
2061  * @ingroup Entry
2062  */
2063 EAPI void
2064 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2065 {
2066    ELM_CHECK_WIDTYPE(obj, widtype);
2067    Widget_Data *wd = elm_widget_data_get(obj);
2068    if (!wd) return;
2069    if (!entry) entry = "";
2070    if(wd->max_no_of_bytes)
2071      {
2072        int len = strlen(entry);
2073        if(len > wd->max_no_of_bytes)
2074        {
2075          ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2076          return;
2077        }
2078      }
2079    edje_object_part_text_set(wd->ent, "elm.text", entry);
2080    if (wd->text) eina_stringshare_del(wd->text);
2081    wd->text = NULL;
2082    wd->changed = EINA_TRUE;
2083    _sizing_eval(obj);
2084 }
2085
2086 /**
2087  * This returns the text currently shown in object @p entry.
2088  * See also elm_entry_entry_set().
2089  *
2090  * @param obj The entry object
2091  * @return The currently displayed text or NULL on failure
2092  *
2093  * @ingroup Entry
2094  */
2095 EAPI const char *
2096 elm_entry_entry_get(const Evas_Object *obj)
2097 {
2098    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2099    Widget_Data *wd = elm_widget_data_get(obj);
2100    const char *text;
2101    if (!wd) return NULL;
2102    if (wd->text) return wd->text;
2103    text = edje_object_part_text_get(wd->ent, "elm.text");
2104    if (!text)
2105      {
2106 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2107 return NULL;
2108      }
2109    eina_stringshare_replace(&wd->text, text);
2110    return wd->text;
2111 }
2112
2113 /**
2114  * This returns all selected text within the entry.
2115  *
2116  * @param obj The entry object
2117  * @return The selected text within the entry or NULL on failure
2118  *
2119  * @ingroup Entry
2120  */
2121 EAPI const char *
2122 elm_entry_selection_get(const Evas_Object *obj)
2123 {
2124    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2125    Widget_Data *wd = elm_widget_data_get(obj);
2126    if (!wd) return NULL;
2127    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2128 }
2129
2130 /**
2131  * This inserts text in @p entry at the beginning of the entry
2132  * object.
2133  *
2134  * @param obj The entry object
2135  * @param entry The text to insert
2136  *
2137  * @ingroup Entry
2138  */
2139 EAPI void
2140 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2141 {
2142    ELM_CHECK_WIDTYPE(obj, widtype);
2143    Widget_Data *wd = elm_widget_data_get(obj);
2144    if (!wd) return;
2145    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2146    wd->changed = EINA_TRUE;
2147    _sizing_eval(obj);
2148 }
2149
2150 /**
2151  * This enables word line wrapping in the entry object.  It is the opposite
2152  * of elm_entry_single_line_set().  Additionally, setting this disables
2153  * character line wrapping.
2154  * See also elm_entry_line_char_wrap_set().
2155  *
2156  * @param obj The entry object
2157  * @param wrap If true, the entry will be wrapped once it reaches the end
2158  * of the object. Wrapping will occur at the end of the word before the end of the
2159  * object.
2160  *
2161  * @ingroup Entry
2162  */
2163 EAPI void
2164 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2165 {
2166    ELM_CHECK_WIDTYPE(obj, widtype);
2167    Widget_Data *wd = elm_widget_data_get(obj);
2168    const char *t;
2169    if (!wd) return;
2170    if (wd->linewrap == wrap) return;
2171    wd->linewrap = wrap;
2172    if(wd->linewrap)
2173        wd->char_linewrap = EINA_FALSE;
2174    t = eina_stringshare_add(elm_entry_entry_get(obj));
2175    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2176    elm_entry_entry_set(obj, t);
2177    eina_stringshare_del(t);
2178    _sizing_eval(obj);
2179 }
2180
2181 /**
2182  * Set wrap width of the entry
2183  *
2184  * @param obj The entry object
2185  * @param w The wrap width in pixels at a minimum where words need to wrap
2186  * @ingroup Entry
2187  */
2188 EAPI void
2189 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2190 {
2191    Widget_Data *wd = elm_widget_data_get(obj);
2192    if (wd->wrap_w == w) return;
2193    wd->wrap_w = w;
2194    _sizing_eval(obj);
2195 }
2196
2197 /**
2198  * get wrap width of the entry
2199  *
2200  * @param obj The entry object
2201  * @return The wrap width in pixels at a minimum where words need to wrap
2202  * @ingroup Entry
2203  */
2204 EAPI Evas_Coord
2205 elm_entry_wrap_width_get(const Evas_Object *obj)
2206 {
2207    Widget_Data *wd = elm_widget_data_get(obj);
2208    return wd->wrap_w;
2209 }
2210
2211 /**
2212  * This enables character line wrapping in the entry object.  It is the opposite
2213  * of elm_entry_single_line_set().  Additionally, setting this disables
2214  * word line wrapping.
2215  * See also elm_entry_line_wrap_set().
2216  *
2217  * @param obj The entry object
2218  * @param wrap If true, the entry will be wrapped once it reaches the end
2219  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2220  *
2221  * @ingroup Entry
2222  */
2223 EAPI void
2224 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2225 {
2226    ELM_CHECK_WIDTYPE(obj, widtype);
2227    Widget_Data *wd = elm_widget_data_get(obj);
2228    const char *t;
2229    if (!wd) return;
2230    if (wd->char_linewrap == wrap) return;
2231    wd->char_linewrap = wrap;
2232    if(wd->char_linewrap)
2233        wd->linewrap = EINA_FALSE;
2234    t = eina_stringshare_add(elm_entry_entry_get(obj));
2235    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2236    elm_entry_entry_set(obj, t);
2237    eina_stringshare_del(t);
2238    _sizing_eval(obj);
2239 }
2240
2241 /**
2242  * This sets the editable attribute of the entry.
2243  *
2244  * @param obj The entry object
2245  * @param editable If true, the entry will be editable by the user.
2246  * If false, it will be set to the disabled state.
2247  *
2248  * @ingroup Entry
2249  */
2250 EAPI void
2251 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2252 {
2253    ELM_CHECK_WIDTYPE(obj, widtype);
2254    Widget_Data *wd = elm_widget_data_get(obj);
2255    const char *t;
2256    if (!wd) return;
2257    if (wd->editable == editable) return;
2258    wd->editable = editable;
2259    t = eina_stringshare_add(elm_entry_entry_get(obj));
2260    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2261    elm_entry_entry_set(obj, t);
2262    eina_stringshare_del(t);
2263    _sizing_eval(obj);
2264 }
2265
2266 /**
2267  * This gets the editable attribute of the entry.
2268  * See also elm_entry_editable_set().
2269  *
2270  * @param obj The entry object
2271  * @return If true, the entry is editable by the user.
2272  * If false, it is not editable by the user
2273  *
2274  * @ingroup Entry
2275  */
2276 EAPI Eina_Bool
2277 elm_entry_editable_get(const Evas_Object *obj)
2278 {
2279    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2280    Widget_Data *wd = elm_widget_data_get(obj);
2281    if (!wd) return EINA_FALSE;
2282    return wd->editable;
2283 }
2284
2285 /**
2286  * This drops any existing text selection within the entry.
2287  *
2288  * @param obj The entry object
2289  *
2290  * @ingroup Entry
2291  */
2292 EAPI void
2293 elm_entry_select_none(Evas_Object *obj)
2294 {
2295    ELM_CHECK_WIDTYPE(obj, widtype);
2296    Widget_Data *wd = elm_widget_data_get(obj);
2297    if (!wd) return;
2298    if (wd->selmode)
2299      {
2300        wd->selmode = EINA_FALSE;
2301        edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2302        edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2303      }
2304    wd->have_selection = EINA_FALSE;
2305    edje_object_part_text_select_none(wd->ent, "elm.text");
2306 }
2307
2308 /**
2309  * This selects all text within the entry.
2310  *
2311  * @param obj The entry object
2312  *
2313  * @ingroup Entry
2314  */
2315 EAPI void
2316 elm_entry_select_all(Evas_Object *obj)
2317 {
2318    ELM_CHECK_WIDTYPE(obj, widtype);
2319    Widget_Data *wd = elm_widget_data_get(obj);
2320    if (!wd) return;
2321    if (wd->selmode)
2322      {
2323        wd->selmode = EINA_FALSE;
2324        edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
2325        edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2326      }
2327    wd->have_selection = EINA_TRUE;
2328    edje_object_part_text_select_all(wd->ent, "elm.text");
2329 }
2330
2331 /**
2332  * This moves the cursor one place to the right within the entry.
2333  *
2334  * @param obj The entry object
2335  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2336  *
2337  * @ingroup Entry
2338  */
2339 EAPI Eina_Bool
2340 elm_entry_cursor_next(Evas_Object *obj)
2341 {
2342    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2343    Widget_Data *wd = elm_widget_data_get(obj);
2344    if (!wd) return EINA_FALSE;
2345    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2346 }
2347
2348 /**
2349  * This moves the cursor one place to the left within the entry.
2350  *
2351  * @param obj The entry object
2352  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2353  *
2354  * @ingroup Entry
2355  */
2356 EAPI Eina_Bool
2357 elm_entry_cursor_prev(Evas_Object *obj)
2358 {
2359    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2360    Widget_Data *wd = elm_widget_data_get(obj);
2361    if (!wd) return EINA_FALSE;
2362    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2363 }
2364
2365 /**
2366  * This moves the cursor one line up within the entry.
2367  *
2368  * @param obj The entry object
2369  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2370  *
2371  * @ingroup Entry
2372  */
2373 EAPI Eina_Bool
2374 elm_entry_cursor_up(Evas_Object *obj)
2375 {
2376    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2377    Widget_Data *wd = elm_widget_data_get(obj);
2378    if (!wd) return EINA_FALSE;
2379    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2380 }
2381
2382 /**
2383  * This moves the cursor one line down within the entry.
2384  *
2385  * @param obj The entry object
2386  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2387  *
2388  * @ingroup Entry
2389  */
2390 EAPI Eina_Bool
2391 elm_entry_cursor_down(Evas_Object *obj)
2392 {
2393    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2394    Widget_Data *wd = elm_widget_data_get(obj);
2395    if (!wd) return EINA_FALSE;
2396    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2397 }
2398
2399 /**
2400  * This moves the cursor to the beginning of the entry.
2401  *
2402  * @param obj The entry object
2403  *
2404  * @ingroup Entry
2405  */
2406 EAPI void
2407 elm_entry_cursor_begin_set(Evas_Object *obj)
2408 {
2409    ELM_CHECK_WIDTYPE(obj, widtype);
2410    Widget_Data *wd = elm_widget_data_get(obj);
2411    if (!wd) return;
2412    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2413 }
2414
2415 /**
2416  * This moves the cursor to the end of the entry.
2417  *
2418  * @param obj The entry object
2419  *
2420  * @ingroup Entry
2421  */
2422 EAPI void
2423 elm_entry_cursor_end_set(Evas_Object *obj)
2424 {
2425    ELM_CHECK_WIDTYPE(obj, widtype);
2426    Widget_Data *wd = elm_widget_data_get(obj);
2427    if (!wd) return;
2428    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2429 }
2430
2431 /**
2432  * This moves the cursor to the beginning of the current line.
2433  *
2434  * @param obj The entry object
2435  *
2436  * @ingroup Entry
2437  */
2438 EAPI void
2439 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2440 {
2441    ELM_CHECK_WIDTYPE(obj, widtype);
2442    Widget_Data *wd = elm_widget_data_get(obj);
2443    if (!wd) return;
2444    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2445 }
2446
2447 /**
2448  * This moves the cursor to the end of the current line.
2449  *
2450  * @param obj The entry object
2451  *
2452  * @ingroup Entry
2453  */
2454 EAPI void
2455 elm_entry_cursor_line_end_set(Evas_Object *obj)
2456 {
2457    ELM_CHECK_WIDTYPE(obj, widtype);
2458    Widget_Data *wd = elm_widget_data_get(obj);
2459    if (!wd) return;
2460    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2461 }
2462
2463 /**
2464  * This begins a selection within the entry as though
2465  * the user were holding down the mouse button to make a selection.
2466  *
2467  * @param obj The entry object
2468  *
2469  * @ingroup Entry
2470  */
2471 EAPI void
2472 elm_entry_cursor_selection_begin(Evas_Object *obj)
2473 {
2474    ELM_CHECK_WIDTYPE(obj, widtype);
2475    Widget_Data *wd = elm_widget_data_get(obj);
2476    if (!wd) return;
2477    edje_object_part_text_select_begin(wd->ent, "elm.text");
2478 }
2479
2480 /**
2481  * This ends a selection within the entry as though
2482  * the user had just released the mouse button while making a selection.
2483  *
2484  * @param obj The entry object
2485  *
2486  * @ingroup Entry
2487  */
2488 EAPI void
2489 elm_entry_cursor_selection_end(Evas_Object *obj)
2490 {
2491    ELM_CHECK_WIDTYPE(obj, widtype);
2492    Widget_Data *wd = elm_widget_data_get(obj);
2493    if (!wd) return;
2494    edje_object_part_text_select_extend(wd->ent, "elm.text");
2495 }
2496
2497 /**
2498  * TODO: fill this in
2499  *
2500  * @param obj The entry object
2501  * @return TODO: fill this in
2502  *
2503  * @ingroup Entry
2504  */
2505 EAPI Eina_Bool
2506 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2507 {
2508    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2509    Widget_Data *wd = elm_widget_data_get(obj);
2510    if (!wd) return EINA_FALSE;
2511    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2512 }
2513
2514 /**
2515  * This returns whether the cursor is visible.
2516  *
2517  * @param obj The entry object
2518  * @return If true, the cursor is visible.
2519  *
2520  * @ingroup Entry
2521  */
2522 EAPI Eina_Bool
2523 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2524 {
2525    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2526    Widget_Data *wd = elm_widget_data_get(obj);
2527    if (!wd) return EINA_FALSE;
2528    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2529 }
2530
2531 /**
2532  * TODO: fill this in
2533  *
2534  * @param obj The entry object
2535  * @return TODO: fill this in
2536  *
2537  * @ingroup Entry
2538  */
2539 EAPI const char *
2540 elm_entry_cursor_content_get(const Evas_Object *obj)
2541 {
2542    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2543    Widget_Data *wd = elm_widget_data_get(obj);
2544    if (!wd) return NULL;
2545    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2546 }
2547
2548 /**
2549  * This executes a "cut" action on the selected text in the entry.
2550  *
2551  * @param obj The entry object
2552  *
2553  * @ingroup Entry
2554  */
2555 EAPI void
2556 elm_entry_selection_cut(Evas_Object *obj)
2557 {
2558    ELM_CHECK_WIDTYPE(obj, widtype);
2559    Widget_Data *wd = elm_widget_data_get(obj);
2560    if (!wd) return;
2561    _cut(obj, NULL, NULL);
2562 }
2563
2564 /**
2565  * This executes a "copy" action on the selected text in the entry.
2566  *
2567  * @param obj The entry object
2568  *
2569  * @ingroup Entry
2570  */
2571 EAPI void
2572 elm_entry_selection_copy(Evas_Object *obj)
2573 {
2574    ELM_CHECK_WIDTYPE(obj, widtype);
2575    Widget_Data *wd = elm_widget_data_get(obj);
2576    if (!wd) return;
2577    _copy(obj, NULL, NULL);
2578 }
2579
2580 /**
2581  * This executes a "paste" action in the entry.
2582  *
2583  * @param obj The entry object
2584  *
2585  * @ingroup Entry
2586  */
2587 EAPI void
2588 elm_entry_selection_paste(Evas_Object *obj)
2589 {
2590    ELM_CHECK_WIDTYPE(obj, widtype);
2591    Widget_Data *wd = elm_widget_data_get(obj);
2592    if (!wd) return;
2593    _paste(obj, NULL, NULL);
2594 }
2595
2596 /**
2597  * This clears and frees the items in a entry's contextual (right click) menu.
2598  *
2599  * @param obj The entry object
2600  *
2601  * @ingroup Entry
2602  */
2603 EAPI void
2604 elm_entry_context_menu_clear(Evas_Object *obj)
2605 {
2606    ELM_CHECK_WIDTYPE(obj, widtype);
2607    Widget_Data *wd = elm_widget_data_get(obj);
2608    Elm_Entry_Context_Menu_Item *it;
2609    if (!wd) return;
2610    EINA_LIST_FREE(wd->items, it)
2611      {
2612         eina_stringshare_del(it->label);
2613         eina_stringshare_del(it->icon_file);
2614         eina_stringshare_del(it->icon_group);
2615         free(it);
2616      }
2617 }
2618
2619 /**
2620  * This adds an item to the entry's contextual menu.
2621  *
2622  * @param obj The entry object
2623  * @param label The item's text label
2624  * @param icon_file The item's icon file
2625  * @param icon_type The item's icon type
2626  * @param func The callback to execute when the item is clicked
2627  * @param data The data to associate with the item for related functions
2628  *
2629  * @ingroup Entry
2630  */
2631 EAPI void
2632 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)
2633 {
2634    ELM_CHECK_WIDTYPE(obj, widtype);
2635    Widget_Data *wd = elm_widget_data_get(obj);
2636    Elm_Entry_Context_Menu_Item *it;
2637    if (!wd) return;
2638    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2639    if (!it) return;
2640    wd->items = eina_list_append(wd->items, it);
2641    it->obj = obj;
2642    it->label = eina_stringshare_add(label);
2643    it->icon_file = eina_stringshare_add(icon_file);
2644    it->icon_type = icon_type;
2645    it->func = func;
2646    it->data = (void *)data;
2647 }
2648
2649 /**
2650  * This disables the entry's contextual (right click) menu.
2651  *
2652  * @param obj The entry object
2653  * @param disabled If true, the menu is disabled
2654  *
2655  * @ingroup Entry
2656  */
2657 EAPI void
2658 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2659 {
2660    ELM_CHECK_WIDTYPE(obj, widtype);
2661    Widget_Data *wd = elm_widget_data_get(obj);
2662    if (!wd) return;
2663    if (wd->context_menu == !disabled) return;
2664    wd->context_menu = !disabled;
2665 }
2666
2667 /**
2668  * This returns whether the entry's contextual (right click) menu is disabled.
2669  *
2670  * @param obj The entry object
2671  * @return If true, the menu is disabled
2672  *
2673  * @ingroup Entry
2674  */
2675 EAPI Eina_Bool
2676 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2677 {
2678    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2679    Widget_Data *wd = elm_widget_data_get(obj);
2680    if (!wd) return EINA_FALSE;
2681    return !wd->context_menu;
2682 }
2683
2684 /**
2685  * This appends a custom item provider to the list for that entry
2686  *
2687  * This appends the given callback. The list is walked from beginning to end
2688  * with each function called given the item href string in the text. If the
2689  * function returns an object handle other than NULL (it should create an
2690  * and object to do this), then this object is used to replace that item. If
2691  * not the next provider is called until one provides an item object, or the
2692  * default provider in entry does.
2693  * 
2694  * @param obj The entry object
2695  * @param func The function called to provide the item object
2696  * @param data The data passed to @p func
2697  *
2698  * @ingroup Entry
2699  */
2700 EAPI void
2701 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2702 {
2703    ELM_CHECK_WIDTYPE(obj, widtype);
2704    Widget_Data *wd = elm_widget_data_get(obj);
2705    if (!wd) return;
2706    if (!func) return;
2707    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2708    if (!ip) return;
2709    ip->func = func;
2710    ip->data = data;
2711    wd->item_providers = eina_list_append(wd->item_providers, ip);
2712 }
2713
2714 /**
2715  * This prepends a custom item provider to the list for that entry
2716  *
2717  * This prepends the given callback. See elm_entry_item_provider_append() for
2718  * more information
2719  * 
2720  * @param obj The entry object
2721  * @param func The function called to provide the item object
2722  * @param data The data passed to @p func
2723  *
2724  * @ingroup Entry
2725  */
2726 EAPI void
2727 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2728 {
2729    ELM_CHECK_WIDTYPE(obj, widtype);
2730    Widget_Data *wd = elm_widget_data_get(obj);
2731    if (!wd) return;
2732    if (!func) return;
2733    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2734    if (!ip) return;
2735    ip->func = func;
2736    ip->data = data;
2737    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2738 }
2739
2740 /**
2741  * This removes a custom item provider to the list for that entry
2742  *
2743  * This removes the given callback. See elm_entry_item_provider_append() for
2744  * more information
2745  * 
2746  * @param obj The entry object
2747  * @param func The function called to provide the item object
2748  * @param data The data passed to @p func
2749  *
2750  * @ingroup Entry
2751  */
2752 EAPI void
2753 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2754 {
2755    ELM_CHECK_WIDTYPE(obj, widtype);
2756    Widget_Data *wd = elm_widget_data_get(obj);
2757    Eina_List *l;
2758    Elm_Entry_Item_Provider *ip;
2759    if (!wd) return;
2760    if (!func) return;
2761    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2762      {
2763         if ((ip->func == func) && (ip->data == data))
2764           {
2765              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2766              free(ip);
2767              return;
2768           }
2769      }
2770 }
2771
2772 /**
2773  * This converts a markup (HTML-like) string into UTF-8.
2774  *
2775  * @param s The string (in markup) to be converted
2776  * @return The converted string (in UTF-8)
2777  *
2778  * @ingroup Entry
2779  */
2780 EAPI char *
2781 elm_entry_markup_to_utf8(const char *s)
2782 {
2783    char *ss = _mkup_to_text(s);
2784    if (!ss) ss = strdup("");
2785    return ss;
2786 }
2787
2788 /**
2789  * This converts a UTF-8 string into markup (HTML-like).
2790  *
2791  * @param s The string (in UTF-8) to be converted
2792  * @return The converted string (in markup)
2793  *
2794  * @ingroup Entry
2795  */
2796 EAPI char *
2797 elm_entry_utf8_to_markup(const char *s)
2798 {
2799    char *ss = _text_to_mkup(s);
2800    if (!ss) ss = strdup("");
2801    return ss;
2802 }
2803
2804 /**
2805  * Get the input method context in the entry widget
2806  *
2807  * @param obj The entry object
2808  * @return The input method context
2809  *
2810  * @ingroup Entry
2811  */
2812 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
2813 {
2814    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2815    Widget_Data *wd = elm_widget_data_get(obj);
2816    if (!wd || !wd->ent) return NULL;
2817   
2818    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
2819 }
2820
2821 /**
2822  * Set whether entry should enable the return key on soft keyboard automatically
2823  *
2824  * @param obj The entry object
2825  * @param on If true, entry enables the return key on soft keyboard automatically.
2826  *
2827  * @ingroup Entry
2828  */
2829 EAPI void 
2830 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
2831 {
2832    ELM_CHECK_WIDTYPE(obj, widtype);
2833    Widget_Data *wd = elm_widget_data_get(obj);
2834    if (!wd) return;
2835
2836    wd->autoreturnkey = on;
2837    _check_enable_returnkey(obj);
2838 }
2839
2840 /**
2841  * Set whether entry should support auto capitalization
2842  *
2843  * @param obj The entry object
2844  * @param on If true, entry suports auto capitalization.
2845  *
2846  * @ingroup Entry
2847  */
2848 EAPI void 
2849 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool on)
2850 {
2851    ELM_CHECK_WIDTYPE(obj, widtype);
2852    Widget_Data *wd = elm_widget_data_get(obj);
2853    if (!wd) return;
2854
2855    if (wd->password)
2856        wd->autocapitalize = EINA_FALSE;
2857    else
2858        wd->autocapitalize = on;
2859
2860    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapitalize);
2861 }
2862
2863 /**
2864  * Set the font size on the entry object
2865  *
2866  * @param obj The entry object
2867  * @param size font size
2868  *
2869  * @ingroup Entry
2870  */
2871 EAPI void
2872 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
2873 {
2874    ELM_CHECK_WIDTYPE(obj, widtype);
2875    Widget_Data *wd = elm_widget_data_get(obj);
2876    Eina_Strbuf *fontbuf = NULL;
2877    int removeflag = 0;
2878    const char *t;
2879
2880    if (!wd) return;
2881    t = eina_stringshare_add(elm_entry_entry_get(obj));
2882    fontbuf = eina_strbuf_new();
2883    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
2884
2885    if (fontsize == 0) removeflag = 1; // remove fontsize tag
2886
2887    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
2888      {
2889        elm_entry_entry_set(obj, t);
2890        wd->changed = 1;
2891        _sizing_eval(obj);
2892      }
2893    eina_strbuf_free(fontbuf);
2894    eina_stringshare_del(t);
2895 }
2896
2897 /**
2898  * Set the text align on the entry object
2899  *
2900  * @param obj The entry object
2901  * @param align align mode
2902  *
2903  * @ingroup Entry
2904  */
2905 EAPI void
2906 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
2907 {
2908    ELM_CHECK_WIDTYPE(obj, widtype);
2909    Widget_Data *wd = elm_widget_data_get(obj);
2910    int len;
2911    const char *t;
2912
2913    if (!wd) return;
2914    t = eina_stringshare_add(elm_entry_entry_get(obj));
2915    len = strlen(t);
2916    if (len <= 0) return;
2917
2918    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
2919      elm_entry_entry_set(obj, t);
2920
2921    wd->changed = 1;
2922    _sizing_eval(obj);
2923    eina_stringshare_del(t);
2924 }
2925
2926 /**
2927  * Set the text color on the entry object
2928  *
2929  * @param obj The entry object
2930  * @param r Red property background color of The entry object 
2931  * @param g Green property background color of The entry object 
2932  * @param b Blue property background color of The entry object 
2933  * @param a Alpha property background alpha of The entry object 
2934  *
2935  * @ingroup Entry
2936  */
2937 EAPI void
2938 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
2939 {
2940    ELM_CHECK_WIDTYPE(obj, widtype);
2941    Widget_Data *wd = elm_widget_data_get(obj);
2942    Eina_Strbuf *colorbuf = NULL;
2943    const char *t;
2944    int len;
2945
2946    if (!wd) return;
2947    t = eina_stringshare_add(elm_entry_entry_get(obj));
2948    len = strlen(t);
2949    if (len <= 0) return;
2950    colorbuf = eina_strbuf_new();
2951    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
2952
2953    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
2954      {
2955        elm_entry_entry_set(obj, t);
2956        wd->changed = 1;
2957        _sizing_eval(obj);
2958      }
2959    eina_strbuf_free(colorbuf);
2960    eina_stringshare_del(t);
2961 }
2962
2963
2964 /**
2965  * Set background color of the entry
2966  *
2967  * @param obj The entry object
2968  * @param r Red property background color of The entry object 
2969  * @param g Green property background color of The entry object 
2970  * @param b Blue property background color of The entry object 
2971  * @param a Alpha property background alpha of The entry object 
2972  * @ingroup Entry
2973  */
2974 EAPI void
2975 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
2976 {
2977    ELM_CHECK_WIDTYPE(obj, widtype);
2978    Widget_Data *wd = elm_widget_data_get(obj);
2979    evas_object_color_set(wd->bg, r, g, b, a);
2980
2981    if (wd->bgcolor == EINA_FALSE)
2982      {
2983        wd->bgcolor = 1;
2984        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
2985      }
2986 }
2987
2988 /**
2989  * Set the ellipsis behavior of the entry
2990  *
2991  * @param obj The entry object
2992  * @param ellipsis To ellipsis text or not
2993  * @ingroup Entry
2994  */
2995 EAPI void
2996 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
2997 {
2998    ELM_CHECK_WIDTYPE(obj, widtype);
2999    Widget_Data *wd = elm_widget_data_get(obj);
3000    if (wd->ellipsis == ellipsis) return;
3001    wd->ellipsis = ellipsis;
3002    wd->changed = 1;
3003    _sizing_eval(obj);
3004 }
3005
3006 /**
3007  * This sets the attribute to show the input panel automatically.
3008  *
3009  * @param obj The entry object
3010  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3011  *
3012  * @ingroup Entry
3013  */
3014 EAPI void
3015 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3016 {
3017    ELM_CHECK_WIDTYPE(obj, widtype);
3018    Widget_Data *wd = elm_widget_data_get(obj);
3019    if (!wd) return;
3020
3021    wd->input_panel_enable = enabled;
3022    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3023 }
3024
3025 /**
3026  * Set the input panel layout of the entry
3027  *
3028  * @param obj The entry object
3029  * @param layout the layout to set
3030  *
3031  * @ingroup Entry
3032  */
3033 EAPI void
3034 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3035 {
3036    ELM_CHECK_WIDTYPE(obj, widtype);
3037    Widget_Data *wd = elm_widget_data_get(obj);
3038    if (!wd) return;
3039    
3040    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3041    if (!ic) return;
3042
3043    wd->input_panel_layout = layout;
3044    
3045    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
3046 }