diff options
author | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2020-03-08 10:46:09 +0100 |
---|---|---|
committer | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2020-03-08 11:01:15 +0100 |
commit | 7dd92a2d98b983557fc4ce21f8d5740e81fa2a74 (patch) | |
tree | 6c7576939b37138f5c6e6f9852712034dfa7ba9b /src/lib/ecore_win32 | |
parent | c731cf56d5d242441d029907ea749ada6eb32ed6 (diff) |
port cnp on Windows
Test Plan: Ctrl-c and Ctrl-Vworking
Reviewers: raster, zmike
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D11439
Diffstat (limited to 'src/lib/ecore_win32')
-rw-r--r-- | src/lib/ecore_win32/Ecore_Win32.h | 47 | ||||
-rw-r--r-- | src/lib/ecore_win32/ecore_win32_clipboard.c | 224 | ||||
-rw-r--r-- | src/lib/ecore_win32/ecore_win32_event.c | 121 |
3 files changed, 235 insertions, 157 deletions
diff --git a/src/lib/ecore_win32/Ecore_Win32.h b/src/lib/ecore_win32/Ecore_Win32.h index 91274ba74a..722f0aa124 100644 --- a/src/lib/ecore_win32/Ecore_Win32.h +++ b/src/lib/ecore_win32/Ecore_Win32.h | |||
@@ -216,21 +216,6 @@ typedef enum | |||
216 | } Ecore_Win32_DnD_State; | 216 | } Ecore_Win32_DnD_State; |
217 | 217 | ||
218 | /** | 218 | /** |
219 | * @typedef Ecore_Win32_Selection | ||
220 | * Type of the selection. | ||
221 | * | ||
222 | * @since 1.16 | ||
223 | */ | ||
224 | typedef enum | ||
225 | { | ||
226 | ECORE_WIN32_SELECTION_PRIMARY, | ||
227 | ECORE_WIN32_SELECTION_SECONDARY, | ||
228 | ECORE_WIN32_SELECTION_DND, | ||
229 | ECORE_WIN32_SELECTION_CLIPBOARD, | ||
230 | ECORE_WIN32_SELECTION_OTHER | ||
231 | } Ecore_Win32_Selection; | ||
232 | |||
233 | /** | ||
234 | * @typedef Ecore_Win32_Window | 219 | * @typedef Ecore_Win32_Window |
235 | * Abstract type for a window. | 220 | * Abstract type for a window. |
236 | */ | 221 | */ |
@@ -326,7 +311,7 @@ typedef struct _Ecore_Win32_Event_Window_Delete_Request Ecore_Win32_Event_Window | |||
326 | * @typedef Ecore_Win32_Event_Selection_Clear | 311 | * @typedef Ecore_Win32_Event_Selection_Clear |
327 | * Event sent when the content of the clipboard has been removed. | 312 | * Event sent when the content of the clipboard has been removed. |
328 | * | 313 | * |
329 | * @since 1.16 | 314 | * @since 1.24 |
330 | */ | 315 | */ |
331 | typedef struct _Ecore_Win32_Event_Selection_Clear Ecore_Win32_Event_Selection_Clear; | 316 | typedef struct _Ecore_Win32_Event_Selection_Clear Ecore_Win32_Event_Selection_Clear; |
332 | 317 | ||
@@ -334,7 +319,7 @@ typedef struct _Ecore_Win32_Event_Selection_Clear Ecore_Win32_Event_Selection_Cl | |||
334 | * @typedef Ecore_Win32_Event_Selection_Notify | 319 | * @typedef Ecore_Win32_Event_Selection_Notify |
335 | * Event sent when the content of the clipboard has been added. | 320 | * Event sent when the content of the clipboard has been added. |
336 | * | 321 | * |
337 | * @since 1.16 | 322 | * @since 1.24 |
338 | */ | 323 | */ |
339 | typedef struct _Ecore_Win32_Event_Selection_Notify Ecore_Win32_Event_Selection_Notify; | 324 | typedef struct _Ecore_Win32_Event_Selection_Notify Ecore_Win32_Event_Selection_Notify; |
340 | 325 | ||
@@ -490,26 +475,26 @@ struct _Ecore_Win32_Event_Window_Delete_Request | |||
490 | * @struct _Ecore_Win32_Event_Selection_Clear | 475 | * @struct _Ecore_Win32_Event_Selection_Clear |
491 | * Event sent when the content of the clipboard has been removed. | 476 | * Event sent when the content of the clipboard has been removed. |
492 | * | 477 | * |
493 | * @since 1.16 | 478 | * @since 1.24 |
494 | */ | 479 | */ |
495 | struct _Ecore_Win32_Event_Selection_Clear | 480 | struct _Ecore_Win32_Event_Selection_Clear |
496 | { | 481 | { |
497 | Ecore_Win32_Window *window; /**< The window that received the event */ | 482 | Ecore_Win32_Window *window; /**< The window that received the event */ |
498 | unsigned long timestamp; /**< The time the event occurred */ | 483 | unsigned long timestamp; /**< The time the event occurred */ |
499 | Ecore_Win32_Selection selection; /**< The type of the selection */ | 484 | char *selection; /**< The type of the selection */ |
500 | }; | 485 | }; |
501 | 486 | ||
502 | /** | 487 | /** |
503 | * @struct _Ecore_Win32_Event_Selection_Notify | 488 | * @struct _Ecore_Win32_Event_Selection_Notify |
504 | * Event sent when the content of the clipboard has been added. | 489 | * Event sent when the content of the clipboard has been added. |
505 | * | 490 | * |
506 | * @since 1.16 | 491 | * @since 1.24 |
507 | */ | 492 | */ |
508 | struct _Ecore_Win32_Event_Selection_Notify | 493 | struct _Ecore_Win32_Event_Selection_Notify |
509 | { | 494 | { |
510 | Ecore_Win32_Window *window; /**< The window that received the event */ | 495 | Ecore_Win32_Window *window; /**< The window that received the event */ |
511 | unsigned long timestamp; /**< The time the event occurred */ | 496 | unsigned long timestamp; /**< The time the event occurred */ |
512 | Ecore_Win32_Selection selection; /**< The type of the selection */ | 497 | char *selection; /**< The type of the selection */ |
513 | void *data; /**< The data of the selection */ | 498 | void *data; /**< The data of the selection */ |
514 | }; | 499 | }; |
515 | 500 | ||
@@ -698,6 +683,7 @@ EAPI void ecore_win32_dnd_unregister_drop_target(Ecore_Win32_Window *window | |||
698 | * @param[in] window The window that owns the clipboard. | 683 | * @param[in] window The window that owns the clipboard. |
699 | * @param[in] data The data to set. | 684 | * @param[in] data The data to set. |
700 | * @param[in] size The size of the data. | 685 | * @param[in] size The size of the data. |
686 | * @param[in] mime_type The mime type describing the data in the clipboard. | ||
701 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. | 687 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. |
702 | * | 688 | * |
703 | * This function sets @p data of size @p size in the clipboard owned by | 689 | * This function sets @p data of size @p size in the clipboard owned by |
@@ -705,11 +691,12 @@ EAPI void ecore_win32_dnd_unregister_drop_target(Ecore_Win32_Window *window | |||
705 | * #EINA_FALSE otherwise. If @p window or @p data are @c NULL, or @p size | 691 | * #EINA_FALSE otherwise. If @p window or @p data are @c NULL, or @p size |
706 | * is less than or equal to 0, this function returns #EINA_FALSE. | 692 | * is less than or equal to 0, this function returns #EINA_FALSE. |
707 | * | 693 | * |
708 | * @since 1.16 | 694 | * @since 1.24 |
709 | */ | 695 | */ |
710 | EAPI Eina_Bool ecore_win32_clipboard_set(const Ecore_Win32_Window *window, | 696 | EAPI Eina_Bool ecore_win32_clipboard_set(const Ecore_Win32_Window *window, |
711 | const void *data, | 697 | const void *data, |
712 | int size); | 698 | size_t size, |
699 | const char *mime_type); | ||
713 | 700 | ||
714 | /** | 701 | /** |
715 | * @brief Get data from the clipboard. | 702 | * @brief Get data from the clipboard. |
@@ -717,6 +704,7 @@ EAPI Eina_Bool ecore_win32_clipboard_set(const Ecore_Win32_Window *window, | |||
717 | * @param[in] window The window that owns the clipboard. | 704 | * @param[in] window The window that owns the clipboard. |
718 | * @param[out] data The retrieved data. | 705 | * @param[out] data The retrieved data. |
719 | * @param[out] size The size of the data. | 706 | * @param[out] size The size of the data. |
707 | * @param[in] mime_type The mime type describing the data in the clipboard. | ||
720 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. | 708 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. |
721 | * | 709 | * |
722 | * This function gets @p data of size @p size from the clipboard owned by | 710 | * This function gets @p data of size @p size from the clipboard owned by |
@@ -724,25 +712,24 @@ EAPI Eina_Bool ecore_win32_clipboard_set(const Ecore_Win32_Window *window, | |||
724 | * #EINA_FALSE otherwise. If @p window is @c NULL, this function returns | 712 | * #EINA_FALSE otherwise. If @p window is @c NULL, this function returns |
725 | * #EINA_FALSE. @p data and @p size must be valid buffers. | 713 | * #EINA_FALSE. @p data and @p size must be valid buffers. |
726 | * | 714 | * |
727 | * @since 1.16 | 715 | * @since 1.24 |
728 | */ | 716 | */ |
729 | EAPI Eina_Bool ecore_win32_clipboard_get(const Ecore_Win32_Window *window, | 717 | EAPI void * ecore_win32_clipboard_get(const Ecore_Win32_Window *window, |
730 | void **data, | 718 | size_t *size, |
731 | int *size); | 719 | const char *mime_type); |
732 | 720 | ||
733 | /** | 721 | /** |
734 | * @brief Cleat the clipboard. | 722 | * @brief Cleat the clipboard. |
735 | * | 723 | * |
736 | * @param[in] window The window that owns the clipboard. | 724 | * @param[in] window The window that owns the clipboard. |
737 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. | ||
738 | * | 725 | * |
739 | * This function clears the clipboard owned by @p window. This | 726 | * This function clears the clipboard owned by @p window. This |
740 | * function returns #EINA_TRUE on success, and #EINA_FALSE otherwise. | 727 | * function returns #EINA_TRUE on success, and #EINA_FALSE otherwise. |
741 | * If @p window is @c NULL, this function returns #EINA_FALSE. | 728 | * If @p window is @c NULL, this function returns #EINA_FALSE. |
742 | * | 729 | * |
743 | * @since 1.16 | 730 | * @since 1.24 |
744 | */ | 731 | */ |
745 | EAPI Eina_Bool ecore_win32_clipboard_clear(const Ecore_Win32_Window *window); | 732 | EAPI void ecore_win32_clipboard_clear(const Ecore_Win32_Window *window); |
746 | 733 | ||
747 | /** | 734 | /** |
748 | * @typedef Ecore_Win32_Monitor | 735 | * @typedef Ecore_Win32_Monitor |
diff --git a/src/lib/ecore_win32/ecore_win32_clipboard.c b/src/lib/ecore_win32/ecore_win32_clipboard.c index a20be680c0..da4960370a 100644 --- a/src/lib/ecore_win32/ecore_win32_clipboard.c +++ b/src/lib/ecore_win32/ecore_win32_clipboard.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <windows.h> | 6 | #include <windows.h> |
7 | #undef WIN32_LEAN_AND_MEAN | 7 | #undef WIN32_LEAN_AND_MEAN |
8 | 8 | ||
9 | #include <evil_private.h> /* utf-8 and utf-16 conversion */ | ||
9 | #include <Eina.h> | 10 | #include <Eina.h> |
10 | 11 | ||
11 | #include "Ecore_Win32.h" | 12 | #include "Ecore_Win32.h" |
@@ -39,10 +40,13 @@ | |||
39 | EAPI Eina_Bool | 40 | EAPI Eina_Bool |
40 | ecore_win32_clipboard_set(const Ecore_Win32_Window *window, | 41 | ecore_win32_clipboard_set(const Ecore_Win32_Window *window, |
41 | const void *data, | 42 | const void *data, |
42 | int size) | 43 | size_t size, |
44 | const char *mime_type) | ||
43 | { | 45 | { |
44 | HGLOBAL global; | 46 | HGLOBAL global; |
45 | char *d; | 47 | char *d; |
48 | Eina_Bool supported_mime_text; | ||
49 | Eina_Bool res = EINA_FALSE; | ||
46 | 50 | ||
47 | /* | 51 | /* |
48 | * See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx#_win32_Copying_Information_to_the_Clipboard | 52 | * See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx#_win32_Copying_Information_to_the_Clipboard |
@@ -54,47 +58,77 @@ ecore_win32_clipboard_set(const Ecore_Win32_Window *window, | |||
54 | 58 | ||
55 | INF("setting data to the clipboard"); | 59 | INF("setting data to the clipboard"); |
56 | 60 | ||
57 | if (!window || !data || (size <= 0)) | 61 | supported_mime_text = eina_str_has_prefix(mime_type, "text/"); |
58 | return EINA_FALSE; | 62 | if (!supported_mime_text) |
63 | { | ||
64 | ERR("Mimetype %s is not handled yet", mime_type); | ||
65 | return EINA_FALSE; | ||
66 | } | ||
59 | 67 | ||
60 | if (!OpenClipboard(window->window)) | 68 | if (!window || !data || (size <= 0) || !OpenClipboard(window->window)) |
61 | return EINA_FALSE; | 69 | return EINA_FALSE; |
62 | 70 | ||
63 | if (!EmptyClipboard()) | 71 | if (!EmptyClipboard()) |
64 | goto close_clipboard; | 72 | goto close_clipboard; |
65 | 73 | ||
66 | global = GlobalAlloc(GMEM_MOVEABLE, size + 1); | 74 | if (supported_mime_text) |
67 | if (!global) | 75 | { |
68 | goto close_clipboard; | 76 | wchar_t *text16; |
69 | 77 | size_t size16; | |
70 | d = (char *)GlobalLock(global); | 78 | |
71 | if (!d) | 79 | /* CF_TEXT (UTF-8) */ |
72 | goto unlock_global; | 80 | |
73 | 81 | global = GlobalAlloc(GMEM_MOVEABLE, size); | |
74 | memcpy(d, data, size); | 82 | if (global) |
75 | d[size] = '\0'; | 83 | { |
76 | GlobalUnlock(global); | 84 | d = (char *)GlobalLock(global); |
77 | SetClipboardData(CF_TEXT, global); | 85 | if (d) |
78 | CloseClipboard(); | 86 | { |
79 | 87 | memcpy(d, data, size); | |
80 | return EINA_TRUE; | 88 | SetClipboardData(CF_TEXT, global); |
89 | res = EINA_TRUE; | ||
90 | GlobalUnlock(global); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | /* CF_UNICODETEXT (UTF-16) */ | ||
95 | |||
96 | text16 = evil_utf8_to_utf16(data); | ||
97 | if (text16) | ||
98 | { | ||
99 | size16 = (wcslen(text16) + 1) * sizeof(wchar_t); | ||
100 | |||
101 | global = GlobalAlloc(GMEM_MOVEABLE, size16); | ||
102 | if (global) | ||
103 | { | ||
104 | d = (char *)GlobalLock(global); | ||
105 | if (d) | ||
106 | { | ||
107 | memcpy(d, text16, size16); | ||
108 | SetClipboardData(CF_UNICODETEXT, global); | ||
109 | res = EINA_TRUE; | ||
110 | GlobalUnlock(global); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | free(text16); | ||
115 | } | ||
116 | } | ||
81 | 117 | ||
82 | unlock_global: | ||
83 | GlobalUnlock(global); | ||
84 | close_clipboard: | 118 | close_clipboard: |
85 | CloseClipboard(); | 119 | CloseClipboard(); |
86 | 120 | ||
87 | return EINA_FALSE; | 121 | return res; |
88 | } | 122 | } |
89 | 123 | ||
90 | EAPI Eina_Bool | 124 | EAPI void * |
91 | ecore_win32_clipboard_get(const Ecore_Win32_Window *window, | 125 | ecore_win32_clipboard_get(const Ecore_Win32_Window *window, |
92 | void **data, | 126 | size_t *size, |
93 | int *size) | 127 | const char *mime_type) |
94 | { | 128 | { |
95 | HGLOBAL global; | 129 | HGLOBAL global; |
130 | void *data; | ||
96 | void *d; | 131 | void *d; |
97 | void *p; | ||
98 | 132 | ||
99 | /* | 133 | /* |
100 | * See https://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx#_win32_Pasting_Information_from_the_Clipboard | 134 | * See https://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx#_win32_Pasting_Information_from_the_Clipboard |
@@ -107,80 +141,100 @@ ecore_win32_clipboard_get(const Ecore_Win32_Window *window, | |||
107 | 141 | ||
108 | INF("getting data from the clipboard"); | 142 | INF("getting data from the clipboard"); |
109 | 143 | ||
110 | if (!window) | 144 | if (!eina_str_has_prefix(mime_type, "text/")) |
111 | return EINA_FALSE; | 145 | { |
112 | 146 | ERR("Mimetype %s is not handled yet", mime_type); | |
113 | if (!IsClipboardFormatAvailable(CF_TEXT)) | 147 | return NULL; |
114 | return EINA_FALSE; | 148 | } |
115 | |||
116 | if (!OpenClipboard(window->window)) | ||
117 | goto set_val; | ||
118 | |||
119 | /* { */ | ||
120 | /* UINT fmt = 0; */ | ||
121 | 149 | ||
122 | /* while (1) */ | 150 | if (!window || !size || !OpenClipboard(window->window)) |
123 | /* { */ | 151 | return NULL; |
124 | /* fmt = EnumClipboardFormats(fmt); */ | ||
125 | /* printf(" $ Format : %x\n", fmt); */ | ||
126 | /* if (!fmt) */ | ||
127 | /* break; */ | ||
128 | /* } */ | ||
129 | /* } */ | ||
130 | 152 | ||
131 | global = GetClipboardData(CF_TEXT); | 153 | *size = 0; |
132 | if (!global) | ||
133 | goto close_clipboard; | ||
134 | |||
135 | d = GlobalLock(global); | ||
136 | if (!d) | ||
137 | goto unlock_global; | ||
138 | |||
139 | *size = strlen(d); | ||
140 | p = malloc(*size); | ||
141 | if (!p) | ||
142 | goto unlock_global; | ||
143 | 154 | ||
144 | memcpy(p, d, *size); | 155 | #if 0 |
145 | *data = p; | 156 | { |
146 | GlobalUnlock(global); | 157 | UINT fmt = 0; |
147 | CloseClipboard(); | 158 | |
159 | while (1) | ||
160 | { | ||
161 | char name[4096]; | ||
162 | int res; | ||
163 | fmt = EnumClipboardFormats(fmt); | ||
164 | res = GetClipboardFormatName(fmt, name, sizeof(name)); | ||
165 | fprintf(stderr, " $ Format2 : %x %d\n", fmt, res); | ||
166 | if (res) | ||
167 | fprintf(stderr, " $ Format2 : %s\n", name); | ||
168 | else | ||
169 | fprintf(stderr, " $ Format2 : error %ld\n", GetLastError()); | ||
170 | fflush(stderr); | ||
171 | if (!fmt) | ||
172 | break; | ||
173 | } | ||
174 | } | ||
175 | #endif | ||
148 | 176 | ||
149 | return EINA_TRUE; | 177 | if (eina_str_has_prefix(mime_type, "text/")) |
178 | { | ||
179 | /* first check if UTF-16 text is available */ | ||
180 | global = GetClipboardData(CF_UNICODETEXT); | ||
181 | if (global) | ||
182 | { | ||
183 | d = GlobalLock(global); | ||
184 | if (d) | ||
185 | { | ||
186 | data = evil_utf16_to_utf8(d); | ||
187 | if (data) | ||
188 | { | ||
189 | *size = strlen(data); | ||
190 | GlobalUnlock(global); | ||
191 | CloseClipboard(); | ||
192 | return data; | ||
193 | } | ||
194 | GlobalUnlock(global); | ||
195 | } | ||
196 | /* otherwise, we try CF_TEXT (UTF-8/ANSI) */ | ||
197 | } | ||
198 | |||
199 | /* second, check if UTF-8/ANSI text is available */ | ||
200 | global = GetClipboardData(CF_TEXT); | ||
201 | if (global) | ||
202 | { | ||
203 | d = GlobalLock(global); | ||
204 | if (d) | ||
205 | { | ||
206 | *size = strlen(d) + 1; | ||
207 | data = malloc(*size); | ||
208 | if (data) | ||
209 | { | ||
210 | memcpy(data, d, *size); | ||
211 | GlobalUnlock(global); | ||
212 | CloseClipboard(); | ||
213 | return data; | ||
214 | } | ||
215 | else | ||
216 | *size = 0; | ||
217 | |||
218 | GlobalUnlock(global); | ||
219 | } | ||
220 | } | ||
221 | } | ||
150 | 222 | ||
151 | unlock_global: | ||
152 | GlobalUnlock(global); | ||
153 | close_clipboard: | ||
154 | CloseClipboard(); | 223 | CloseClipboard(); |
155 | set_val: | ||
156 | *data = NULL; | ||
157 | *size = 0; | ||
158 | 224 | ||
159 | return EINA_FALSE; | 225 | return NULL; |
160 | } | 226 | } |
161 | 227 | ||
162 | EAPI Eina_Bool | 228 | EAPI void |
163 | ecore_win32_clipboard_clear(const Ecore_Win32_Window *window) | 229 | ecore_win32_clipboard_clear(const Ecore_Win32_Window *window) |
164 | { | 230 | { |
165 | INF("clearing the clipboard"); | 231 | INF("clearing the clipboard"); |
166 | 232 | ||
167 | if (!window) | 233 | if (!window || !OpenClipboard(window->window)) |
168 | return EINA_FALSE; | 234 | return; |
169 | |||
170 | if (!OpenClipboard(window->window)) | ||
171 | return EINA_FALSE; | ||
172 | |||
173 | if (!EmptyClipboard()) | ||
174 | goto close_clipboard; | ||
175 | |||
176 | CloseClipboard(); | ||
177 | |||
178 | return EINA_TRUE; | ||
179 | 235 | ||
180 | close_clipboard: | 236 | EmptyClipboard(); |
181 | CloseClipboard(); | 237 | CloseClipboard(); |
182 | |||
183 | return EINA_FALSE; | ||
184 | } | 238 | } |
185 | 239 | ||
186 | /** | 240 | /** |
diff --git a/src/lib/ecore_win32/ecore_win32_event.c b/src/lib/ecore_win32/ecore_win32_event.c index 0c232e7bc3..28a5b1f07e 100644 --- a/src/lib/ecore_win32/ecore_win32_event.c +++ b/src/lib/ecore_win32/ecore_win32_event.c | |||
@@ -1958,66 +1958,103 @@ _ecore_win32_event_handle_selection_notify(Ecore_Win32_Callback_Data *msg) | |||
1958 | { | 1958 | { |
1959 | Ecore_Win32_Event_Selection_Notify *e; | 1959 | Ecore_Win32_Event_Selection_Notify *e; |
1960 | HGLOBAL global; | 1960 | HGLOBAL global; |
1961 | char *str; | ||
1962 | 1961 | ||
1963 | INF("selection_notify"); | 1962 | INF("selection_notify"); |
1964 | 1963 | ||
1964 | e = calloc(1, sizeof(Ecore_Win32_Event_Selection_Notify)); | ||
1965 | if (!e) return; | ||
1966 | |||
1967 | e->window = (void *)GetWindowLongPtr(msg->window, GWLP_USERDATA); | ||
1968 | e->timestamp = _ecore_win32_event_last_time; | ||
1969 | |||
1965 | /* | 1970 | /* |
1966 | * we have text data in clipboard but no data before, | 1971 | * we have data in clipboard but no data before, |
1967 | * so text data has just been added | 1972 | * so data has just been added |
1968 | */ | 1973 | */ |
1969 | if (IsClipboardFormatAvailable(CF_TEXT) && !_ecore_win32_clipboard_has_data) | 1974 | if (!_ecore_win32_clipboard_has_data) |
1970 | { | 1975 | { |
1971 | e = calloc(1, sizeof(Ecore_Win32_Event_Selection_Notify)); | 1976 | /* if case someone else is owning the clipboard, we can't do anything */ |
1972 | if (!e) return; | ||
1973 | |||
1974 | e->window = (void *)GetWindowLongPtr(msg->window, GWLP_USERDATA); | ||
1975 | e->timestamp = _ecore_win32_event_last_time; | ||
1976 | e->selection = ECORE_WIN32_SELECTION_CLIPBOARD; | ||
1977 | |||
1978 | if (!OpenClipboard(msg->window)) | 1977 | if (!OpenClipboard(msg->window)) |
1979 | goto free_e; | 1978 | { |
1980 | 1979 | free(e); | |
1981 | global = GetClipboardData(CF_TEXT); | 1980 | return; |
1982 | if (!global) | 1981 | } |
1983 | goto close_clipboard; | ||
1984 | 1982 | ||
1985 | str = GlobalLock(global); | 1983 | if (IsClipboardFormatAvailable(CF_UNICODETEXT)) |
1986 | if (str) | ||
1987 | { | 1984 | { |
1988 | e->data = strdup(str); | 1985 | global = GetClipboardData(CF_UNICODETEXT); |
1989 | GlobalUnlock(global); | 1986 | if (global) |
1987 | { | ||
1988 | e->selection = strdup("text/plain;charset=utf-8"); | ||
1989 | if (e->selection) | ||
1990 | { | ||
1991 | wchar_t *d; | ||
1992 | |||
1993 | d = (wchar_t *)GlobalLock(global); | ||
1994 | if (d) | ||
1995 | e->data = evil_utf16_to_utf8(d); | ||
1996 | |||
1997 | GlobalUnlock(global); | ||
1998 | if (e->data) | ||
1999 | { | ||
2000 | ecore_event_add(ECORE_WIN32_EVENT_SELECTION_NOTIFY, e, NULL, NULL); | ||
2001 | _ecore_win32_clipboard_has_data = EINA_TRUE; | ||
2002 | CloseClipboard(); | ||
2003 | return; | ||
2004 | } | ||
2005 | } | ||
2006 | } | ||
1990 | } | 2007 | } |
1991 | 2008 | ||
2009 | if (IsClipboardFormatAvailable(CF_TEXT)) | ||
2010 | { | ||
2011 | global = GetClipboardData(CF_TEXT); | ||
2012 | if (global) | ||
2013 | { | ||
2014 | e->selection = strdup("text/plain;charset=utf-8"); | ||
2015 | if (e->selection) | ||
2016 | { | ||
2017 | char *d; | ||
2018 | |||
2019 | d = (char *)GlobalLock(global); | ||
2020 | if (d) | ||
2021 | e->data = strdup(d); | ||
2022 | |||
2023 | GlobalUnlock(global); | ||
2024 | if (e->data) | ||
2025 | { | ||
2026 | ecore_event_add(ECORE_WIN32_EVENT_SELECTION_NOTIFY, e, NULL, NULL); | ||
2027 | |||
2028 | _ecore_win32_clipboard_has_data = EINA_TRUE; | ||
2029 | CloseClipboard(); | ||
2030 | return; | ||
2031 | } | ||
2032 | } | ||
2033 | } | ||
2034 | } | ||
2035 | free(e->data); | ||
2036 | free(e->selection); | ||
2037 | free(e); | ||
1992 | CloseClipboard(); | 2038 | CloseClipboard(); |
1993 | |||
1994 | ecore_event_add(ECORE_WIN32_EVENT_SELECTION_NOTIFY, e, NULL, NULL); | ||
1995 | |||
1996 | _ecore_win32_clipboard_has_data = EINA_TRUE; | ||
1997 | } | 2039 | } |
1998 | |||
1999 | /* | 2040 | /* |
2000 | * we have no more text data in clipboard and data before, | 2041 | * otherwise, we have no more text data in clipboard and data before, |
2001 | * so text data has just been removed | 2042 | * so text data has just been removed |
2002 | */ | 2043 | */ |
2003 | if (!IsClipboardFormatAvailable(CF_TEXT) && _ecore_win32_clipboard_has_data) | 2044 | else |
2004 | { | 2045 | { |
2005 | e = calloc(1, sizeof(Ecore_Win32_Event_Selection_Clear)); | 2046 | if (!IsClipboardFormatAvailable(CF_UNICODETEXT) && |
2006 | if (!e) return; | 2047 | !IsClipboardFormatAvailable(CF_TEXT)) |
2007 | 2048 | { | |
2008 | e->window = (void *)GetWindowLongPtr(msg->window, GWLP_USERDATA); | 2049 | e->selection = strdup("text/plain;charset=utf-8"); |
2009 | e->timestamp = _ecore_win32_event_last_time; | 2050 | if (e->selection) |
2010 | e->selection = ECORE_WIN32_SELECTION_CLIPBOARD; | 2051 | { |
2011 | 2052 | ecore_event_add(ECORE_WIN32_EVENT_SELECTION_CLEAR, e, NULL, NULL); | |
2012 | ecore_event_add(ECORE_WIN32_EVENT_SELECTION_CLEAR, e, NULL, NULL); | 2053 | _ecore_win32_clipboard_has_data = EINA_FALSE; |
2013 | 2054 | return; | |
2014 | _ecore_win32_clipboard_has_data = EINA_FALSE; | 2055 | } |
2056 | } | ||
2015 | } | 2057 | } |
2016 | 2058 | ||
2017 | return; | ||
2018 | |||
2019 | close_clipboard: | ||
2020 | CloseClipboard(); | ||
2021 | free_e: | ||
2022 | free(e); | 2059 | free(e); |
2023 | } | 2060 | } |