summaryrefslogtreecommitdiff
path: root/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2020-02-14 14:09:21 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2020-03-08 10:59:43 +0100
commit06b793351274db94149a3199211d26e9a3e1fee2 (patch)
tree4a88e927cbe3b9b9ebb976307054d6e46d1bbea4 /src/lib/ecore_cocoa/ecore_cocoa_cnp.m
parent165f6f0ae285dd495547eb3dbca521ce2cfc184e (diff)
ecore_cocoa: change clipboard API
the new API works with mimetypes, so we can remove the cnp types from Ecore_Cocoa.h and just forward the types from ecore_evas directly Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D11350
Diffstat (limited to '')
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_cnp.m61
1 files changed, 30 insertions, 31 deletions
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_cnp.m b/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
index c5fd22e99d..fabfc8c5a5 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
@@ -9,16 +9,17 @@
9#import "ecore_cocoa_app.h" 9#import "ecore_cocoa_app.h"
10 10
11EAPI Eina_Bool 11EAPI Eina_Bool
12ecore_cocoa_clipboard_set(const void *data, 12ecore_cocoa_clipboard_set(const void *data,
13 int size, 13 int size,
14 Ecore_Cocoa_Cnp_Type type) 14 const char *raw_mime_type)
15{ 15{
16 NSMutableArray *objects; 16 NSMutableArray *objects;
17 NSString *str = nil; 17 NSString *str = nil;
18 BOOL ok = YES; 18 BOOL ok = YES;
19 NSString *mime_type = [NSString stringWithUTF8String:raw_mime_type];
19 20
20 objects = [[NSMutableArray alloc] init]; 21 objects = [[NSMutableArray alloc] init];
21 if (type & ECORE_COCOA_CNP_TYPE_STRING) 22 if ([mime_type hasPrefix:@"text/"])
22 { 23 {
23 str = [[NSString alloc] initWithBytes: data 24 str = [[NSString alloc] initWithBytes: data
24 length: size 25 length: size
@@ -26,18 +27,9 @@ ecore_cocoa_clipboard_set(const void *data,
26 if (str) 27 if (str)
27 [objects addObject: str]; 28 [objects addObject: str];
28 } 29 }
29 if (type & ECORE_COCOA_CNP_TYPE_MARKUP) 30 else
30 { 31 {
31 WRN("Markup CNP: NOT IMPLEMENTED"); 32 ERR("Mimetype %s is not handled yet", raw_mime_type);
32 }
33
34 if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
35 {
36 WRN("Image CNP: NOT IMPLEMENTED");
37 }
38 if (type & ECORE_COCOA_CNP_TYPE_HTML)
39 {
40 WRN("HTML CNP: NOT IMPLEMENTED");
41 } 33 }
42 34
43 /* Write to pasteboard */ 35 /* Write to pasteboard */
@@ -54,35 +46,45 @@ ecore_cocoa_clipboard_set(const void *data,
54 return (ok) ? EINA_TRUE : EINA_FALSE; 46 return (ok) ? EINA_TRUE : EINA_FALSE;
55} 47}
56 48
49EAPI Eina_Bool
50ecore_cocoa_clipboard_exists(void)
51{
52 NSDictionary *options;
53 NSPasteboard *pb;
54 NSArray *items;
55 NSMutableArray *classes;
56
57 classes = [[NSMutableArray alloc] init];
58 [classes addObject: [NSString class]]; // we only support strings for now
59 pb = [NSPasteboard generalPasteboard];
60 options = [NSDictionary dictionary];
61 return [pb canReadItemWithDataConformingToTypes: classes];
62}
57 63
58EAPI void * 64EAPI void *
59ecore_cocoa_clipboard_get(int *size, 65ecore_cocoa_clipboard_get(int *size,
60 Ecore_Cocoa_Cnp_Type type, 66 const char *raw_mime_type)
61 Ecore_Cocoa_Cnp_Type *retrieved_types)
62{ 67{
63 NSMutableArray *classes; 68 NSMutableArray *classes;
64 void *data; 69 void *data = NULL;
65 NSDictionary *options; 70 NSDictionary *options;
66 NSPasteboard *pb; 71 NSPasteboard *pb;
67 NSArray *items; 72 NSArray *items;
68 unsigned int len; 73 unsigned int len;
69 BOOL string_class = NO; 74 BOOL string_class = NO;
70 Ecore_Cocoa_Cnp_Type types = 0; 75 NSString *mime_type = [NSString stringWithUTF8String:raw_mime_type];
71 76
72 classes = [[NSMutableArray alloc] init]; 77 classes = [[NSMutableArray alloc] init];
73 78
74 if (type & ECORE_COCOA_CNP_TYPE_STRING) 79 if ([mime_type hasPrefix:@"text/"])
75 { 80 {
76 string_class = YES; 81 string_class = YES;
77 [classes addObject: [NSString class]]; 82 [classes addObject: [NSString class]];
78 } 83 }
79 if (type & ECORE_COCOA_CNP_TYPE_IMAGE) 84 else
80 {
81 WRN("Image CNP: NOT IMPLEMENTED");
82 }
83 if (type & ECORE_COCOA_CNP_TYPE_HTML)
84 { 85 {
85 WRN("HTML CNP: NOT IMPLEMENTED"); 86 ERR("Mimetype %s is not handled yet", raw_mime_type);
87 goto fail;
86 } 88 }
87 89
88 if ([classes count] <= 0) 90 if ([classes count] <= 0)
@@ -120,7 +122,6 @@ ecore_cocoa_clipboard_get(int *size,
120 (const char *)data, len); 122 (const char *)data, len);
121 goto remove_fail; 123 goto remove_fail;
122 } 124 }
123 types |= ECORE_COCOA_CNP_TYPE_STRING;
124 125
125#if 0 126#if 0
126 if (type & ECORE_COCOA_CNP_TYPE_MARKUP) 127 if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
@@ -139,7 +140,7 @@ ecore_cocoa_clipboard_get(int *size,
139#endif 140#endif
140 } 141 }
141 142
142 if (!types) 143 if (!data)
143 { 144 {
144 ERR("No types retrieved!"); 145 ERR("No types retrieved!");
145 goto remove_fail; 146 goto remove_fail;
@@ -148,14 +149,12 @@ ecore_cocoa_clipboard_get(int *size,
148 [classes removeAllObjects]; 149 [classes removeAllObjects];
149 150
150 if (size) *size = len; 151 if (size) *size = len;
151 if (retrieved_types) *retrieved_types = types;
152 return data; 152 return data;
153 153
154remove_fail: 154remove_fail:
155 [classes removeAllObjects]; 155 [classes removeAllObjects];
156fail: 156fail:
157 if (size) *size = 0; 157 if (size) *size = 0;
158 if (retrieved_types) *retrieved_types = 0;
159 return NULL; 158 return NULL;
160} 159}
161 160