summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2015-10-09 17:18:03 +0200
committerNicolas Aguirre <aguirre.nicolas@gmail.com>2015-11-10 08:32:49 +0100
commit825e316ac55eb9b2e261012d0dfd1a7cc97571d3 (patch)
tree83e8ece9055dd4871f995101954250a30902b53a
parentc7a482f8a3375fea00fcbabcda12b5ed3488c454 (diff)
ecore_cocoa: copy and paste support
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile_Ecore_Cocoa.am1
-rw-r--r--src/lib/ecore_cocoa/Ecore_Cocoa.h32
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa.m7
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_cnp.m176
5 files changed, 217 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index f0980adf7b..5de251ebcf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2807,6 +2807,8 @@ EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [ecore-input])
2807EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [ecore]) 2807EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [ecore])
2808EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eo]) 2808EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eo])
2809EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eina]) 2809EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eina])
2810EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [evas])
2811EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [emile])
2810 2812
2811### Checks for header files 2813### Checks for header files
2812 2814
diff --git a/src/Makefile_Ecore_Cocoa.am b/src/Makefile_Ecore_Cocoa.am
index a158767380..9b5ab544b1 100644
--- a/src/Makefile_Ecore_Cocoa.am
+++ b/src/Makefile_Ecore_Cocoa.am
@@ -14,6 +14,7 @@ lib_ecore_cocoa_libecore_cocoa_la_SOURCES = \
14lib/ecore_cocoa/ecore_cocoa.m \ 14lib/ecore_cocoa/ecore_cocoa.m \
15lib/ecore_cocoa/ecore_cocoa_window.h \ 15lib/ecore_cocoa/ecore_cocoa_window.h \
16lib/ecore_cocoa/ecore_cocoa_window.m \ 16lib/ecore_cocoa/ecore_cocoa_window.m \
17lib/ecore_cocoa/ecore_cocoa_cnp.m \
17lib/ecore_cocoa/ecore_cocoa_app.m \ 18lib/ecore_cocoa/ecore_cocoa_app.m \
18lib/ecore_cocoa/ecore_cocoa_app.h \ 19lib/ecore_cocoa/ecore_cocoa_app.h \
19lib/ecore_cocoa/ecore_cocoa_private.h 20lib/ecore_cocoa/ecore_cocoa_private.h
diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa.h b/src/lib/ecore_cocoa/Ecore_Cocoa.h
index 84a69a87d2..caae2d0741 100644
--- a/src/lib/ecore_cocoa/Ecore_Cocoa.h
+++ b/src/lib/ecore_cocoa/Ecore_Cocoa.h
@@ -40,6 +40,8 @@ EAPI extern int ECORE_COCOA_EVENT_LOST_FOCUS;
40EAPI extern int ECORE_COCOA_EVENT_RESIZE; 40EAPI extern int ECORE_COCOA_EVENT_RESIZE;
41EAPI extern int ECORE_COCOA_EVENT_EXPOSE; 41EAPI extern int ECORE_COCOA_EVENT_EXPOSE;
42EAPI extern int ECORE_COCOA_EVENT_WINDOW_DESTROY; 42EAPI extern int ECORE_COCOA_EVENT_WINDOW_DESTROY;
43EAPI extern int ECORE_COCOA_EVENT_DATA_SOURCE_SEND;
44EAPI extern int ECORE_COCOA_EVENT_SELECTION_DATA_READY;
43 45
44typedef void * Ecore_Cocoa_Window_Id; 46typedef void * Ecore_Cocoa_Window_Id;
45typedef struct _Ecore_Cocoa_Event_Video_Resize Ecore_Cocoa_Event_Video_Resize; 47typedef struct _Ecore_Cocoa_Event_Video_Resize Ecore_Cocoa_Event_Video_Resize;
@@ -61,6 +63,15 @@ struct _Ecore_Cocoa_Screen
61 int dummy; 63 int dummy;
62}; 64};
63 65
66typedef enum
67{
68 ECORE_COCOA_CNP_TYPE_UNKNOWN = 0,
69 ECORE_COCOA_CNP_TYPE_STRING = (1 << 0),
70 ECORE_COCOA_CNP_TYPE_MARKUP = (1 << 1),
71 ECORE_COCOA_CNP_TYPE_IMAGE = (1 << 2),
72 ECORE_COCOA_CNP_TYPE_HTML = (1 << 3)
73} Ecore_Cocoa_Cnp_Type;
74
64/* Core */ 75/* Core */
65 76
66EAPI int ecore_cocoa_init(void); 77EAPI int ecore_cocoa_init(void);
@@ -167,6 +178,27 @@ EAPI int ecore_cocoa_titlebar_height_get(void);
167EAPI Ecore_Cocoa_Window_Id ecore_cocoa_window_get_window_id(const Ecore_Cocoa_Window *window); 178EAPI Ecore_Cocoa_Window_Id ecore_cocoa_window_get_window_id(const Ecore_Cocoa_Window *window);
168 179
169 180
181
182/**
183 * @return false on error, true otherwise
184 *
185 * @ingroup Ecore_Cocoa_Cpn_Group
186 */
187EAPI Eina_Bool ecore_cocoa_selection_clipboard_set(const void *data, int size, Ecore_Cocoa_Cnp_Type type);
188
189/**
190 * @return false if type not found or on error, true otherwise
191 *
192 * @ingroup Ecore_Cocoa_Cnp_Group
193 */
194EAPI void *ecore_cocoa_selection_clipboard_get(int *size, Ecore_Cocoa_Cnp_Type type,
195 Ecore_Cocoa_Cnp_Type *retrieved_types);
196
197/**
198 * @ingroup Ecore_Cocoa_Cnp_Group
199 */
200EAPI void ecore_cocoa_selection_clipboard_clear(void);
201
170EAPI void ecore_cocoa_window_cursor_set(Ecore_Cocoa_Window *win, Ecore_Cocoa_Cursor c); 202EAPI void ecore_cocoa_window_cursor_set(Ecore_Cocoa_Window *win, Ecore_Cocoa_Cursor c);
171EAPI void ecore_cocoa_window_cursor_show(Ecore_Cocoa_Window *win, Eina_Bool show); 203EAPI void ecore_cocoa_window_cursor_show(Ecore_Cocoa_Window *win, Eina_Bool show);
172 204
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m
index 84ee03bf2c..d2acc20c86 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa.m
@@ -20,6 +20,8 @@ EAPI int ECORE_COCOA_EVENT_LOST_FOCUS = 0;
20EAPI int ECORE_COCOA_EVENT_RESIZE = 0; 20EAPI int ECORE_COCOA_EVENT_RESIZE = 0;
21EAPI int ECORE_COCOA_EVENT_EXPOSE = 0; 21EAPI int ECORE_COCOA_EVENT_EXPOSE = 0;
22EAPI int ECORE_COCOA_EVENT_WINDOW_DESTROY = 0; 22EAPI int ECORE_COCOA_EVENT_WINDOW_DESTROY = 0;
23EAPI int ECORE_COCOA_EVENT_DATA_SOURCE_SEND = 0;
24EAPI int ECORE_COCOA_EVENT_SELECTION_DATA_READY = 0;
23 25
24static int _ecore_cocoa_init_count = 0; 26static int _ecore_cocoa_init_count = 0;
25 27
@@ -47,12 +49,15 @@ ecore_cocoa_init(void)
47 } 49 }
48 50
49 DBG(""); 51 DBG("");
50 52
51 ECORE_COCOA_EVENT_GOT_FOCUS = ecore_event_type_new(); 53 ECORE_COCOA_EVENT_GOT_FOCUS = ecore_event_type_new();
52 ECORE_COCOA_EVENT_LOST_FOCUS = ecore_event_type_new(); 54 ECORE_COCOA_EVENT_LOST_FOCUS = ecore_event_type_new();
53 ECORE_COCOA_EVENT_RESIZE = ecore_event_type_new(); 55 ECORE_COCOA_EVENT_RESIZE = ecore_event_type_new();
54 ECORE_COCOA_EVENT_EXPOSE = ecore_event_type_new(); 56 ECORE_COCOA_EVENT_EXPOSE = ecore_event_type_new();
55 ECORE_COCOA_EVENT_WINDOW_DESTROY = ecore_event_type_new(); 57 ECORE_COCOA_EVENT_WINDOW_DESTROY = ecore_event_type_new();
58 ECORE_COCOA_EVENT_DATA_SOURCE_SEND = ecore_event_type_new();
59 ECORE_COCOA_EVENT_SELECTION_DATA_READY = ecore_event_type_new();
60
56 61
57 /* Init the Application handler */ 62 /* Init the Application handler */
58 [Ecore_Cocoa_Application sharedApplication]; 63 [Ecore_Cocoa_Application sharedApplication];
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_cnp.m b/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
new file mode 100644
index 0000000000..f5b0571cbf
--- /dev/null
+++ b/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
@@ -0,0 +1,176 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Eina.h>
6#include <Evas.h>
7#import <Cocoa/Cocoa.h>
8#import "ecore_cocoa_window.h"
9#include "ecore_cocoa_private.h"
10#import "ecore_cocoa_app.h"
11
12EAPI Eina_Bool
13ecore_cocoa_selection_clipboard_set(const void *data,
14 int size,
15 Ecore_Cocoa_Cnp_Type type)
16{
17 static NSMutableArray *objects = nil;
18 NSPasteboard *pb;
19 NSString *str = nil;
20 BOOL ok = YES;
21
22 if (!objects)
23 objects = [[NSMutableArray alloc] init];
24
25 pb = [NSPasteboard generalPasteboard];
26 [pb clearContents];
27
28 if (type & ECORE_COCOA_CNP_TYPE_STRING)
29 {
30 str = [[NSString alloc] initWithBytes: data
31 length: size
32 encoding: NSUTF8StringEncoding];
33 [objects addObject: str];
34 }
35 if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
36 {
37 char *utf8;
38
39 utf8 = evas_textblock_text_markup_to_utf8(NULL, (const char *)data);
40 str = [[NSString alloc] initWithBytes: utf8
41 length: strlen(utf8) // XXX strlen() ?
42 encoding: NSUTF8StringEncoding];
43 free(utf8);
44 [objects addObject: str];
45 }
46 if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
47 {
48 WRN("Image CNP: NOT IMPLEMENTED");
49 }
50 if (type & ECORE_COCOA_CNP_TYPE_HTML)
51 {
52 WRN("HTML CNP: NOT IMPLEMENTED");
53 }
54
55
56 /* Write to pasteboard */
57 if ([objects count] > 0)
58 {
59 ok = [pb writeObjects: objects];
60 [objects removeAllObjects];
61 }
62
63 return (ok) ? EINA_TRUE : EINA_FALSE;
64}
65
66
67EAPI void *
68ecore_cocoa_selection_clipboard_get(int *size,
69 Ecore_Cocoa_Cnp_Type type,
70 Ecore_Cocoa_Cnp_Type *retrieved_types)
71{
72 static NSMutableArray *classes = nil;
73 void *data;
74 NSDictionary *options;
75 NSPasteboard *pb;
76 NSArray *items;
77 unsigned int len;
78 BOOL string_class = NO;
79 Ecore_Cocoa_Cnp_Type types = 0;
80
81 if (!classes)
82 classes = [[NSMutableArray alloc] init];
83
84 if ((type & ECORE_COCOA_CNP_TYPE_STRING) ||
85 (type & ECORE_COCOA_CNP_TYPE_MARKUP))
86 {
87 string_class = YES;
88 [classes addObject: [NSString class]];
89 }
90 if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
91 {
92 WRN("Image CNP: NOT IMPLEMENTED");
93 }
94 if (type & ECORE_COCOA_CNP_TYPE_HTML)
95 {
96 WRN("HTML CNP: NOT IMPLEMENTED");
97 }
98
99 if ([classes count] <= 0)
100 {
101 ERR("No registered classes... got nothing from pasteboard");
102 goto fail;
103 }
104
105 pb = [NSPasteboard generalPasteboard];
106 options = [NSDictionary dictionary];
107 items = [pb readObjectsForClasses: classes
108 options: options];
109 if (!items)
110 {
111 ERR("No items in the clipboard");
112 goto remove_fail;
113 }
114 if ([items count] != 1)
115 {
116 ERR("%lu items in pasteboard. Only one at the time can be handled",
117 [items count]);
118 goto fail;
119 }
120
121 if (string_class)
122 {
123 NSString *str = [items objectAtIndex: 0];
124 data = (void *)[str UTF8String];
125 len = [str lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
126 data = strndup((const char *)data, len);
127
128 if (EINA_UNLIKELY(!data))
129 {
130 CRI("Failed to strndup() string \"%s\" (len: %u)",
131 (const char *)data, len);
132 goto remove_fail;
133 }
134 types |= ECORE_COCOA_CNP_TYPE_STRING;
135
136// if (type & ECORE_COCOA_CNP_TYPE_MARKUP)
137// {
138// char *markup;
139// markup = evas_textblock_text_utf8_to_markup(NULL, data);
140// free(data);
141// data = markup;
142// if (EINA_UNLIKELY(!data))
143// {
144// CRI("Failed to retrieve markup from UTF8");
145// goto remove_fail;
146// }
147// len = strlen(markup);
148// }
149 }
150
151 if (!types)
152 {
153 ERR("No types retrieved!");
154 goto remove_fail;
155 }
156
157 [classes removeAllObjects];
158
159 if (size) *size = len;
160 if (retrieved_types) *retrieved_types = types;
161 return data;
162
163remove_fail:
164 [classes removeAllObjects];
165fail:
166 if (size) *size = 0;
167 if (retrieved_types) *retrieved_types = 0;
168 return NULL;
169}
170
171EAPI void
172ecore_cocoa_selection_clipboard_clear(void)
173{
174 [[NSPasteboard generalPasteboard] clearContents];
175}
176