From 78418c0226b9c31ed2ccabdf7a7e0cc6df7ff401 Mon Sep 17 00:00:00 2001 From: Brett Nash Date: Thu, 13 Jan 2011 23:04:25 +0000 Subject: [PATCH] Elm: Entry: cno: Add support for using text only in entries. By default it's text only for single line entries (you can toggle it back on if you want to). Otherwise images are enabled for multiline entries. SVN revision: 56078 --- legacy/elementary/src/lib/Elementary.h.in | 3 ++ legacy/elementary/src/lib/elm_entry.c | 58 ++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/legacy/elementary/src/lib/Elementary.h.in b/legacy/elementary/src/lib/Elementary.h.in index 8e6bba3b36..460d489add 100644 --- a/legacy/elementary/src/lib/Elementary.h.in +++ b/legacy/elementary/src/lib/Elementary.h.in @@ -1223,6 +1223,9 @@ extern "C" { EAPI void elm_entry_file_save(Evas_Object *obj) EINA_ARG_NONNULL(1); EAPI void elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave) EINA_ARG_NONNULL(1); EAPI Eina_Bool elm_entry_autosave_get(const Evas_Object *obj) EINA_ARG_NONNULL(1); + EAPI void elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly) EINA_ARG_NONNULL(1); + EAPI Eina_Bool elm_entry_cnp_textonly_get(Evas_Object *obj) EINA_ARG_NONNULL(1); + /* pre-made filters for entries */ typedef struct _Elm_Entry_Filter_Limit_Size Elm_Entry_Filter_Limit_Size; struct _Elm_Entry_Filter_Limit_Size diff --git a/legacy/elementary/src/lib/elm_entry.c b/legacy/elementary/src/lib/elm_entry.c index 2ddc36dda4..87f451edda 100644 --- a/legacy/elementary/src/lib/elm_entry.c +++ b/legacy/elementary/src/lib/elm_entry.c @@ -135,6 +135,7 @@ struct _Widget_Data Eina_Bool drag_selection_asked : 1; Eina_Bool can_write : 1; Eina_Bool autosave : 1; + Eina_Bool textonly : 1; }; struct _Elm_Entry_Context_Menu_Item @@ -679,7 +680,11 @@ _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) if (wd->sel_notify_handler) { #ifdef HAVE_ELEMENTARY_X + Elm_Sel_Format formats; wd->selection_asked = EINA_TRUE; + formats = ELM_SEL_FORMAT_MARKUP; + if (!wd->textonly) + formats |= ELM_SEL_FORMAT_IMAGE; elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data, NULL, NULL); #endif @@ -1411,6 +1416,7 @@ elm_entry_add(Evas_Object *parent) wd->disabled = EINA_FALSE; wd->context_menu = EINA_TRUE; wd->autosave = EINA_TRUE; + wd->textonly = EINA_FALSE; wd->ent = edje_object_add(e); edje_object_item_provider_set(wd->ent, _get_item, obj); @@ -1475,7 +1481,8 @@ elm_entry_add(Evas_Object *parent) _event_selection_clear, obj); } - elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL); + elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE, + _drag_drop_cb, NULL); #endif entries = eina_list_prepend(entries, obj); @@ -1513,6 +1520,7 @@ elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line) wd->single_line = single_line; wd->linewrap = EINA_FALSE; wd->char_linewrap = EINA_FALSE; + elm_entry_cnp_textonly_set(obj, EINA_TRUE); t = eina_stringshare_add(elm_entry_entry_get(obj)); _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj)); elm_entry_entry_set(obj, t); @@ -2672,3 +2680,51 @@ elm_entry_autosave_get(const Evas_Object *obj) if (!wd) return EINA_FALSE; return wd->autosave; } + + +/** + * Control pasting of text and images for the widget. + * + * Normally the entry allows both text and images to be pasted. By setting + * textonly to be true, this prevents images from being pasted. + * + * Note this only changes the behaviour of text. + * + * @param obj The entry object + * @param pmode paste mode - 0 is text only, 1 is text+image+other. + * + * @ingroup Entry + */ +EAPI void +elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly) +{ + Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP; + ELM_CHECK_WIDTYPE(obj, widtype); + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + textonly = !!textonly; + if (wd->textonly == textonly) return; + wd->textonly = !!textonly; + if (!textonly) format |= ELM_SEL_FORMAT_IMAGE; + elm_drop_target_add(obj, format, _drag_drop_cb, NULL); +} + +/** + * Getting elm_entry text paste/drop mode. + * + * In textonly mode, only text may be pasted or dropped into the widget. + * + * @param obj The entry object + * @return If the widget only accepts text from pastes. + * + * @ingroup Entry + */ +EAPI Eina_Bool +elm_entry_cnp_textonly_get(Evas_Object *obj) +{ + ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE; + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return EINA_FALSE; + return wd->textonly; +} +