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