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