summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-05-10 17:33:16 +0900
committerThiep Ha <thiepha@gmail.com>2015-06-02 21:50:24 +0900
commitf18cd3796eb3b66a849faddde98ea9ebb91982b9 (patch)
tree05362104c9d5abf16ccddfb88e3be187c8d8f86c
parent52e61b58cda08627ed7f086db7c60ba7620a62a8 (diff)
CnP/Wl: Add data notify handling for cnp
Data notify handlers support only drag & drop for now. This patch adds data notify handling for copy & paste also.
-rw-r--r--src/lib/elm_cnp.c257
1 files changed, 173 insertions, 84 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 2ef6f0b5f..b4453ad56 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -2945,28 +2945,50 @@ _wl_notify_handler_uri(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Read
2945 } 2945 }
2946 free(savedtypes.imgfile); 2946 free(savedtypes.imgfile);
2947 2947
2948 /* FIXME: this needs to be generic: Used for all receives */ 2948 if (ev->selection == ECORE_WL_SELECTION_DND)
2949 EINA_LIST_FOREACH(drops, l, dropable)
2950 { 2949 {
2951 if (dropable->obj == sel->requestwidget) break; 2950 /* FIXME: this needs to be generic: Used for all receives */
2951 EINA_LIST_FOREACH(drops, l, dropable)
2952 {
2953 if (dropable->obj == sel->requestwidget) break;
2954 }
2955 if (!dropable)
2956 {
2957 cnp_debug("Unable to find drop object");
2958 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2959 return 0;
2960 }
2961 dropable = eina_list_data_get(l);
2962 ddata.x = savedtypes.x;
2963 ddata.y = savedtypes.y;
2964 ddata.data = stripstr;
2965 ddata.len = strlen(stripstr);
2966 ddata.action = sel->action;
2967 ddata.format = sel->requestformat;
2968 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
2969 if ((cbs->types & dropable->last.format) && cbs->dropcb)
2970 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
2971 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2952 } 2972 }
2953 if (!dropable) 2973 else if (sel->datacb)
2954 { 2974 {
2955 cnp_debug("Unable to find drop object"); 2975 ddata.x = ddata.y = 0;
2956 ecore_wl_dnd_drag_end(ecore_wl_input_get()); 2976 ddata.format = ELM_SEL_FORMAT_MARKUP;
2957 return 0; 2977 ddata.data = stripstr;
2978 ddata.len = strlen(stripstr);
2979 ddata.action = sel->action;
2980 sel->datacb(sel->udata, sel->widget, &ddata);
2958 } 2981 }
2959 dropable = eina_list_data_get(l); 2982 else
2960 ddata.x = savedtypes.x; 2983 {
2961 ddata.y = savedtypes.y; 2984 char *mkupstr;
2962 ddata.data = stripstr; 2985
2963 ddata.len = strlen(stripstr); 2986 mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
2964 ddata.action = sel->action; 2987 /* TODO BUG: should never NEVER assume it's an elm_entry! */
2965 ddata.format = sel->requestformat; 2988 _elm_entry_entry_paste(sel->requestwidget, mkupstr);
2966 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs) 2989 free(mkupstr);
2967 if ((cbs->types & dropable->last.format) && cbs->dropcb) 2990 }
2968 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata); 2991
2969 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2970 return 0; 2992 return 0;
2971} 2993}
2972 2994
@@ -2976,36 +2998,50 @@ _wl_vcard_receive(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Ready *ev
2976 cnp_debug("In\n"); 2998 cnp_debug("In\n");
2977 return EINA_TRUE; 2999 return EINA_TRUE;
2978 3000
2979 Dropable *dropable;
2980 Eina_List *l;
2981
2982 cnp_debug("vcard receive\n");
2983 Dropable_Cbs *cbs;
2984 Eina_Inlist *itr;
2985 Elm_Selection_Data ddata; 3001 Elm_Selection_Data ddata;
2986 3002
2987 /* FIXME: this needs to be generic: Used for all receives */ 3003 if (ev->selection == ECORE_WL_SELECTION_DND)
2988 EINA_LIST_FOREACH(drops, l, dropable)
2989 { 3004 {
2990 if (dropable->obj == sel->requestwidget) break; 3005 Dropable *dropable;
3006 Eina_List *l;
3007 Dropable_Cbs *cbs;
3008 Eina_Inlist *itr;
3009 cnp_debug("vcard receive\n");
3010
3011 /* FIXME: this needs to be generic: Used for all receives */
3012 EINA_LIST_FOREACH(drops, l, dropable)
3013 {
3014 if (dropable->obj == sel->requestwidget) break;
3015 }
3016 if (!dropable)
3017 {
3018 cnp_debug("Unable to find drop object");
3019 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3020 return 0;
3021 }
3022 dropable = eina_list_data_get(l);
3023 ddata.x = savedtypes.x;
3024 ddata.y = savedtypes.y;
3025 ddata.format = ELM_SEL_FORMAT_VCARD;
3026 ddata.data = ev->data;
3027 ddata.len = ev->len;
3028 ddata.action = sel->action;
3029 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
3030 if ((cbs->types & dropable->last.format) && cbs->dropcb)
3031 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
3032 ecore_wl_dnd_drag_end(ecore_wl_input_get());
2991 } 3033 }
2992 if (!dropable) 3034 else if (sel->datacb)
2993 { 3035 {
2994 cnp_debug("Unable to find drop object"); 3036 ddata.x = ddata.y = 0;
2995 ecore_wl_dnd_drag_end(ecore_wl_input_get()); 3037 ddata.format = ELM_SEL_FORMAT_VCARD;
2996 return 0; 3038 ddata.data = ev->data;
3039 ddata.len = ev->len;
3040 ddata.action = sel->action;
3041 sel->datacb(sel->udata, sel->widget, &ddata);
2997 } 3042 }
2998 dropable = eina_list_data_get(l); 3043 else cnp_debug("Paste request\n");
2999 ddata.x = savedtypes.x; 3044
3000 ddata.y = savedtypes.y;
3001 ddata.format = ELM_SEL_FORMAT_VCARD;
3002 ddata.data = ev->data;
3003 ddata.len = ev->len;
3004 ddata.action = sel->action;
3005 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
3006 if ((cbs->types & dropable->last.format) && cbs->dropcb)
3007 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
3008 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3009 return 0; 3045 return 0;
3010} 3046}
3011 3047
@@ -3014,40 +3050,65 @@ _wl_notify_handler_image(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Re
3014{ 3050{
3015 cnp_debug("In\n"); 3051 cnp_debug("In\n");
3016 Tmp_Info *tmp; 3052 Tmp_Info *tmp;
3017 Eina_List *l;
3018 Dropable *dropable;
3019
3020 Elm_Selection_Data ddata; 3053 Elm_Selection_Data ddata;
3021 3054
3022 tmp = _tempfile_new(ev->len); 3055 if (ev->selection == ECORE_WL_SELECTION_DND)
3023 if (!tmp) goto end;
3024 memcpy(tmp->map, ev->data, ev->len);
3025 munmap(tmp->map, ev->len);
3026
3027 /* FIXME: this needs to be generic: Used for all receives */
3028 EINA_LIST_FOREACH(drops, l, dropable)
3029 { 3056 {
3030 if (dropable->obj == sel->requestwidget) break; 3057 Eina_List *l;
3031 dropable = NULL; 3058 Dropable *dropable;
3059
3060 tmp = _tempfile_new(ev->len);
3061 if (!tmp)
3062 {
3063 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3064 return 0;
3065 }
3066 memcpy(tmp->map, ev->data, ev->len);
3067 munmap(tmp->map, ev->len);
3068 /* FIXME: this needs to be generic: Used for all receives */
3069 EINA_LIST_FOREACH(drops, l, dropable)
3070 {
3071 if (dropable->obj == sel->requestwidget) break;
3072 dropable = NULL;
3073 }
3074 if (dropable)
3075 {
3076 Dropable_Cbs *cbs;
3077 Eina_Inlist *itr;
3078 ddata.x = savedtypes.x;
3079 ddata.y = savedtypes.y;
3080 ddata.format = ELM_SEL_FORMAT_IMAGE;
3081 ddata.data = tmp->filename;
3082 ddata.len = strlen(tmp->filename);
3083 ddata.action = sel->action;
3084 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
3085 if ((cbs->types & dropable->last.format) && cbs->dropcb)
3086 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
3087 }
3088 _tmpinfo_free(tmp);
3089 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3032 } 3090 }
3033 if (dropable) 3091 else if (sel->datacb)
3034 { 3092 {
3035 Dropable_Cbs *cbs; 3093 ddata.x = ddata.y = 0;
3036 Eina_Inlist *itr;
3037 ddata.x = savedtypes.x;
3038 ddata.y = savedtypes.y;
3039 ddata.format = ELM_SEL_FORMAT_IMAGE; 3094 ddata.format = ELM_SEL_FORMAT_IMAGE;
3040 ddata.data = tmp->filename; 3095 ddata.data = ev->data;
3041 ddata.len = strlen(tmp->filename); 3096 ddata.len = ev->len;
3042 ddata.action = sel->action; 3097 ddata.action = sel->action;
3043 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs) 3098 sel->datacb(sel->udata, sel->widget, &ddata);
3044 if ((cbs->types & dropable->last.format) && cbs->dropcb) 3099 }
3045 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata); 3100 else
3101 {
3102 cnp_debug("no datacb\n");
3103 tmp = _tempfile_new(ev->len);
3104 if (!tmp) return 0;
3105 memcpy(tmp->map, ev->data, ev->len);
3106 munmap(tmp->map, ev->len);
3107 /* FIXME: Add to paste image data to clean up */
3108 _pasteimage_append(tmp->filename, sel->requestwidget);
3109 _tmpinfo_free(tmp);
3046 } 3110 }
3047 _tmpinfo_free(tmp);
3048 3111
3049end:
3050 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3051 return 0; 3112 return 0;
3052} 3113}
3053 3114
@@ -3056,33 +3117,61 @@ _wl_notify_handler_text(Wl_Cnp_Selection *sel, Ecore_Wl_Event_Selection_Data_Rea
3056{ 3117{
3057 cnp_debug("In\n"); 3118 cnp_debug("In\n");
3058 3119
3059 Eina_List *l;
3060 Dropable *dropable;
3061
3062 Elm_Selection_Data ddata; 3120 Elm_Selection_Data ddata;
3063 3121
3064 cnp_debug("drag & drop\n"); 3122 if (ev->selection == ECORE_WL_SELECTION_DND)
3065 /* FIXME: this needs to be generic: Used for all receives */
3066 EINA_LIST_FOREACH(drops, l, dropable)
3067 { 3123 {
3068 if (dropable->obj == sel->requestwidget) break; 3124 Eina_List *l;
3069 dropable = NULL; 3125 Dropable *dropable;
3126
3127 cnp_debug("drag & drop\n");
3128 /* FIXME: this needs to be generic: Used for all receives */
3129 EINA_LIST_FOREACH(drops, l, dropable)
3130 {
3131 if (dropable->obj == sel->requestwidget) break;
3132 dropable = NULL;
3133 }
3134 if (dropable)
3135 {
3136 Dropable_Cbs *cbs;
3137 Eina_Inlist *itr;
3138 ddata.x = savedtypes.x;
3139 ddata.y = savedtypes.y;
3140 ddata.format = ELM_SEL_FORMAT_TEXT;
3141 ddata.data = ev->data;
3142 ddata.len = ev->len;
3143 ddata.action = sel->action;
3144 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
3145 if ((cbs->types & dropable->last.format) && cbs->dropcb)
3146 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
3147 }
3148 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3070 } 3149 }
3071 if (dropable) 3150 else if (sel->datacb)
3072 { 3151 {
3073 Dropable_Cbs *cbs; 3152 ddata.x = ddata.y = 0;
3074 Eina_Inlist *itr;
3075 ddata.x = savedtypes.x;
3076 ddata.y = savedtypes.y;
3077 ddata.format = ELM_SEL_FORMAT_TEXT; 3153 ddata.format = ELM_SEL_FORMAT_TEXT;
3078 ddata.data = ev->data; 3154 ddata.data = ev->data;
3079 ddata.len = ev->len; 3155 ddata.len = ev->len;
3080 ddata.action = sel->action; 3156 ddata.action = sel->action;
3081 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs) 3157 sel->datacb(sel->udata, sel->widget, &ddata);
3082 if ((cbs->types & dropable->last.format) && cbs->dropcb)
3083 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
3084 } 3158 }
3085 ecore_wl_dnd_drag_end(ecore_wl_input_get()); 3159 else
3160 {
3161 cnp_debug("no datacb\n");
3162 char *stripstr, *mkupstr;
3163
3164 stripstr = malloc(ev->len + 1);
3165 if (!stripstr) return 0;
3166 strncpy(stripstr, (char *)ev->data, ev->len);
3167 stripstr[ev->len] = '\0';
3168 mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
3169 /* TODO BUG: should never NEVER assume it's an elm_entry! */
3170 _elm_entry_entry_paste(sel->requestwidget, mkupstr);
3171 free(stripstr);
3172 free(mkupstr);
3173 }
3174
3086 return 0; 3175 return 0;
3087} 3176}
3088 3177