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