From cb4aeb780eda499736ddcba5fab939ec1ee3b792 Mon Sep 17 00:00:00 2001 From: Hyoyoung Chang Date: Tue, 20 Dec 2011 08:37:26 +0000 Subject: [PATCH] From: Hyoyoung Chang Subject: [E-devel] [patch] elm_cnp_helper - add type checking for non-elm cnp datas Date: Fri, 16 Dec 2011 17:09:37 +0900 Dear developers elm_cnp_helper supports rich types for copying & pasting. but it doesn't extend like x11 way. this patch introduces to reduce mismatch for checking selection type format. now elm can live in harmony with non-elm cnp datas Thanks SVN revision: 66367 --- legacy/elementary/src/lib/elm_cnp_helper.c | 45 ++++++++++++++-------- legacy/elementary/src/lib/elm_widget.h | 10 +++-- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/legacy/elementary/src/lib/elm_cnp_helper.c b/legacy/elementary/src/lib/elm_cnp_helper.c index 9a5884c7bf..03254d2f40 100644 --- a/legacy/elementary/src/lib/elm_cnp_helper.c +++ b/legacy/elementary/src/lib/elm_cnp_helper.c @@ -168,15 +168,15 @@ static const Escape escapes[] = { static Cnp_Atom atoms[CNP_N_ATOMS] = { [CNP_ATOM_TARGETS] = { "TARGETS", - (Elm_Sel_Format) -1, // everything + ELM_SEL_TARGETS, targets_converter, response_handler_targets, notify_handler_targets, 0 }, [CNP_ATOM_ATOM] = { - "ATOM", - (Elm_Sel_Format) -1, // everything + "ATOM", // for opera browser + ELM_SEL_TARGETS, targets_converter, response_handler_targets, notify_handler_targets, @@ -425,7 +425,7 @@ elm_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format fo sel = selections + selection; - sel->active = 1; + sel->active = EINA_TRUE; sel->widget = widget; sel->set(xwin, &selection, sizeof(Elm_Sel_Type)); @@ -452,7 +452,7 @@ elm_selection_clear(Elm_Sel_Type selection, Evas_Object *widget) /* No longer this selection: Consider it gone! */ if ((!sel->active) || (sel->widget != widget)) return EINA_TRUE; - sel->active = 0; + sel->active = EINA_FALSE; sel->widget = NULL; sel->clear(); @@ -587,7 +587,18 @@ selection_notify(void *udata __UNUSED__, int type __UNUSED__, void *event) return ECORE_CALLBACK_PASS_ON; } - +static Elm_Sel_Format +_get_selection_type(void *data, int size) +{ + if (size == sizeof(Elm_Sel_Type)) + { + Cnp_Selection *sel; + sel = selections + *((int *)data); + if (sel->active) + return sel->format; + } + return ELM_SEL_FORMAT_NONE; +} static Eina_Bool targets_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize) @@ -598,7 +609,7 @@ targets_converter(char *target __UNUSED__, void *data, int size, void **data_ret if (!data_ret) return EINA_FALSE; - if (size != sizeof(int)) + if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE) { if (data_ret) { @@ -987,7 +998,7 @@ text_converter(char *target __UNUSED__, void *data, int size, void **data_ret, i Cnp_Selection *sel; cnp_debug("text converter\n"); - if (size != sizeof(int)) + if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE) { if (data_ret) { @@ -1026,15 +1037,7 @@ text_converter(char *target __UNUSED__, void *data, int size, void **data_ret, i static Eina_Bool general_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__) { - if (size == sizeof(int)) - { - Cnp_Selection *sel; - - sel = selections + *((int *)data); - if (data_ret) *data_ret = strdup(sel->selbuf); - if (size_ret) *size_ret = strlen(sel->selbuf); - } - else if (size) + if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE) { if (data_ret) { @@ -1044,6 +1047,14 @@ general_converter(char *target __UNUSED__, void *data, int size, void **data_ret } if (size_ret) *size_ret = size; } + else + { + Cnp_Selection *sel; + + sel = selections + *((int *)data); + if (data_ret) *data_ret = strdup(sel->selbuf); + if (size_ret) *size_ret = strlen(sel->selbuf); + } return EINA_TRUE; } diff --git a/legacy/elementary/src/lib/elm_widget.h b/legacy/elementary/src/lib/elm_widget.h index 8ed1fa107d..79886ae633 100644 --- a/legacy/elementary/src/lib/elm_widget.h +++ b/legacy/elementary/src/lib/elm_widget.h @@ -727,16 +727,20 @@ typedef enum _Elm_Sel_Type typedef enum _Elm_Sel_Format { + /** Targets: for matching every atom requesting */ + ELM_SEL_TARGETS = -1, + /** they come from outside of elm */ + ELM_SEL_FORMAT_NONE = 0x0, /** Plain unformated text: Used for things that don't want rich markup */ ELM_SEL_FORMAT_TEXT = 0x01, /** Edje textblock markup, including inline images */ ELM_SEL_FORMAT_MARKUP = 0x02, /** Images */ - ELM_SEL_FORMAT_IMAGE = 0x04, + ELM_SEL_FORMAT_IMAGE = 0x04, /** Vcards */ - ELM_SEL_FORMAT_VCARD = 0x08, + ELM_SEL_FORMAT_VCARD = 0x08, /** Raw HTMLish things for widgets that want that stuff (hello webkit!) */ - ELM_SEL_FORMAT_HTML = 0x10, + ELM_SEL_FORMAT_HTML = 0x10, } Elm_Sel_Format; struct _Elm_Selection_Data