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