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