Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF-8 support for windows entry #1759

Merged
merged 2 commits into from
May 9, 2019
Merged

Conversation

cloudwu
Copy link
Contributor

@cloudwu cloudwu commented May 8, 2019

WM_CHAR was not handled correctly.

  1. The window is create in ANSI mode, so WM_CHAR can't received unicode code point. WideCharToMultiByte will not get the UTF-8 string.

  2. _wparam is a WPARAM, it's not a 16bit (WCHAR) integer. (LPCWSTR)&_wparam has some endian problem. Of cource, Windows always run on the little-endian platform :)

  3. We should handle surrogate pairs. For example, the emoji U+1F604 😀 , it is posted by two WM_CHAR message. See unicode inputChar support for imguiBeginFrame #1756

@bkaradzic
Copy link
Owner

Is it really necessary for everything to become W? Instead just those things that actually accept W string?

@cloudwu
Copy link
Contributor Author

cloudwu commented May 8, 2019

Windows has some strange behaviors. I debug for hours today, just because I haven’t use DispatchMessageW :(

MSG structure has no string , and DispatchMessage is for thread rather than window. We can create ANSI and Unicode windows in the same thread. DispatchMessage should convert the WM_CHAR to correct version (ansi or unicode), but it doesn’t.

So I think two version of DispatchMessage is a design error. (TranslateMessage has only one version)

If we use A version APIs (DispatchMessage, DefaultWinProc, etc), the Unicode Window would receive strange WM_CHAR. it’s not ansi code neither unicode.

You can change some W version api (not for strings) to A version, and printf WM_CHAR’s WPARAM. I am not sure which one trigger the bug , so I think the only safe way is to use W version API everywhere.

@cloudwu
Copy link
Contributor Author

cloudwu commented May 8, 2019

I guess at least we should use DefWindowProcW instead of DefWindowProcA, because the window is created in W mode. I will test it tomorrow, but I don’t think mixing A and W APIs is a good idea.

@cloudwu
Copy link
Contributor Author

cloudwu commented May 9, 2019

I reverted the unnecessary W APIs.

Except the API accept strings, there are three W APIs are necessary.

We should use DefWindowProcW because the window is in Unicode Mode.

PeekMessageW and DispatchMessageW are necessary because Unicode is a superset of ANSI, if we use A version APIs to dispatch thread message queue, some Unicode code points would be lost.

@bkaradzic bkaradzic merged commit 285936a into bkaradzic:master May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants