summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2020-02-25 09:23:48 -0500
committerMike Blumenkrantz <zmike@samsung.com>2020-02-25 09:23:48 -0500
commit0ff7469d91df09f859dffd5152dfc508759206e6 (patch)
treec83cb264a1b38db44dee980712521d4396fc3e94
parent526b1e2c72560f80bcc7c435a924b2def3016215 (diff)
Evil: add evil_utf8_to_utf16() API ; use evil_utf16_to_utf8() in Ecore_Win32
Summary: use existing utf-16 to utf-8 conversion function in Ecore_Win32. Add API to convert utf-8 to utf-16 in Evil for copy'n paste on Windows Test Plan: compilation Reviewers: raster, zmike Reviewed By: zmike Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11406
-rw-r--r--src/lib/ecore_win32/ecore_win32_event.c35
-rw-r--r--src/lib/evil/evil_util.c28
-rw-r--r--src/lib/evil/evil_util.h18
3 files changed, 51 insertions, 30 deletions
diff --git a/src/lib/ecore_win32/ecore_win32_event.c b/src/lib/ecore_win32/ecore_win32_event.c
index 293b16816b..c2e9200580 100644
--- a/src/lib/ecore_win32/ecore_win32_event.c
+++ b/src/lib/ecore_win32/ecore_win32_event.c
@@ -9,6 +9,7 @@
9#undef WIN32_LEAN_AND_MEAN 9#undef WIN32_LEAN_AND_MEAN
10#include <windowsx.h> 10#include <windowsx.h>
11 11
12#include <evil_private.h> /* evil_utf16_to_utf8() */
12#include <Eina.h> 13#include <Eina.h>
13#include <Ecore.h> 14#include <Ecore.h>
14#include <Ecore_Input.h> 15#include <Ecore_Input.h>
@@ -42,32 +43,6 @@ static Ecore_Win32_Key_Mask _ecore_win32_key_mask = 0;
42static Eina_Bool _ecore_win32_ctrl_fake = EINA_FALSE; 43static Eina_Bool _ecore_win32_ctrl_fake = EINA_FALSE;
43static Eina_Bool _ecore_win32_clipboard_has_data = EINA_FALSE; 44static Eina_Bool _ecore_win32_clipboard_has_data = EINA_FALSE;
44 45
45static char *
46_ecore_win32_utf16_to_utf8(const wchar_t *text)
47{
48 char *res;
49 int size;
50
51 /* text is used as an array, hence never NULL */
52
53 size = WideCharToMultiByte(CP_UTF8, 0, text, -1, NULL, 0, NULL, NULL);
54 if (size == 0)
55 return NULL;
56
57 res = (char *)malloc(size * sizeof(char));
58 if (!res)
59 return NULL;
60
61 size = WideCharToMultiByte(CP_UTF8, 0, text, -1, res, size, NULL, NULL);
62 if (size == 0)
63 {
64 free(res);
65 return NULL;
66 }
67
68 return res;
69}
70
71static unsigned int 46static unsigned int
72_ecore_win32_modifiers_get(void) 47_ecore_win32_modifiers_get(void)
73{ 48{
@@ -1202,13 +1177,13 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1202 if (res == -1) 1177 if (res == -1)
1203 { 1178 {
1204 /* dead key, but managed like normal key */ 1179 /* dead key, but managed like normal key */
1205 compose = _ecore_win32_utf16_to_utf8(buf); 1180 compose = evil_utf16_to_utf8(buf);
1206 } 1181 }
1207 else if (res == 0) 1182 else if (res == 0)
1208 { 1183 {
1209 INF("No translatable character found, skipping"); 1184 INF("No translatable character found, skipping");
1210 if (msg->window_param >= 0x30 && msg->window_param <= 0x39) 1185 if (msg->window_param >= 0x30 && msg->window_param <= 0x39)
1211 compose = _ecore_win32_utf16_to_utf8(buf); 1186 compose = evil_utf16_to_utf8(buf);
1212 /* otherwise, compose is NULL */ 1187 /* otherwise, compose is NULL */
1213 } 1188 }
1214 else if (res >= 2) 1189 else if (res >= 2)
@@ -1222,11 +1197,11 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1222 MapVirtualKey(msg->window_param, MAPVK_VK_TO_CHAR), 1197 MapVirtualKey(msg->window_param, MAPVK_VK_TO_CHAR),
1223 kbd_state, buf, 4, 0); 1198 kbd_state, buf, 4, 0);
1224 if (!((res != 1) && (res != -1))) 1199 if (!((res != 1) && (res != -1)))
1225 compose = _ecore_win32_utf16_to_utf8(buf); 1200 compose = evil_utf16_to_utf8(buf);
1226 /* otherwise, compose is NULL */ 1201 /* otherwise, compose is NULL */
1227 } 1202 }
1228 else /* res == 1 : 1 char written to buf */ 1203 else /* res == 1 : 1 char written to buf */
1229 compose = _ecore_win32_utf16_to_utf8(buf); 1204 compose = evil_utf16_to_utf8(buf);
1230 1205
1231 /*** key field ***/ 1206 /*** key field ***/
1232 1207
diff --git a/src/lib/evil/evil_util.c b/src/lib/evil/evil_util.c
index c045bf3cc0..fc3c0607b2 100644
--- a/src/lib/evil/evil_util.c
+++ b/src/lib/evil/evil_util.c
@@ -107,6 +107,34 @@ evil_utf16_to_utf8(const wchar_t *text16)
107 return text8; 107 return text8;
108} 108}
109 109
110wchar_t *
111evil_utf8_to_utf16(const char *text)
112{
113 wchar_t *text16;
114 DWORD flag = MB_ERR_INVALID_CHARS;
115 int size16;
116
117 if (!text)
118 return NULL;
119
120 size16 = MultiByteToWideChar(CP_UTF8, flag, text, -1, NULL, 0);
121 if (size16 == 0)
122 {
123 _evil_last_error_display(__FUNCTION__);
124 return NULL;
125 }
126
127 text16 = malloc(size16 * sizeof(wchar_t));
128 if (text16)
129 if (!MultiByteToWideChar(CP_UTF8, flag, text, -1, text16, size16))
130 {
131 _evil_last_error_display(__FUNCTION__);
132 return NULL;
133 }
134
135 return text16;
136}
137
110const char * 138const char *
111evil_format_message(long err) 139evil_format_message(long err)
112{ 140{
diff --git a/src/lib/evil/evil_util.h b/src/lib/evil/evil_util.h
index 5709371f18..55b42f6823 100644
--- a/src/lib/evil/evil_util.h
+++ b/src/lib/evil/evil_util.h
@@ -59,6 +59,24 @@ EAPI char *evil_wchar_to_char(const wchar_t *text);
59 */ 59 */
60EAPI char *evil_utf16_to_utf8(const wchar_t *text); 60EAPI char *evil_utf16_to_utf8(const wchar_t *text);
61 61
62/**
63 * @brief Convert a string from UTF-8 to UTF-16.
64 *
65 * @param text The string to convert in UTF-8.
66 * @return The converted string in UTF-16.
67 *
68 * Convert a string from UTF-8 to UTF-16 and return it. If the
69 * allocation or conversion fails, NULL is returned. On success, the
70 * returned value must be freed when it is not used anymore.
71 *
72 * Conformity: Non applicable.
73 *
74 * @since 1.24
75 *
76 * @ingroup Evil
77 */
78EAPI wchar_t *evil_utf8_to_utf16(const char *text);
79
62EAPI const char *evil_format_message(long err); 80EAPI const char *evil_format_message(long err);
63 81
64EAPI const char *evil_last_error_get(void); 82EAPI const char *evil_last_error_get(void);