summaryrefslogtreecommitdiffstats
path: root/win/tkWinX.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-09-27 15:21:16 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-09-27 15:21:16 (GMT)
commit8982d2a60381e8ad4eb9305272f572d939a5d097 (patch)
tree5bc0701b49839f4c2039e46686b5432d58c23b2d /win/tkWinX.c
parentf43df857228b616f87644802136c05915d59d48b (diff)
parent506ee2fc81bb27e237860565c11a1494ab8c7b38 (diff)
downloadtk-8982d2a60381e8ad4eb9305272f572d939a5d097.zip
tk-8982d2a60381e8ad4eb9305272f572d939a5d097.tar.gz
tk-8982d2a60381e8ad4eb9305272f572d939a5d097.tar.bz2
Merge core-8-6-branch. More surrogate handling, e.g. in HandleIMEComposition()
Diffstat (limited to 'win/tkWinX.c')
-rw-r--r--win/tkWinX.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/win/tkWinX.c b/win/tkWinX.c
index 987fbb5..b2424ce 100644
--- a/win/tkWinX.c
+++ b/win/tkWinX.c
@@ -92,7 +92,7 @@ static Tcl_ThreadDataKey dataKey;
static void GenerateXEvent(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam);
static unsigned int GetState(UINT message, WPARAM wParam, LPARAM lParam);
-static void GetTranslatedKey(XKeyEvent *xkey);
+static void GetTranslatedKey(XKeyEvent *xkey, UINT type);
static void UpdateInputLanguage(int charset);
static int HandleIMEComposition(HWND hwnd, LPARAM lParam);
@@ -1157,7 +1157,8 @@ GenerateXEvent(
event.type = KeyPress;
event.xany.send_event = -1;
event.xkey.keycode = wParam;
- GetTranslatedKey(&event.xkey);
+ GetTranslatedKey(&event.xkey, (message == WM_KEYDOWN) ? WM_CHAR :
+ WM_SYSCHAR);
break;
case WM_SYSKEYUP:
@@ -1229,9 +1230,10 @@ GenerateXEvent(
if (IsDBCSLeadByte((BYTE) wParam)) {
MSG msg;
- if ((PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) != 0)
+ if ((PeekMessage(&msg, NULL, WM_CHAR, WM_CHAR,
+ PM_NOREMOVE) != 0)
&& (msg.message == WM_CHAR)) {
- GetMessage(&msg, NULL, 0, 0);
+ GetMessage(&msg, NULL, WM_CHAR, WM_CHAR);
event.xkey.nbytes = 2;
event.xkey.trans_chars[1] = (char) msg.wParam;
}
@@ -1370,19 +1372,20 @@ GetState(
static void
GetTranslatedKey(
- XKeyEvent *xkey)
+ XKeyEvent *xkey,
+ UINT type)
{
MSG msg;
xkey->nbytes = 0;
while ((xkey->nbytes < XMaxTransChars)
- && PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) {
- if ((msg.message != WM_CHAR) && (msg.message != WM_SYSCHAR)) {
+ && (PeekMessageA(&msg, NULL, type, type, PM_NOREMOVE) != 0)) {
+ if (msg.message != type) {
break;
}
- GetMessageA(&msg, NULL, 0, 0);
+ GetMessageA(&msg, NULL, type, type);
/*
* If this is a normal character message, we may need to strip off the
@@ -1523,7 +1526,7 @@ TkWinGetUnicodeEncoding(void)
*
* HandleIMEComposition --
*
- * This function works around a definciency in some versions of Windows
+ * This function works around a deficiency in some versions of Windows
* 2000 to make it possible to entry multi-lingual characters under all
* versions of Windows 2000.
*
@@ -1553,6 +1556,7 @@ HandleIMEComposition(
{
HIMC hIMC;
int n;
+ int high = 0;
if ((lParam & GCS_RESULTSTR) == 0) {
/*
@@ -1570,12 +1574,12 @@ HandleIMEComposition(
n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0);
if (n > 0) {
- char *buff = ckalloc(n);
+ WCHAR *buff = (WCHAR *) ckalloc(n);
TkWindow *winPtr;
XEvent event;
int i;
- n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, buff, (unsigned) n);
+ n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, buff, (unsigned) n) / 2;
/*
* Set up the fields pertinent to key event.
@@ -1600,7 +1604,6 @@ HandleIMEComposition(
event.xkey.state = TkWinGetModifierState();
event.xkey.time = TkpGetMS();
event.xkey.same_screen = True;
- event.xkey.nbytes = 0;
for (i=0; i<n; ) {
/*
@@ -1608,9 +1611,16 @@ HandleIMEComposition(
* UNICODE character in the composition.
*/
- event.xkey.keycode = ((unsigned char) buff[i++]) << 8;
- event.xkey.keycode += (unsigned char) buff[i++];
+ event.xkey.keycode = buff[i++];
+ if ((event.xkey.keycode & 0xfc00) == 0xd800) {
+ high = ((event.xkey.keycode & 0x3ff) << 10) + 0x10000;
+ break;
+ } else if (high && (event.xkey.keycode & 0xfc00) == 0xdc00) {
+ event.xkey.keycode &= 0x3ff;
+ event.xkey.keycode += high;
+ high = 0;
+ }
event.type = KeyPress;
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);