arrow key works on gdi

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@244 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-09 13:21:01 +00:00
parent 2cecb6c34a
commit a8f2628009
5 changed files with 57 additions and 1 deletions

View File

@@ -215,6 +215,9 @@
<dd>
<a href="#Mw_Unicode_h__MwUTF8Copy">MwUTF8Copy</a>
</dd>
<dd>
<a href="#Mw_Unicode_h__MwUTF32ToUTF8">MwUTF32ToUTF8</a>
</dd>
<dt>
<a href="#Mw_Widget_Button_h">Mw/Widget/Button.h</a>
</dt>
@@ -1724,6 +1727,22 @@
</dd>
</dl>
<hr>
<pre id="Mw_Unicode_h__MwUTF32ToUTF8">MWDECL <B><FONT COLOR="#228B22">int</FONT></B> <B><FONT COLOR="#0000FF">MwUTF32ToUTF8</FONT></B> (
<B><FONT COLOR="#228B22">int</FONT></B> input,
<B><FONT COLOR="#228B22">char</FONT></B>* output
);</pre>
<dl>
<dd>
output Output.
</dd>
<dt>
Returns
</dt>
<dd>
Bytes this wide byte takes.
</dd>
</dl>
<hr>
<h2 align="center" id="Mw_Widget_Button_h">Mw/Widget/Button.h</h2>
<dl>
<dt>

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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++;