diff options
author | nyamatongwe <devnull@localhost> | 2007-06-23 04:22:01 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2007-06-23 04:22:01 +0000 |
commit | e59983b9d2615428729b24f94216ec33bdc5c2a6 (patch) | |
tree | 118956af9c8e379f06510415bb5514b97470ad5b | |
parent | 94cd1460c1434763252b1d6f4df9d883ed7ce895 (diff) | |
download | scintilla-mirror-e59983b9d2615428729b24f94216ec33bdc5c2a6.tar.gz |
Fixes for bug #1732146, Armenian input on Windows by registering the
Scintilla windows class as wide and using GetMessageW/DispatchMessageW
in the SciTE event loop.
-rw-r--r-- | src/Editor.cxx | 1 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 78 |
2 files changed, 46 insertions, 33 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index f96ef1bfc..9c4c77d3c 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -3238,6 +3238,7 @@ void Editor::AddChar(char ch) { AddCharUTF(s, 1); } +// AddCharUTF inserts an array of bytes which may or may not be in UTF-8. void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) { bool wasSelection = currentPos != anchor; ClearSelection(); diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 248513e18..f8757ba6d 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -554,6 +554,24 @@ static unsigned int SciMessageFromEM(unsigned int iMessage) { return iMessage; } +static UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage) { + CHARSETINFO ci = { 0, 0, { { 0, 0, 0, 0 }, { 0, 0 } } }; + BOOL bci = ::TranslateCharsetInfo((DWORD*)characterSet, + &ci, TCI_SRCCHARSET); + + UINT cp; + if (bci) + cp = ci.ciACP; + else + cp = documentCodePage; + + CPINFO cpi; + if (!IsValidCodePage(cp) && !GetCPInfo(cp, &cpi)) + cp = CP_ACP; + + return cp; +} + sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { //Platform::DebugPrintf("S M:%x WP:%x L:%x\n", iMessage, wParam, lParam); iMessage = SciMessageFromEM(iMessage); @@ -730,17 +748,29 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam } case WM_CHAR: - if (!iscntrl(wParam&0xff) || !lastKeyDownConsumed) { - if (IsUnicodeMode()) { - // For a wide character version of the window: - //char utfval[4]; - //wchar_t wcs[2] = {wParam, 0}; - //unsigned int len = UTF8Length(wcs, 1); - //UTF8FromUTF16(wcs, 1, utfval, len); - //AddCharUTF(utfval, len); - AddCharBytes('\0', LOBYTE(wParam)); + if (((wParam >= 128) || !iscntrl(wParam)) || !lastKeyDownConsumed) { + if (::IsWindowUnicode(MainHWND())) { + wchar_t wcs[2] = {wParam, 0}; + if (IsUnicodeMode()) { + // For a wide character version of the window: + char utfval[4]; + unsigned int len = UTF8Length(wcs, 1); + UTF8FromUTF16(wcs, 1, utfval, len); + AddCharUTF(utfval, len); + } else { + UINT cpDest = CodePageFromCharSet( + vs.styles[STYLE_DEFAULT].characterSet, pdoc->dbcsCodePage); + char inBufferCP[20]; + int size = ::WideCharToMultiByte(cpDest, + 0, wcs, 1, inBufferCP, sizeof(inBufferCP) - 1, 0, 0); + AddCharUTF(inBufferCP, size); + } } else { - AddChar(LOBYTE(wParam)); + if (IsUnicodeMode()) { + AddCharBytes('\0', LOBYTE(wParam)); + } else { + AddChar(LOBYTE(wParam)); + } } } return 0; @@ -1215,24 +1245,6 @@ bool ScintillaWin::CanPaste() { return false; } -static UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage) { - CHARSETINFO ci = { 0, 0, { { 0, 0, 0, 0 }, { 0, 0 } } }; - BOOL bci = ::TranslateCharsetInfo((DWORD*)characterSet, - &ci, TCI_SRCCHARSET); - - UINT cp; - if (bci) - cp = ci.ciACP; - else - cp = documentCodePage; - - CPINFO cpi; - if (!IsValidCodePage(cp) && !GetCPInfo(cp, &cpi)) - cp = CP_ACP; - - return cp; -} - class GlobalMemory { HGLOBAL hand; public: @@ -2191,10 +2203,10 @@ bool ScintillaWin::Register(HINSTANCE hInstance_) { hInstance = hInstance_; bool result; -#if 0 + // Register the Scintilla class if (IsNT()) { - //if (0) { + // Register Scintilla as a wide character window WNDCLASSEXW wndclass; wndclass.cbSize = sizeof(wndclass); @@ -2209,9 +2221,9 @@ bool ScintillaWin::Register(HINSTANCE hInstance_) { wndclass.lpszMenuName = NULL; wndclass.lpszClassName = L"Scintilla"; wndclass.hIconSm = 0; - result = ::RegisterClassExW(&wndclass); + result = ::RegisterClassExW(&wndclass) != 0; } else { -#endif + // Register Scintilla as a normal character window WNDCLASSEX wndclass; wndclass.cbSize = sizeof(wndclass); @@ -2227,7 +2239,7 @@ bool ScintillaWin::Register(HINSTANCE hInstance_) { wndclass.lpszClassName = scintillaClassName; wndclass.hIconSm = 0; result = ::RegisterClassEx(&wndclass) != 0; - //} + } if (result) { // Register the CallTip class |