From 57af60f04e3c8fc132fd72e17e960590c811b00d Mon Sep 17 00:00:00 2001 From: discomfitor Date: Tue, 27 Dec 2011 11:24:13 +0000 Subject: [PATCH] From: Hyoyoung Chang Subject: [E-devel] [patch] elm_cnp_helper - change elm_cnp_selection_set and code cleanup Date: Tue, 27 Dec 2011 20:15:14 +0900 Dear all. As discomfitor suggested, I cleanup some codes. elm_cnp_selection_set : add buffer length argument and check for image type. (i think it's urgent issue before elm_cnp_selection_set api is widely used.) enum defines : add 'type' prefix. Thanks git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@66566 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/Elementary.h.in | 30 ++++++------- src/lib/elm_cnp_helper.c | 109 ++++++++++++++++++++++++++++------------------- src/lib/elm_entry.c | 25 ++++++----- src/lib/elm_photo.c | 3 +- 4 files changed, 97 insertions(+), 70 deletions(-) diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index f0440f4..e1a50df 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -30414,30 +30414,30 @@ extern "C" { typedef enum _Elm_Sel_Type { - ELM_SEL_PRIMARY, - ELM_SEL_SECONDARY, - ELM_SEL_CLIPBOARD, - ELM_SEL_XDND, + ELM_SEL_TYPE_PRIMARY, + ELM_SEL_TYPE_SECONDARY, + ELM_SEL_TYPE_CLIPBOARD, + ELM_SEL_TYPE_XDND, - ELM_SEL_MAX, + ELM_SEL_TYPE_MAX, } Elm_Sel_Type; typedef enum _Elm_Sel_Format { /** Targets: for matching every atom requesting */ - ELM_SEL_TARGETS = -1, + ELM_SEL_FORMAT_TARGETS = -1, /** they come from outside of elm */ - ELM_SEL_FORMAT_NONE = 0x0, + ELM_SEL_FORMAT_NONE = 0x0, /** Plain unformated text: Used for things that don't want rich markup */ - ELM_SEL_FORMAT_TEXT = 0x01, + ELM_SEL_FORMAT_TEXT = 0x01, /** Edje textblock markup, including inline images */ - ELM_SEL_FORMAT_MARKUP = 0x02, + 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_MAX } Elm_Sel_Format; @@ -30445,9 +30445,9 @@ extern "C" { struct _Elm_Selection_Data { int x, y; - Elm_Sel_Format format; + Elm_Sel_Format format; void *data; - int len; + size_t len; }; /** @@ -30466,7 +30466,7 @@ extern "C" { * */ - EAPI Eina_Bool elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format format, const char *buf); + EAPI Eina_Bool elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format format, const void *buf, size_t buflen); /** * @brief Retrive the data from the widget which is set for copying and pasting. diff --git a/src/lib/elm_cnp_helper.c b/src/lib/elm_cnp_helper.c index 92a622d..9b29697 100644 --- a/src/lib/elm_cnp_helper.c +++ b/src/lib/elm_cnp_helper.c @@ -62,19 +62,19 @@ enum struct _Cnp_Selection { - const char *debug; - Evas_Object *widget; - char *selbuf; - Evas_Object *requestwidget; - void *udata; - Elm_Sel_Format requestformat; - Elm_Drop_Cb datacb; + const char *debug; + Evas_Object *widget; + char *selbuf; + Evas_Object *requestwidget; + void *udata; + Elm_Sel_Format requestformat; + Elm_Drop_Cb datacb; Eina_Bool (*set) (Ecore_X_Window, const void *data, int size); Eina_Bool (*clear) (void); void (*request) (Ecore_X_Window, const char *target); - Elm_Sel_Format format; - Ecore_X_Selection ecore_sel; + Elm_Sel_Format format; + Ecore_X_Selection ecore_sel; Eina_Bool active : 1; }; @@ -82,7 +82,7 @@ struct _Cnp_Selection struct _Escape { const char *escape; - const char *value; + const char *value; }; struct _Tmp_Info @@ -96,7 +96,7 @@ struct _Tmp_Info struct _Cnp_Atom { const char *name; - Elm_Sel_Format formats; + Elm_Sel_Format formats; /* Called by ecore to do conversion */ Converter_Fn_Cb converter; Response_Handler_Cb response; @@ -116,11 +116,11 @@ struct _Saved_Type struct _Dropable { - Evas_Object *obj; + Evas_Object *obj; /* FIXME: Cache window */ - Elm_Sel_Format types; - Elm_Drop_Cb dropcb; - void *cbdata; + Elm_Sel_Format types; + Elm_Drop_Cb dropcb; + void *cbdata; }; static Tmp_Info *elm_cnp_tempfile_create(int size); @@ -168,7 +168,7 @@ static const Escape escapes[] = { static Cnp_Atom atoms[CNP_N_ATOMS] = { [CNP_ATOM_TARGETS] = { "TARGETS", - ELM_SEL_TARGETS, + ELM_SEL_FORMAT_TARGETS, targets_converter, response_handler_targets, notify_handler_targets, @@ -176,7 +176,7 @@ static Cnp_Atom atoms[CNP_N_ATOMS] = { }, [CNP_ATOM_ATOM] = { "ATOM", // for opera browser - ELM_SEL_TARGETS, + ELM_SEL_FORMAT_TARGETS, targets_converter, response_handler_targets, notify_handler_targets, @@ -342,29 +342,29 @@ static Cnp_Atom atoms[CNP_N_ATOMS] = { }, }; -static Cnp_Selection selections[ELM_SEL_MAX] = { - ARRAYINIT(ELM_SEL_PRIMARY) { +static Cnp_Selection selections[ELM_SEL_TYPE_MAX] = { + ARRAYINIT(ELM_SEL_TYPE_PRIMARY) { .debug = "Primary", .ecore_sel = ECORE_X_SELECTION_PRIMARY, .set = ecore_x_selection_primary_set, .clear = ecore_x_selection_primary_clear, .request = ecore_x_selection_primary_request, }, - ARRAYINIT(ELM_SEL_SECONDARY) { + ARRAYINIT(ELM_SEL_TYPE_SECONDARY) { .debug = "Secondary", .ecore_sel = ECORE_X_SELECTION_SECONDARY, .set = ecore_x_selection_secondary_set, .clear = ecore_x_selection_secondary_clear, .request = ecore_x_selection_secondary_request, }, - ARRAYINIT(ELM_SEL_CLIPBOARD) { + ARRAYINIT(ELM_SEL_TYPE_CLIPBOARD) { .debug = "Clipboard", .ecore_sel = ECORE_X_SELECTION_CLIPBOARD, .set = ecore_x_selection_clipboard_set, .clear = ecore_x_selection_clipboard_clear, .request = ecore_x_selection_clipboard_request, }, - ARRAYINIT(ELM_SEL_XDND) { + ARRAYINIT(ELM_SEL_TYPE_XDND) { .debug = "XDnD", .ecore_sel = ECORE_X_SELECTION_XDND, .request = ecore_x_selection_xdnd_request, @@ -408,7 +408,8 @@ elm_selection_selection_has_owner(void) } Eina_Bool -elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format format, const char *selbuf) +elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *widget, + Elm_Sel_Format format, const void *selbuf, size_t buflen) { #ifdef HAVE_ELEMENTARY_X Evas_Object *top = elm_widget_top_get(widget); @@ -418,7 +419,8 @@ elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Forma if (top) xwin = elm_win_xwindow_get(top); else xwin = elm_win_xwindow_get(widget); if (!xwin) return EINA_FALSE; - if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE; + if ((unsigned int)selection >= (unsigned int)ELM_SEL_TYPE_MAX) + return EINA_FALSE; if (!_elm_cnp_init_count) _elm_cnp_init(); if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE)) return elm_cnp_selection_clear(selection, widget); @@ -430,7 +432,20 @@ elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Forma sel->set(xwin, &selection, sizeof(Elm_Sel_Type)); sel->format = format; - sel->selbuf = selbuf ? strdup(selbuf) : NULL; + + if (selbuf) + { + if (format == ELM_SEL_FORMAT_IMAGE) + { + sel->selbuf = malloc(buflen+1); + memcpy(sel->selbuf, selbuf, buflen); + } + else + sel->selbuf = strdup((char*)selbuf); + } + else + sel->selbuf = NULL; + return EINA_TRUE; #else @@ -444,7 +459,8 @@ elm_cnp_selection_clear(Elm_Sel_Type selection, Evas_Object *widget) #ifdef HAVE_ELEMENTARY_X Cnp_Selection *sel; - if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE; + if ((unsigned int)selection >= (unsigned int)ELM_SEL_TYPE_MAX) + return EINA_FALSE; if (!_elm_cnp_init_count) _elm_cnp_init(); sel = selections + selection; @@ -454,6 +470,9 @@ elm_cnp_selection_clear(Elm_Sel_Type selection, Evas_Object *widget) sel->active = EINA_FALSE; sel->widget = NULL; + if (sel->selbuf) + free(sel->selbuf); + sel->selbuf = NULL; sel->clear(); return EINA_TRUE; @@ -464,13 +483,14 @@ elm_cnp_selection_clear(Elm_Sel_Type selection, Evas_Object *widget) Eina_Bool elm_cnp_selection_get(Elm_Sel_Type selection, Elm_Sel_Format format, - Evas_Object *widget, Elm_Drop_Cb datacb, void *udata) + Evas_Object *widget, Elm_Drop_Cb datacb, void *udata) { #ifdef HAVE_ELEMENTARY_X Evas_Object *top; Cnp_Selection *sel; - if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE; + if ((unsigned int)selection >= (unsigned int)ELM_SEL_TYPE_MAX) + return EINA_FALSE; if (!_elm_cnp_init_count) _elm_cnp_init(); sel = selections + selection; @@ -518,17 +538,19 @@ selection_clear(void *udata __UNUSED__, int type __UNUSED__, void *event) Cnp_Selection *sel; int i; - for (i = 0; i < ELM_SEL_MAX; i++) + for (i = 0; i < ELM_SEL_TYPE_MAX; i++) { if (selections[i].ecore_sel == ev->selection) break; } cnp_debug("selection %d clear\n", i); /* Not me... Don't care */ - if (i == ELM_SEL_MAX) return ECORE_CALLBACK_PASS_ON; + if (i == ELM_SEL_TYPE_MAX) return ECORE_CALLBACK_PASS_ON; sel = selections + i; - sel->active = 0; + sel->active = EINA_FALSE; sel->widget = NULL; + if (sel->selbuf) + free(sel->selbuf); sel->selbuf = NULL; return ECORE_CALLBACK_PASS_ON; @@ -552,16 +574,16 @@ selection_notify(void *udata __UNUSED__, int type __UNUSED__, void *event) switch (ev->selection) { case ECORE_X_SELECTION_CLIPBOARD: - sel = selections + ELM_SEL_CLIPBOARD; + sel = selections + ELM_SEL_TYPE_CLIPBOARD; break; case ECORE_X_SELECTION_PRIMARY: - sel = selections + ELM_SEL_PRIMARY; + sel = selections + ELM_SEL_TYPE_PRIMARY; break; case ECORE_X_SELECTION_SECONDARY: - sel = selections + ELM_SEL_SECONDARY; + sel = selections + ELM_SEL_TYPE_SECONDARY; break; case ECORE_X_SELECTION_XDND: - sel = selections + ELM_SEL_XDND; + sel = selections + ELM_SEL_TYPE_XDND; break; default: return ECORE_CALLBACK_PASS_ON; @@ -595,7 +617,8 @@ _get_selection_type(void *data, int size) Cnp_Selection *sel; sel = selections + *((int *)data); if (sel->active && - (sel->format >= ELM_SEL_TARGETS) && (sel->format < ELM_SEL_FORMAT_MAX)) + (sel->format >= ELM_SEL_FORMAT_TARGETS) && + (sel->format < ELM_SEL_FORMAT_MAX)) return sel->format; } return ELM_SEL_FORMAT_NONE; @@ -876,7 +899,7 @@ vcard_receive(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify) data = notify->data; cnp_debug("vcard receive\n"); - if (sel == (selections + ELM_SEL_XDND)) + if (sel == (selections + ELM_SEL_TYPE_XDND)) { Elm_Selection_Data ddata; @@ -1372,9 +1395,9 @@ found: } cnp_debug("doing a request then\n"); - selections[ELM_SEL_XDND].requestwidget = dropable->obj; - selections[ELM_SEL_XDND].requestformat = ELM_SEL_FORMAT_MARKUP; - selections[ELM_SEL_XDND].active = EINA_TRUE; + selections[ELM_SEL_TYPE_XDND].requestwidget = dropable->obj; + selections[ELM_SEL_TYPE_XDND].requestformat = ELM_SEL_FORMAT_MARKUP; + selections[ELM_SEL_TYPE_XDND].active = EINA_TRUE; ecore_x_selection_xdnd_request(xwin, atoms[i].name); @@ -1545,7 +1568,7 @@ _drag_mouse_up(void *un __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void * ecore_x_dnd_drop(); if (dragdonecb) { - dragdonecb(dragdonecb,selections[ELM_SEL_XDND].widget); + dragdonecb(dragdonecb,selections[ELM_SEL_TYPE_XDND].widget); dragdonecb = NULL; } if (dragwin) @@ -1569,7 +1592,7 @@ elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data, void ( { Ecore_X_Window xwin; Cnp_Selection *sel; - Elm_Sel_Type xdnd = ELM_SEL_XDND; + Elm_Sel_Type xdnd = ELM_SEL_TYPE_XDND; Ecore_Evas *ee; int x, y, x2, y2, x3, y3; Evas_Object *icon; @@ -1582,7 +1605,7 @@ elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data, void ( cnp_debug("starting drag...\n"); ecore_x_dnd_type_set(xwin, "text/uri-list", 1); - sel = selections + ELM_SEL_XDND; + sel = selections + ELM_SEL_TYPE_XDND; sel->active = 1; sel->widget = obj; sel->format = format; diff --git a/src/lib/elm_entry.c b/src/lib/elm_entry.c index e7ca4e4..94c8921 100644 --- a/src/lib/elm_entry.c +++ b/src/lib/elm_entry.c @@ -1126,7 +1126,7 @@ _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) formats = ELM_SEL_FORMAT_MARKUP; if (!wd->textonly) formats |= ELM_SEL_FORMAT_IMAGE; - elm_cnp_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL); + elm_cnp_selection_get(ELM_SEL_TYPE_CLIPBOARD, formats, data, NULL, NULL); #endif } } @@ -1140,8 +1140,8 @@ _store_selection(Elm_Sel_Type seltype, Evas_Object *obj) if (!wd) return; sel = edje_object_part_text_selection_get(wd->ent, "elm.text"); if ((!sel) || (!sel[0])) return; /* avoid deleting our own selection */ - elm_cnp_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel); - if (seltype == ELM_SEL_CLIPBOARD) + elm_cnp_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel, strlen(sel)); + if (seltype == ELM_SEL_TYPE_CLIPBOARD) eina_stringshare_replace(&wd->cut_sel, sel); } @@ -1157,7 +1157,7 @@ _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm"); if (!_elm_config->desktop_entry) elm_widget_scroll_hold_pop(data); - _store_selection(ELM_SEL_CLIPBOARD, data); + _store_selection(ELM_SEL_TYPE_CLIPBOARD, data); edje_object_part_text_insert(wd->ent, "elm.text", ""); edje_object_part_text_select_none(wd->ent, "elm.text"); _sizing_eval(data); @@ -1175,7 +1175,7 @@ _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm"); elm_widget_scroll_hold_pop(data); } - _store_selection(ELM_SEL_CLIPBOARD, data); + _store_selection(ELM_SEL_TYPE_CLIPBOARD, data); // edje_object_part_text_select_none(wd->ent, "elm.text"); } @@ -1531,7 +1531,8 @@ _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emi top = elm_widget_top_get(data); if ((top) && (elm_win_xwindow_get(top))) - elm_cnp_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt); + elm_cnp_selection_set(ELM_SEL_TYPE_PRIMARY, data, + ELM_SEL_FORMAT_MARKUP, txt, strlen(txt)); } #endif } @@ -1559,7 +1560,7 @@ _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *e if (!wd) return; wd->have_selection = EINA_TRUE; evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL); - _store_selection(ELM_SEL_PRIMARY, data); + _store_selection(ELM_SEL_TYPE_PRIMARY, data); } static void @@ -1579,8 +1580,9 @@ _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *e top = elm_widget_top_get(data); if ((top) && (elm_win_xwindow_get(top))) - elm_cnp_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, - wd->cut_sel); + elm_cnp_selection_set(ELM_SEL_TYPE_PRIMARY, data, + ELM_SEL_FORMAT_MARKUP, wd->cut_sel, + strlen(wd->cut_sel)); #endif eina_stringshare_del(wd->cut_sel); wd->cut_sel = NULL; @@ -1592,7 +1594,7 @@ _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *e top = elm_widget_top_get(data); if ((top) && (elm_win_xwindow_get(top))) - elm_cnp_selection_clear(ELM_SEL_PRIMARY, data); + elm_cnp_selection_clear(ELM_SEL_TYPE_PRIMARY, data); #endif } } @@ -1602,7 +1604,8 @@ static void _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__) { Widget_Data *wd = elm_widget_data_get(data); - Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ? ELM_SEL_PRIMARY : ELM_SEL_CLIPBOARD; + Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ? + ELM_SEL_TYPE_PRIMARY : ELM_SEL_TYPE_CLIPBOARD; if (!wd) return; evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL); if (wd->sel_notify_handler) diff --git a/src/lib/elm_photo.c b/src/lib/elm_photo.c index 608cf0c..8a437bb 100644 --- a/src/lib/elm_photo.c +++ b/src/lib/elm_photo.c @@ -189,7 +189,8 @@ _longpress(void *objv) /* FIXME: Deal with relative paths */ buf = malloc(strlen(file) + strlen("file://") + 1); sprintf(buf, "%s%s","file://",file); - elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE, buf, _drag_done_cb, NULL); + elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE, + buf, _drag_done_cb, NULL); free(buf); } elm_object_scroll_freeze_push(objv); -- 2.7.4