summaryrefslogtreecommitdiff
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-04 17:26:30 +0100
commit072a5fa525c53aad58c42e4f1c8a25acc4ed4501 (patch)
tree3b89e94a6ecd8dcf0da80fc918fe54ef0330e343
parent87901ea2ffda3ef0becde28c306b4208531cc1a1 (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 Differential Revision: https://phab.enlightenment.org/D11350
-rw-r--r--src/lib/ecore_cocoa/Ecore_Cocoa.h36
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_cnp.m63
2 files changed, 41 insertions, 58 deletions
diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa.h b/src/lib/ecore_cocoa/Ecore_Cocoa.h
index 36f17b490b..ca0a835be2 100644
--- a/src/lib/ecore_cocoa/Ecore_Cocoa.h
+++ b/src/lib/ecore_cocoa/Ecore_Cocoa.h
@@ -196,22 +196,6 @@ struct _Ecore_Cocoa_Event_Window_Destroy
196 Ecore_Cocoa_Object *cocoa_window; /**< Handler of the Cocoa window */ 196 Ecore_Cocoa_Object *cocoa_window; /**< Handler of the Cocoa window */
197}; 197};
198 198
199/**
200 * @typedef Ecore_Cocoa_Cnp_Type
201 * Type used to interact with the Cocoa pasteboard.
202 * It holds types that can apply to a context.
203 * @since 1.18
204 */
205typedef enum
206{
207 ECORE_COCOA_CNP_TYPE_UNKNOWN = 0, /**< Undefined type */
208 ECORE_COCOA_CNP_TYPE_STRING = (1 << 0), /**< String type (pure text) */
209 ECORE_COCOA_CNP_TYPE_MARKUP = (1 << 1), /**< Elementary markup */
210 ECORE_COCOA_CNP_TYPE_IMAGE = (1 << 2), /**< Image (all formats) */
211 ECORE_COCOA_CNP_TYPE_HTML = (1 << 3) /**< HTML */
212} Ecore_Cocoa_Cnp_Type;
213
214
215/*============================================================================* 199/*============================================================================*
216 * Core * 200 * Core *
217 *============================================================================*/ 201 *============================================================================*/
@@ -561,27 +545,22 @@ EAPI void ecore_cocoa_terminate_cb_set(Ecore_Cocoa_Terminate_Cb cb)
561 * Sets the clipboard of Cocoa (NSPasteboard) 545 * Sets the clipboard of Cocoa (NSPasteboard)
562 * @param data The contents to be set in the clipboard 546 * @param data The contents to be set in the clipboard
563 * @param size The size in bytes of @c data 547 * @param size The size in bytes of @c data
564 * @param type 548 * @param mine_type
565 * @return EINA_TRUE on success, EINA_FALSE on failure 549 * @return EINA_TRUE on success, EINA_FALSE on failure
566 */ 550 */
567EAPI Eina_Bool ecore_cocoa_clipboard_set(const void *data, 551EAPI Eina_Bool ecore_cocoa_clipboard_set(const void *data,
568 int size, 552 int size,
569 Ecore_Cocoa_Cnp_Type type); 553 const char *mime_type);
570 554
571/* 555/*
572 * Gets the contents of the Cocoa clipboard 556 * Gets the contents of the Cocoa clipboard
573 * @param size Pointer used to retrieve the size of the received contents 557 * @param size Pointer used to retrieve the size of the received contents
574 * @param type The type of object to retrieve from the clipboard 558 * @param mine_type The type of object to retrieve from the clipboard
575 * @param retrieved_types The types of objects retrieved from the clipboard
576 * @return The data retrieved from the clipboard. NULL on failure 559 * @return The data retrieved from the clipboard. NULL on failure
577 * 560 *
578 * If @c type was ECORE_COCOA_CNP_TYPE_STRING or ECORE_COCOA_CNP_TYPE_MARKUP,
579 * @c retrieved_types will contain ECORE_COCOA_CNP_TYPE_STRING and the data
580 * will be a C string (char*) that must be freed after use.
581 */ 561 */
582EAPI void *ecore_cocoa_clipboard_get(int *size, 562EAPI void *ecore_cocoa_clipboard_get(int *size,
583 Ecore_Cocoa_Cnp_Type type, 563 const char *mime_type)
584 Ecore_Cocoa_Cnp_Type *retrieved_types)
585 EINA_WARN_UNUSED_RESULT; 564 EINA_WARN_UNUSED_RESULT;
586 565
587/* 566/*
@@ -589,6 +568,11 @@ EAPI void *ecore_cocoa_clipboard_get(int *size,
589 */ 568 */
590EAPI void ecore_cocoa_clipboard_clear(void); 569EAPI void ecore_cocoa_clipboard_clear(void);
591 570
571/*
572 * Returns true when the clipboard contains data that can be received.
573 */
574EAPI Eina_Bool ecore_cocoa_clipboard_exists(void);
575
592#endif /* EFL_BETA_API_SUPPORT */ 576#endif /* EFL_BETA_API_SUPPORT */
593 577
594#ifdef __cplusplus 578#ifdef __cplusplus
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_cnp.m b/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
index c5fd22e99d..34adfac80e 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)
@@ -112,7 +114,7 @@ ecore_cocoa_clipboard_get(int *size,
112 NSString *str = [items objectAtIndex: 0]; 114 NSString *str = [items objectAtIndex: 0];
113 data = (void *)[str UTF8String]; 115 data = (void *)[str UTF8String];
114 len = [str lengthOfBytesUsingEncoding: NSUTF8StringEncoding]; 116 len = [str lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
115 data = eina_strndup((const char *)data, len); 117 data = strndup((const char *)data, len);
116 118
117 if (EINA_UNLIKELY(!data)) 119 if (EINA_UNLIKELY(!data))
118 { 120 {
@@ -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