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