ecore_win32: fix compose event field

Summary:
compose event field was encoded in UTF-16 and not UTF-8. Also string
event field was not correctly defined and was generating eina error
messages

Test Plan: running a test

Reviewers: raster, cedric, zmike

Reviewed By: raster

Subscribers: #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D10753
This commit is contained in:
Vincent Torri 2019-11-28 11:06:24 +00:00 committed by Carsten Haitzler (Rasterman)
parent 92d2cc7ae3
commit 9acab812ee
1 changed files with 42 additions and 13 deletions

View File

@ -42,6 +42,32 @@ static Ecore_Win32_Key_Mask _ecore_win32_key_mask = 0;
static Eina_Bool _ecore_win32_ctrl_fake = EINA_FALSE;
static Eina_Bool _ecore_win32_clipboard_has_data = EINA_FALSE;
static char *
_ecore_win32_utf16_to_utf8(const wchar_t *text)
{
char *res;
int size;
/* text is used as an array, hence never NULL */
size = WideCharToMultiByte(CP_UTF8, 0, text, -1, NULL, 0, NULL, NULL);
if (size == 0)
return NULL;
res = (char *)malloc(size * sizeof(char));
if (!res)
return NULL;
size = WideCharToMultiByte(CP_UTF8, 0, text, -1, res, size, NULL, NULL);
if (size == 0)
{
free(res);
return NULL;
}
return res;
}
static unsigned int
_ecore_win32_modifiers_get(void)
{
@ -1176,15 +1202,14 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
if (res == -1)
{
/* dead key, but managed like normal key */
compose = _ecore_win32_utf16_to_utf8(buf);
}
else if (res == 0)
{
INF("No translatable character found, skipping");
if (msg->window_param >= 0x30 && msg->window_param <= 0x39)
{
buf[0] = msg->window_param;
}
else return NULL;
compose = _ecore_win32_utf16_to_utf8(buf);
/* otherwise, compose is NULL */
}
else if (res >= 2)
{
@ -1196,12 +1221,12 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
res = ToUnicode(msg->window_param,
MapVirtualKey(msg->window_param, MAPVK_VK_TO_CHAR),
kbd_state, buf, 4, 0);
if ((res != 1) && (res != -1))
return NULL;
if (!((res != 1) && (res != -1)))
compose = _ecore_win32_utf16_to_utf8(buf);
/* otherwise, compose is NULL */
}
string[0] = (char)buf[0];
compose = string;
else /* res == 1 : 1 char written to buf */
compose = _ecore_win32_utf16_to_utf8(buf);
/*** key field ***/
@ -1232,7 +1257,6 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
{
buf[0] = msg->window_param;
}
else return NULL;
}
else if (res >= 2)
{
@ -1303,7 +1327,7 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
{
buf[0] = msg->window_param;
}
else return NULL;
else buf[0] = 0;// return NULL;
}
else if (res >= 2)
{
@ -1353,7 +1377,7 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
e = (Ecore_Event_Key *)calloc(1, sizeof(Ecore_Event_Key) +
strlen(keyname) + 1 +
strlen(key) + 1 +
(compose ? (strlen(compose) + 1) : 0));
(compose ? strlen(compose) : 0) + 1);
if (!e)
return NULL;
@ -1366,7 +1390,12 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
memcpy((char *)e->keyname, keyname, strlen(keyname));
memcpy((char *)e->key, key, strlen(key));
if (compose) memcpy((char *)e->compose, compose, strlen(compose));
if (compose)
{
memcpy((char *)e->compose, compose, strlen(compose));
free(compose);
}
return e;
}