diff --git a/doc/index.html b/doc/index.html index 35f497d..ad2f47c 100644 --- a/doc/index.html +++ b/doc/index.html @@ -215,6 +215,9 @@
MwUTF8Copy
+
+ MwUTF32ToUTF8 +
Mw/Widget/Button.h
@@ -1724,6 +1727,22 @@
+
MWDECL int MwUTF32ToUTF8 (
+	int input,
+	char* output
+);
+
+
+ output Output. +
+
+ Returns +
+
+ Bytes this wide byte takes. +
+
+

Mw/Widget/Button.h

diff --git a/include/Mw/Unicode.h b/include/Mw/Unicode.h index 0450bf1..3a7e160 100644 --- a/include/Mw/Unicode.h +++ b/include/Mw/Unicode.h @@ -39,6 +39,14 @@ MWDECL int MwUTF8Length(const char* input); */ MWDECL int MwUTF8Copy(const char* src, int srcskip, char* dst, int dstskip, int len); +/*! + * %brief Converts UTF-32 to UTF-8 + * %brief input Input + * %brief output Output + * %return Bytes this wide byte takes + */ +MWDECL int MwUTF32ToUTF8(int input, char* output); + #ifdef __cplusplus } #endif diff --git a/src/backend/gdi.c b/src/backend/gdi.c index 65d193b..019e48b 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -76,6 +76,11 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { int n = wp; MwLLDispatch(u->ll, key, &n); + } else if(msg == WM_KEYDOWN) { + int n = -1; + if(wp == VK_LEFT) n = MwLLKeyLeft; + if(wp == VK_RIGHT) n = MwLLKeyRight; + if(n != -1) MwLLDispatch(u->ll, key, &n); } else { return (u->old == NULL) ? DefWindowProc(hWnd, msg, wp, lp) : CallWindowProc(u->old, hWnd, msg, wp, lp); } diff --git a/src/unicode.c b/src/unicode.c index a7bc5c0..9506d47 100644 --- a/src/unicode.c +++ b/src/unicode.c @@ -97,3 +97,27 @@ int MwUTF8Copy(const char* src, int srcskip, char* dst, int dstskip, int len) { return total; } + +int MwUTF32ToUTF8(int input, char* output) { + if(input < 128) { + output[0] = input; + return 1; + } else if(input < 2048) { + output[0] = 0xc0 | (input >> 6); + output[1] = 0x80 | (input & 0x3f); + return 2; + } else if(input < 65536) { + output[0] = 0xe0 | (input >> 12); + output[1] = 0x80 | ((input >> 6) & 0x3f); + output[2] = 0x80 | (input & 0x3f); + return 3; + } else { + output[0] = 0xf0 | (input >> 18); + output[1] = 0x80 | ((input >> 12) & 0x3f); + output[2] = 0x80 | ((input >> 6) & 0x3f); + output[3] = 0x80 | (input & 0x3f); + return 4; + } + + return 0; +} diff --git a/src/widget/entry.c b/src/widget/entry.c index ea57c07..5be17e2 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -106,7 +106,7 @@ static void key(MwWidget handle, int code) { int incr = 0; out = malloc(strlen(str) + 1 + 1); incr += MwUTF8Copy(str, 0, out, 0, t->cursor); - out[incr++] = code; + MwUTF32ToUTF8(code, out + incr); MwUTF8Copy(str, t->cursor, out, t->cursor + 1, MwUTF8Length(str) - t->cursor); t->cursor++;