summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2015-10-09 17:18:03 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-12-01 12:15:31 -0800
commit3d5f1817e63c40764cd3752c1036b35c598b74fe (patch)
treef7061657094441075df8ae73279b93b390742411
parent8182fc38cbeac575af815b816df0bd9bb78fb219 (diff)
ecore_cocoa: copy and paste support
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-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 fe86264..0758c7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2843,6 +2843,8 @@ EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [ecore-input])
2843EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [ecore]) 2843EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [ecore])
2844EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eo]) 2844EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eo])
2845EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eina]) 2845EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [eina])
2846EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [evas])
2847EFL_INTERNAL_DEPEND_PKG([ECORE_COCOA], [emile])
2846 2848
2847### Checks for header files 2849### Checks for header files
2848 2850
diff --git a/src/Makefile_Ecore_Cocoa.am b/src/Makefile_Ecore_Cocoa.am
index a158767..9b5ab54 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 84a69a8..caae2d0 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 84ee03b..d2acc20 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 0000000..f94dfe9
--- /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 /* Write to pasteboard */
56 if ([objects count] > 0)
57 {
58 ok = [pb writeObjects: objects];
59 [objects removeAllObjects];
60 }
61
62 return (ok) ? EINA_TRUE : EINA_FALSE;
63}
64
65
66EAPI void *
67ecore_cocoa_selection_clipboard_get(int *size,
68 Ecore_Cocoa_Cnp_Type type,
69 Ecore_Cocoa_Cnp_Type *retrieved_types)
70{
71 static NSMutableArray *classes = nil;
72 void *data;
73 NSDictionary *options;
74 NSPasteboard *pb;
75 NSArray *items;
76 unsigned int len;
77 BOOL string_class = NO;
78 Ecore_Cocoa_Cnp_Type types = 0;
79
80 if (!classes)
81 classes = [[NSMutableArray alloc] init];
82
83 if ((type & ECORE_COCOA_CNP_TYPE_STRING) ||
84 (type & ECORE_COCOA_CNP_TYPE_MARKUP))
85 {
86 string_class = YES;
87 [classes addObject: [NSString class]];
88 }
89 if (type & ECORE_COCOA_CNP_TYPE_IMAGE)
90 {
91 WRN("Image CNP: NOT IMPLEMENTED");
92 }
93 if (type & ECORE_COCOA_CNP_TYPE_HTML)
94 {
95 WRN("HTML CNP: NOT IMPLEMENTED");
96 }
97
98 if ([classes count] <= 0)
99 {
100 ERR("No registered classes... got nothing from pasteboard");
101 goto fail;
102 }
103
104 pb = [NSPasteboard generalPasteboard];
105 options = [NSDictionary dictionary];
106 items = [pb readObjectsForClasses: classes
107 options: options];
108 if (!items)
109 {
110 ERR("No items in the clipboard");
111 goto remove_fail;
112 }
113 if ([items count] != 1)
114 {
115 ERR("%lu items in pasteboard. Only one at the time can be handled",
116 [items count]);
117 goto fail;
118 }
119
120 if (string_class)
121 {
122 NSString *str = [items objectAtIndex: 0];
123 data = (void *)[str UTF8String];
124 len = [str lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
125 data = strndup((const char *)data, len);
126
127 if (EINA_UNLIKELY(!data))
128 {
129 CRI("Failed to strndup() string \"%s\" (len: %u)",
130 (const char *)data, len);
131 goto remove_fail;
132 }
133 types |= ECORE_COCOA_CNP_TYPE_STRING;
134
135#if 0
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#endif
150 }
151
152 if (!types)
153 {
154 ERR("No types retrieved!");
155 goto remove_fail;
156 }
157
158 [classes removeAllObjects];
159
160 if (size) *size = len;
161 if (retrieved_types) *retrieved_types = types;
162 return data;
163
164remove_fail:
165 [classes removeAllObjects];
166fail:
167 if (size) *size = 0;
168 if (retrieved_types) *retrieved_types = 0;
169 return NULL;
170}
171
172EAPI void
173ecore_cocoa_selection_clipboard_clear(void)
174{
175 [[NSPasteboard generalPasteboard] clearContents];
176}