diff options
author | nyamatongwe <unknown> | 2002-01-10 21:58:35 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2002-01-10 21:58:35 +0000 |
commit | d43d89fa81e0b04b762c2a9d58cb3d86d0400ec2 (patch) | |
tree | b0e72c136fb4a93c63ecdecad31d3c60ddef6209 | |
parent | 99502442f5bb65731554e5efb067c2ce0be9fa86 (diff) | |
download | scintilla-mirror-d43d89fa81e0b04b762c2a9d58cb3d86d0400ec2.tar.gz |
Patch from Kengo Jinno to make Japanese entry work on Windows 9x.
More changes from Neil to avoid problem introduced by above with overstrike
mode replacing one character with two.
Comments about Digital Mars ifdefs.
-rw-r--r-- | src/Editor.cxx | 61 | ||||
-rw-r--r-- | src/Editor.h | 2 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 4 | ||||
-rw-r--r-- | src/ScintillaBase.h | 2 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 28 |
5 files changed, 61 insertions, 36 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index f9afa81a1..44df21c99 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1914,7 +1914,7 @@ void Editor::AddChar(char ch) { AddCharUTF(s, 1); } -void Editor::AddCharUTF(char *s, unsigned int len) { +void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) { bool wasSelection = currentPos != anchor; ClearSelection(); if (inOverstrike && !wasSelection) { @@ -1931,37 +1931,42 @@ void Editor::AddCharUTF(char *s, unsigned int len) { ShowCaretAtCurrentPosition(); SetLastXChosen(); - int byte = static_cast<unsigned char>(s[0]); - if ((byte < 0xC0) || (1 == len)) { - // Handles UTF-8 characters between 0x01 and 0x7F and single byte - // characters when not in UTF-8 mode. - // Also treats \0 and naked trail bytes 0x80 to 0xBF as valid - // characters representing themselves. + if (treatAsDBCS) { + NotifyChar((static_cast<unsigned char>(s[0]) << 8) | + static_cast<unsigned char>(s[1])); } else { - // Unroll 1 to 3 byte UTF-8 sequences. See reference data at: - // http://www.cl.cam.ac.uk/~mgk25/unicode.html - // http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt - if (byte < 0xE0) { - int byte2 = static_cast<unsigned char>(s[1]); - if ((byte2 & 0xC0) == 0x80) { - // Two-byte-character lead-byte followed by a trail-byte. - byte = (((byte & 0x1F) << 6) | (byte2 & 0x3F)); - } - // A two-byte-character lead-byte not followed by trail-byte - // represents itself. - } else if (byte < 0xF0) { - int byte2 = static_cast<unsigned char>(s[1]); - int byte3 = static_cast<unsigned char>(s[2]); - if (((byte2 & 0xC0) == 0x80) && ((byte3 & 0xC0) == 0x80)) { - // Three-byte-character lead byte followed by two trail bytes. - byte = (((byte & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | - (byte3 & 0x3F)); + int byte = static_cast<unsigned char>(s[0]); + if ((byte < 0xC0) || (1 == len)) { + // Handles UTF-8 characters between 0x01 and 0x7F and single byte + // characters when not in UTF-8 mode. + // Also treats \0 and naked trail bytes 0x80 to 0xBF as valid + // characters representing themselves. + } else { + // Unroll 1 to 3 byte UTF-8 sequences. See reference data at: + // http://www.cl.cam.ac.uk/~mgk25/unicode.html + // http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt + if (byte < 0xE0) { + int byte2 = static_cast<unsigned char>(s[1]); + if ((byte2 & 0xC0) == 0x80) { + // Two-byte-character lead-byte followed by a trail-byte. + byte = (((byte & 0x1F) << 6) | (byte2 & 0x3F)); + } + // A two-byte-character lead-byte not followed by trail-byte + // represents itself. + } else if (byte < 0xF0) { + int byte2 = static_cast<unsigned char>(s[1]); + int byte3 = static_cast<unsigned char>(s[2]); + if (((byte2 & 0xC0) == 0x80) && ((byte3 & 0xC0) == 0x80)) { + // Three-byte-character lead byte followed by two trail bytes. + byte = (((byte & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | + (byte3 & 0x3F)); + } + // A three-byte-character lead-byte not followed by two trail-bytes + // represents itself. } - // A three-byte-character lead-byte not followed by two trail-bytes - // represents itself. } + NotifyChar(byte); } - NotifyChar(byte); } void Editor::ClearSelection() { diff --git a/src/Editor.h b/src/Editor.h index a9da3f9a1..1e2310513 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -295,7 +295,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void ChangeSize(); void AddChar(char ch); - virtual void AddCharUTF(char *s, unsigned int len); + virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false); void ClearSelection(); void ClearAll(); void ClearDocumentStyle(); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index fe732cabd..6b2bd8553 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -63,10 +63,10 @@ void ScintillaBase::RefreshColourPalette(Palette &pal, bool want) { ct.RefreshColourPalette(pal, want); } -void ScintillaBase::AddCharUTF(char *s, unsigned int len) { +void ScintillaBase::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) { bool acActiveBeforeCharAdded = ac.Active(); if (!acActiveBeforeCharAdded || !ac.IsFillUpChar(*s)) - Editor::AddCharUTF(s, len); + Editor::AddCharUTF(s, len, treatAsDBCS); if (acActiveBeforeCharAdded) AutoCompleteChanged(s[0]); } diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index 375cc9a74..0c1f6fee9 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -57,7 +57,7 @@ protected: virtual void RefreshColourPalette(Palette &pal, bool want); - virtual void AddCharUTF(char *s, unsigned int len); + virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false); void Command(int cmdId); virtual void CancelModes(); virtual int KeyCommand(unsigned int iMessage); diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index ccf7402a1..1eae2e1e8 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -410,8 +410,10 @@ static BOOL IsNT() { sptr_t ScintillaWin::HandleComposition(uptr_t wParam, sptr_t lParam) { #ifdef __DMC__ + // Digital Mars compiler does not include Imm library return 0; #else + sptr_t ret; if ((lParam & GCS_RESULTSTR) && (IsNT())) { HIMC hIMC = ::ImmGetContext(MainHWND()); if (hIMC) { @@ -436,10 +438,22 @@ sptr_t ScintillaWin::HandleComposition(uptr_t wParam, sptr_t lParam) { } ::ImmReleaseContext(MainHWND(), hIMC); } - return 0; + ret = 0; } else { - return ::DefWindowProc(MainHWND(), WM_IME_COMPOSITION, wParam, lParam); + ret = ::DefWindowProc(MainHWND(), WM_IME_COMPOSITION, wParam, lParam); + } + if ((lParam & GCS_RESULTSTR)) { + HIMC hIMC = ::ImmGetContext(MainHWND()); + Point pos = LocationFromPosition(currentPos); + COMPOSITIONFORM CompForm; + CompForm.dwStyle = CFS_POINT; + CompForm.ptCurrentPos.x = pos.x; + CompForm.ptCurrentPos.y = pos.y; + ::ImmSetCompositionWindow(hIMC, &CompForm); + ::ImmReleaseContext(MainHWND(), hIMC); + DropCaret(); } + return ret; #endif } @@ -1355,6 +1369,7 @@ DropTarget::DropTarget() { */ void ScintillaWin::ImeStartComposition() { #ifndef __DMC__ + // Digital Mars compiler does not include Imm library if (caret.active) { // Move IME Window to current caret position HIMC hIMC = ::ImmGetContext(MainHWND()); @@ -1405,7 +1420,7 @@ void ScintillaWin::ImeEndComposition() { void ScintillaWin::AddCharBytes(char b0, char b1) { int inputCodePage = InputCodePage(); - if (inputCodePage) { + if (inputCodePage && IsUnicodeMode()) { char utfval[4]="\0\0\0"; char ansiChars[3]; ansiChars[0] = b0; @@ -1417,9 +1432,14 @@ void ScintillaWin::AddCharBytes(char b0, char b1) { UTF8FromUCS2(wcs, 1, utfval, len); utfval[len] = '\0'; AddCharUTF(utfval,len); + } else if (b1) { + char dbcsChars[3]; + dbcsChars[0] = b0; + dbcsChars[1] = b1; + dbcsChars[2] = '\0'; + AddCharUTF(dbcsChars, strlen(dbcsChars), true); } else { AddChar(b0); - AddChar(b1); } } |