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