[Ttssh2-commit] [7487] IME前後参照変換が動作しなくなっていたので調整

scmno****@osdn***** scmno****@osdn*****
2019年 3月 17日 (日) 01:20:34 JST


Revision: 7487
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7487
Author:   zmatsuo
Date:     2019-03-17 01:20:33 +0900 (Sun, 17 Mar 2019)
Log Message:
-----------
IME前後参照変換が動作しなくなっていたので調整

Modified Paths:
--------------
    trunk/teraterm/teraterm/ttime.c
    trunk/teraterm/teraterm/ttime.h
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/teraterm/teraterm/ttime.c
===================================================================
--- trunk/teraterm/teraterm/ttime.c	2019-03-14 15:54:31 UTC (rev 7486)
+++ trunk/teraterm/teraterm/ttime.c	2019-03-16 16:20:33 UTC (rev 7487)
@@ -33,16 +33,16 @@
 #include <stdlib.h>
 #include <string.h>
 #include <imm.h>
+#include <crtdbg.h>
+#include <stdio.h>
+#include <assert.h>
 
 #include "ttime.h"
-#include "ttlib.h"
 
-#if 1
-#include "teraterm.h"
-#include "tttypes.h"
-#include "ttwinman.h"
-#include "ttcommon.h"
-#include "buffer.h"		// for BuffGetCurrentLineData()
+#ifdef _DEBUG
+#define malloc(l)	_malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
+#define calloc(l,n)	_calloc_dbg((l), (n), _NORMAL_BLOCK, __FILE__, __LINE__)
+#define free(p)		_free_dbg((p), _NORMAL_BLOCK)
 #endif
 
 // imm.h \x82\xAA include \x82ł\xAB\x82\xEA\x82\xCE _IMM_ \x82\xAA define \x82\xB3\x82\xEA\x82\xE9 \x81\xA8 \x82\xB1\x82̃u\x83\x8D\x83b\x83N\x95s\x97v?
@@ -60,6 +60,8 @@
 #define GCS_RESULTSTR 0x0800
 #endif //_IMM_
 
+// #define ENABLE_DUMP	1
+
 typedef LONG (WINAPI *TImmGetCompositionStringA)(HIMC, DWORD, LPVOID, DWORD);
 typedef LONG (WINAPI *TImmGetCompositionStringW)(HIMC, DWORD, LPVOID, DWORD);
 typedef HIMC (WINAPI *TImmGetContext)(HWND);
@@ -88,56 +90,57 @@
   char imm32_dll[MAX_PATH];
 
   if (HIMEDLL != NULL) return TRUE;
+
   GetSystemDirectoryA(imm32_dll, sizeof(imm32_dll));
   strncat_s(imm32_dll, sizeof(imm32_dll), "\\imm32.dll", _TRUNCATE);
   HIMEDLL = LoadLibraryA(imm32_dll);
   if (HIMEDLL == NULL)
   {
-    return FALSE;
+	return FALSE;
   }
 
   Err = FALSE;
 
   PImmGetCompositionStringW = (TImmGetCompositionStringW)GetProcAddress(
-    HIMEDLL, "ImmGetCompositionStringW");
+	HIMEDLL, "ImmGetCompositionStringW");
   if (PImmGetCompositionStringW==NULL) Err = TRUE;
 
   PImmGetCompositionStringA = (TImmGetCompositionStringA)GetProcAddress(
-    HIMEDLL, "ImmGetCompositionStringA");
+	HIMEDLL, "ImmGetCompositionStringA");
   if (PImmGetCompositionStringA==NULL) Err = TRUE;
 
   PImmGetContext = (TImmGetContext)GetProcAddress(
-    HIMEDLL, "ImmGetContext");
+	HIMEDLL, "ImmGetContext");
   if (PImmGetContext==NULL) Err = TRUE;
 
   PImmReleaseContext = (TImmReleaseContext)GetProcAddress(
-    HIMEDLL, "ImmReleaseContext");
+	HIMEDLL, "ImmReleaseContext");
   if (PImmReleaseContext==NULL) Err = TRUE;
 
   PImmSetCompositionFont = (TImmSetCompositionFont)GetProcAddress(
-    HIMEDLL, "ImmSetCompositionFontA");
+	HIMEDLL, "ImmSetCompositionFontA");
   if (PImmSetCompositionFont==NULL) Err = TRUE;
 
   PImmSetCompositionWindow = (TImmSetCompositionWindow)GetProcAddress(
-    HIMEDLL, "ImmSetCompositionWindow");
+	HIMEDLL, "ImmSetCompositionWindow");
   if (PImmSetCompositionWindow==NULL) Err = TRUE;
 
   PImmGetOpenStatus = (TImmGetOpenStatus)GetProcAddress(
-    HIMEDLL, "ImmGetOpenStatus");
+	HIMEDLL, "ImmGetOpenStatus");
   if (PImmGetOpenStatus==NULL) Err = TRUE;
 
   PImmSetOpenStatus = (TImmSetOpenStatus)GetProcAddress(
-    HIMEDLL, "ImmSetOpenStatus");
+	HIMEDLL, "ImmSetOpenStatus");
   if (PImmSetOpenStatus==NULL) Err = TRUE;
 
   if ( Err )
   {
-    FreeLibrary(HIMEDLL);
-    HIMEDLL = NULL;
-    return FALSE;
+	FreeLibrary(HIMEDLL);
+	HIMEDLL = NULL;
+	return FALSE;
   }
-  else
-    return TRUE;
+
+  return TRUE;
 }
 
 void FreeIME(HWND hWnd)
@@ -169,12 +172,12 @@
   hIMC = (*PImmGetContext)(HWnd);
   if (X>=0)
   {
-    cf.dwStyle = CFS_POINT;
-    cf.ptCurrentPos.x = X;
-    cf.ptCurrentPos.y = Y;
+	cf.dwStyle = CFS_POINT;
+	cf.ptCurrentPos.x = X;
+	cf.ptCurrentPos.y = Y;
   }
   else
-    cf.dwStyle = CFS_DEFAULT;
+	cf.dwStyle = CFS_DEFAULT;
   (*PImmSetCompositionWindow)(hIMC,&cf);
   (*PImmReleaseContext)(HWnd,hIMC);
 }
@@ -192,48 +195,123 @@
   (*PImmReleaseContext)(HWnd,hIMC);
 }
 
+// \x93\xE0\x95\x94\x97p
+static const char *GetConvStringA_i(HWND hWnd, DWORD index, size_t *len)
+{
+	HIMC hIMC;
+	LONG size;
+	char *lpstr;
+
+	hIMC = (*PImmGetContext)(hWnd);
+	if (hIMC==0)
+		goto error_2;
+
+	// Get the size of the result string.
+	//		\x92\x8D\x88\xD3 ImmGetCompositionStringA() \x82̖߂\xE8\x92l\x82\xCD byte \x90\x94
+	size = PImmGetCompositionStringA(hIMC, index, NULL, 0);
+	if (size <= 0)
+		goto error_1;
+
+	lpstr = malloc(size + sizeof(char));
+	if (lpstr == NULL)
+		goto error_1;
+
+	size = PImmGetCompositionStringA(hIMC, index, lpstr, size);
+	if (size <= 0) {
+		free(lpstr);
+		goto error_1;
+	}
+
+	*len = size;
+	lpstr[size] = 0;	// \x83^\x81[\x83~\x83l\x81[\x83g\x82\xB7\x82\xE9
+
+	(*PImmReleaseContext)(hWnd, hIMC);
+	return lpstr;
+
+error_1:
+	(*PImmReleaseContext)(hWnd, hIMC);
+error_2:
+	*len = 0;
+	return NULL;
+}
+
+// \x93\xE0\x95\x94\x97p wchar_t\x94\xC5
+static const wchar_t *GetConvStringW_i(HWND hWnd, DWORD index, size_t *len)
+{
+	HIMC hIMC;
+	LONG size;
+	wchar_t *lpstr;
+
+	hIMC = (*PImmGetContext)(hWnd);
+	if (hIMC==0)
+		goto error_2;
+
+	// Get the size of the result string.
+	//		\x92\x8D\x88\xD3 ImmGetCompositionStringW() \x82̖߂\xE8\x92l\x82\xCD byte \x90\x94
+	size = PImmGetCompositionStringW(hIMC, index, NULL, 0);
+	if (size <= 0)
+		goto error_1;
+
+	lpstr = malloc(size + sizeof(wchar_t));
+	if (lpstr == NULL)
+		goto error_1;
+
+	size = PImmGetCompositionStringW(hIMC, index, lpstr, size);
+	if (size <= 0) {
+		free(lpstr);
+		goto error_1;
+	}
+
+	*len = size/2;
+	lpstr[(size/2)] = 0;	// \x83^\x81[\x83~\x83l\x81[\x83g\x82\xB7\x82\xE9
+
+	(*PImmReleaseContext)(hWnd, hIMC);
+	return lpstr;
+
+error_1:
+	(*PImmReleaseContext)(hWnd, hIMC);
+error_2:
+	*len = 0;
+	return NULL;
+}
+
 /*
- *	@param[in,out]	*len	wchar_t\x95\xB6\x8E\x9A\x90\x94
- *	@reterun		\x95ϊ\xB7wchar_t\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+ *	@param[out]		*len	wchar_t\x95\xB6\x8E\x9A\x90\x94('\0'\x82͊܂܂Ȃ\xA2)
+ *	@retval			\x95ϊ\xB7wchar_t\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
  *					NULL\x82̏ꍇ\x95ϊ\xB7\x8Am\x92肵\x82Ă\xA2\x82Ȃ\xA2(\x82܂\xBD\x82̓G\x83\x89\x81[)
  *					\x95\xB6\x8E\x9A\x97\xF1\x82͎g\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6
  */
-const wchar_t *GetConvString(HWND hWnd, UINT wParam, LPARAM lParam, size_t *len)
+const wchar_t *GetConvStringW(HWND hWnd, LPARAM lParam, size_t *len)
 {
-	wchar_t *lpstr;
+	const wchar_t *lpstr;
 
 	*len = 0;
 	if (HIMEDLL==NULL) return NULL;
 
 	if ((lParam & GCS_RESULTSTR) != 0) {
-		HIMC hIMC;
-		LONG size;
+		lpstr = GetConvStringW_i(hWnd, GCS_RESULTSTR, len);
+	} else {
+		lpstr = NULL;
+	}
 
-		hIMC = (*PImmGetContext)(hWnd);
-		if (hIMC==0) return NULL;
+	return lpstr;
+}
 
-		// Get the size of the result string.
-		//		\x92\x8D\x88\xD3 ImmGetCompositionStringW() \x82̖߂\xE8\x92l\x82\xCD byte \x90\x94
-		size = PImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
-		if (size <= 0) {
-			lpstr = NULL;		// \x83G\x83\x89\x81[
-		} else {
-			lpstr = malloc(size + sizeof(WCHAR));
-			if (lpstr != NULL)
-			{
-				size = PImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpstr, size);
-				if (size <= 0) {
-					free(lpstr);
-					lpstr = NULL;
-				} else {
-					*len = size/2;
-					lpstr[(size/2)] = 0;	// \x83^\x81[\x83~\x83l\x81[\x83g\x82\xB7\x82\xE9
-				}
-			}
-		}
+/*
+ *	@param[out]		*len	\x95\xB6\x8E\x9A\x90\x94('\0'\x82͊܂܂Ȃ\xA2)
+ *	@retval			\x95ϊ\xB7\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+ *					NULL\x82̏ꍇ\x95ϊ\xB7\x8Am\x92肵\x82Ă\xA2\x82Ȃ\xA2(\x82܂\xBD\x82̓G\x83\x89\x81[)
+ *					\x95\xB6\x8E\x9A\x97\xF1\x82͎g\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6
+ */
+const char *GetConvStringA(HWND hWnd, LPARAM lParam, size_t *len)
+{
+	const char *lpstr;
 
-		(*PImmReleaseContext)(hWnd, hIMC);
+	*len = 0;
+	if (HIMEDLL==NULL) return NULL;
 
+	if ((lParam & GCS_RESULTSTR) != 0) {
+		lpstr = GetConvStringA_i(hWnd, GCS_RESULTSTR, len);
 	} else {
 		lpstr = NULL;
 	}
@@ -252,7 +330,6 @@
 	(*PImmReleaseContext)(hWnd, hIMC);
 
 	return stat;
-
 }
 
 void SetIMEOpenStatus(HWND hWnd, BOOL stat)
@@ -265,73 +342,182 @@
 	(*PImmReleaseContext)(hWnd, hIMC);
 }
 
+#if defined(ENABLE_DUMP)
+static void DumpReconvStringSt(RECONVERTSTRING *pReconv, BOOL unicode)
+{
+	if (unicode) {
+		wchar_t tmp[1024];
+		_snwprintf(tmp, _countof(tmp),
+				   L"Str %d,%d CompStr %d,%d TargeteStr %d,%d '%s'\n",
+				   pReconv->dwStrLen,
+				   pReconv->dwStrOffset,
+				   pReconv->dwCompStrLen,
+				   pReconv->dwCompStrOffset,
+				   pReconv->dwTargetStrLen,
+				   pReconv->dwTargetStrOffset,
+				   (wchar_t *)(((char *)pReconv) + pReconv->dwStrOffset)
+			);
+		OutputDebugStringW(tmp);
+	} else {
+		char tmp[1024];
+		_snprintf(tmp, sizeof(tmp),
+				  "Str %d,%d CompStr %d,%d TargeteStr %d,%d '%s'\n",
+				  pReconv->dwStrLen,
+				  pReconv->dwStrOffset,
+				  pReconv->dwCompStrLen,
+				  pReconv->dwCompStrOffset,
+				  pReconv->dwTargetStrLen,
+				  pReconv->dwTargetStrOffset,
+				  (((char *)pReconv) + pReconv->dwStrOffset)
+			);
+		OutputDebugStringA(tmp);
+	}
+}
+#endif
+
 // IME\x82̑O\x8C\xE3\x8EQ\x8Fƕϊ\xB7\x8B@\x94\\x82ւ̑Ή\x9E
 // MS\x82\xA9\x82炿\x82\xE1\x82\xF1\x82Ǝd\x97l\x82\xAA\x92񎦂\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2\x82̂ŁA\x83A\x83h\x83z\x83b\x83N\x82ɂ\xE2\x82邵\x82\xA9\x82Ȃ\xA2\x82炵\x82\xA2\x81B
 // cf. http://d.hatena.ne.jp/topiyama/20070703
-//     http://ice.hotmint.com/putty/#DOWNLOAD
-//     http://27213143.at.webry.info/201202/article_2.html
-//     http://webcache.googleusercontent.com/search?q=cache:WzlX3ouMscIJ:anago.2ch.net/test/read.cgi/software/1325573999/82+IMR_DOCUMENTFEED&cd=13&hl=ja&ct=clnk&gl=jp
+//	   http://ice.hotmint.com/putty/#DOWNLOAD
+//	   http://27213143.at.webry.info/201202/article_2.html
+//	   http://webcache.googleusercontent.com/search?q=cache:WzlX3ouMscIJ:anago.2ch.net/test/read.cgi/software/1325573999/82+IMR_DOCUMENTFEED&cd=13&hl=ja&ct=clnk&gl=jp
 // (2012.5.9 yutaka)
-LRESULT ReplyIMERequestDocumentfeed(HWND hWnd, LPARAM lParam, int NumOfColumns)
+/**
+ * IME\x82̑O\x8C\xE3\x8EQ\x8Fƕϊ\xB7\x8B@\x94\\x97p\x8D\\x91\xA2\x91̂\xF0\x8D쐬\x82\xB7\x82\xE9
+ *		msg == WM_IME_REQUEST,wParam == IMR_DOCUMENTFEED \x82̉\x9E\x93\x9A\x82Ɏg\x82\xA4
+ *		ANSI\x82\xA9Unicode\x83E\x83B\x83\x93\x83h\x83E\x82ɂ\xE6\x82\xC1\x82ĎQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82\xF0\x95ύX\x82\xB7\x82邱\x82\xC6
+ * unicode		TRUE\x82̂Ƃ\xABunicode
+ * str_ptr		\x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+ * str_count	\x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82̕\xB6\x8E\x9A\x90\x94(char\x82Ȃ\xE7bytes\x90\x94,wchar_t\x82Ȃ\xE7wchar_t\x90\x94)
+ * cx			\x83J\x81[\x83\\x83\x8B\x88ʒu(char/wchar_t\x92P\x88\xCA)
+ * st_size		\x90\xB6\x90\xAC\x82\xB5\x82\xBD\x8D\\x91\xA2\x91̂̃T\x83C\x83Y
+ * \x96߂\xE8\x92l		\x8D\\x91\xA2\x91̂ւ̃|\x83C\x83\x93\x83^
+ *				\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free()\x82\xB7\x82邱\x82\xC6
+ */
+static void *CreateReconvStringSt(HWND hWnd, BOOL unicode,
+								  const void *str_ptr, size_t str_count,
+								  size_t cx, size_t *st_size_)
 {
-	static int complen, newsize;
-	static char comp[512];
-	int size, ret;
-	char buf[512], newbuf[1024];
-	HIMC hIMC;
-	int cx;
+	static int new_str_len_bytes;
+	static int new_buf_len_bytes;
+	int new_str_len_count;
+	int str_len_bytes;
+	size_t str_len_count;
+	int cx_bytes;
+	RECONVERTSTRING *pReconv;
+	const void *comp_ptr;
+	size_t complen_count;
+	size_t complen_bytes;
+	const void *buf;
+	size_t st_size;
 
-	// "IME=off"\x82̏ꍇ\x82́A\x89\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2\x81B
-	size = NumOfColumns + 1;   // \x83J\x81[\x83\\x83\x8B\x82\xAA\x82\xA0\x82\xE9\x8Ds\x82̒\xB7\x82\xB3+null
+	buf = str_ptr;
+	str_len_count = str_count;
 
-	if (lParam == 0) {  // 1\x89\xF1\x96ڂ̌Ăяo\x82\xB5
-		// \x83o\x83b\x83t\x83@\x82̃T\x83C\x83Y\x82\xF0\x95Ԃ\xB7\x82̂݁B
-		// ATOK2012\x82ł͏\xED\x82\xC9 complen=0 \x82ƂȂ\xE9\x81B
-		complen = 0;
-		memset(comp, 0, sizeof(comp));
-		hIMC = PImmGetContext(hWnd);
-		if (hIMC) {
-			ret = PImmGetCompositionStringA(hIMC, GCS_COMPSTR, comp, sizeof(comp));
-			if (ret == IMM_ERROR_NODATA || ret == IMM_ERROR_GENERAL) {
-				memset(comp, 0, sizeof(comp));
-			}
-			complen = strlen(comp);  // w/o null
-			PImmReleaseContext(hWnd, hIMC);
-		}
-		newsize = size + complen;  // \x95ϊ\xB7\x95\xB6\x8E\x9A\x82\xE0\x8A܂߂\xBD\x91S\x91̂̒\xB7\x82\xB3(including null)
+	if(unicode) {
+		str_len_bytes = str_len_count * sizeof(wchar_t);
+		cx_bytes = cx * sizeof(wchar_t);
+	} else {
+		str_len_bytes = str_len_count;
+		cx_bytes = cx;
+	}
 
-	} else {  // 2\x89\xF1\x96ڂ̌Ăяo\x82\xB5
-		//lParam \x82\xF0 RECONVERTSTRING \x82\xC6 \x95\xB6\x8E\x9A\x97\xF1\x8Ai\x94[\x83o\x83b\x83t\x83@\x82Ɏg\x97p\x82\xB7\x82\xE9
-		RECONVERTSTRING *pReconv   = (RECONVERTSTRING*)lParam;
-		char*  pszParagraph        = (char*)pReconv + sizeof(RECONVERTSTRING);
+	// \x95ϊ\xB7\x92\x86\x8C\xF3\x95╶\x8E\x9A\x97\xF1\x82\xF0\x8E擾
+	// ATOK2012\x82ł͏\xED\x82\xC9 complen_count=0 \x82ƂȂ\xE9\x81B
+	if (!unicode) {
+		const char *comp_strA;
+		comp_strA = GetConvStringA_i(hWnd, GCS_COMPSTR, &complen_count);
+		complen_bytes = complen_count;
+		comp_ptr = comp_strA;
+	} else {
+		const wchar_t *comp_strW;
+		comp_strW = GetConvStringW_i(hWnd,GCS_COMPSTR,	&complen_count);
+		complen_bytes = complen_count * sizeof(wchar_t);
+		comp_ptr = comp_strW;
+	}
 
-		cx = BuffGetCurrentLineData(buf, sizeof(buf));
+	// \x95ϊ\xB7\x95\xB6\x8E\x9A\x82\xE0\x8A܂߂\xBD\x91S\x91̂̒\xB7\x82\xB3(including null)
+	if (!unicode) {
+		new_str_len_bytes = str_len_bytes + complen_bytes;
+		new_buf_len_bytes = new_str_len_bytes + 1;
+		new_str_len_count = new_str_len_bytes;
+	} else {
+		new_str_len_bytes = str_len_bytes + complen_bytes;
+		new_buf_len_bytes = new_str_len_bytes + sizeof(wchar_t);
+		new_str_len_count = new_str_len_bytes / sizeof(wchar_t);
+	}
 
-		// \x83J\x81[\x83\\x83\x8B\x88ʒu\x82ɕϊ\xB7\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x91}\x93\xFC\x82\xB7\x82\xE9\x81B
-		memset(newbuf, 0, sizeof(newbuf));
-		memcpy(newbuf, buf, cx);
-		memcpy(newbuf + cx, comp, complen);
-		memcpy(newbuf + cx + complen, buf + cx, size - cx);
-		newsize = size + complen;  // \x95ϊ\xB7\x95\xB6\x8E\x9A\x82\xE0\x8A܂߂\xBD\x91S\x91̂̒\xB7\x82\xB3(including null)
+	st_size = sizeof(RECONVERTSTRING) + new_buf_len_bytes;
+	pReconv = calloc(1, st_size);
 
-		pReconv->dwSize            = sizeof(RECONVERTSTRING);
-		pReconv->dwVersion         = 0;
-		pReconv->dwStrLen          = newsize - 1;
-		pReconv->dwStrOffset       = sizeof(RECONVERTSTRING);
-		pReconv->dwCompStrLen      = complen;
-		pReconv->dwCompStrOffset   = cx;
-		pReconv->dwTargetStrLen    = complen;
-		pReconv->dwTargetStrOffset = cx;
+	// Len\x82͕\xB6\x8E\x9A\x90\x94(char/wchar_t\x92P\x88\xCA)
+	// Offset\x82\xCDbyte\x92P\x88\xCA
+//	pReconv->dwSize				= sizeof(RECONVERTSTRING);
+	pReconv->dwSize				= sizeof(RECONVERTSTRING) + new_buf_len_bytes;
+	pReconv->dwVersion			= 0;
+	pReconv->dwStrLen			= new_str_len_count;
+	pReconv->dwStrOffset		= sizeof(RECONVERTSTRING);
+	pReconv->dwCompStrLen		= complen_count;
+	pReconv->dwCompStrOffset	= cx_bytes;
+	pReconv->dwTargetStrLen		= complen_count;		// = dwCompStrOffset
+	pReconv->dwTargetStrOffset	= cx_bytes;				// = dwTargetStrLen
 
-		memcpy(pszParagraph, newbuf, newsize);
+	// RECONVERTSTRING\x82̌\xE3\x82\xEB\x82\xC9
+	// \x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82\xF0\x83R\x83s\x81[+\x83J\x81[\x83\\x83\x8B\x88ʒu\x82ɕϕ\xB6\x8E\x9A\x97\xF1\x82\xF0\x91}\x93\xFC
+	char *newbuf = (char *)pReconv + sizeof(RECONVERTSTRING);
+	if (comp_ptr != NULL) {
+		memcpy(newbuf, buf, cx_bytes);
+		newbuf += cx_bytes;
+		memcpy(newbuf, comp_ptr, complen_bytes);
+		newbuf += complen_bytes;
+		memcpy(newbuf, (char *)buf + cx_bytes, str_len_bytes - cx_bytes);
+		free((void *)comp_ptr);
+		comp_ptr = NULL;
+	} else {
+		memcpy(newbuf, buf, str_len_bytes);
 	}
-
-#if 0
-	OutputDebugPrintf("WM_IME_REQUEST,IMR_DOCUMENTFEED size %d\n", newsize);
-	if (lParam == 1) {
-		OutputDebugPrintf("cx %d buf [%d:%s] -> [%d:%s]\n", cx, size, buf, newsize, newbuf);
-	}
+#if defined(ENABLE_DUMP)
+	DumpReconvStringSt(pReconv, unicode);
 #endif
 
-	return (sizeof(RECONVERTSTRING) + newsize);
+	*st_size_ = st_size;
+	return pReconv;
 }
+
+/**
+ * IME\x82̑O\x8C\xE3\x8EQ\x8Fƕϊ\xB7\x8B@\x94\\x97p\x8D\\x91\xA2\x91̂\xF0\x8D쐬\x82\xB7\x82\xE9
+ * ANSI\x83E\x83B\x83\x93\x83h\x83E\x97p
+ *		msg == WM_IME_REQUEST,wParam == IMR_DOCUMENTFEED \x82̉\x9E\x93\x9A\x82Ɏg\x82\xA4
+ * str_ptr		\x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+ * str_count	\x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82̕\xB6\x8E\x9A\x90\x94(char\x90\x94,bytes\x90\x94)
+ * cx			\x83J\x81[\x83\\x83\x8B\x88ʒu(char\x92P\x88\xCA)
+ * st_size		\x90\xB6\x90\xAC\x82\xB5\x82\xBD\x8D\\x91\xA2\x91̂̃T\x83C\x83Y(byte)
+ * \x96߂\xE8\x92l		\x8D\\x91\xA2\x91̂ւ̃|\x83C\x83\x93\x83^
+ *				\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free()\x82\xB7\x82邱\x82\xC6
+ */
+void *CreateReconvStringStA(
+	HWND hWnd, const char *str_ptr, size_t str_count,
+	size_t cx, size_t *st_size_)
+{
+	assert(IsWindowUnicode(hWnd) == FALSE);
+	return CreateReconvStringSt(hWnd, FALSE, str_ptr, str_count, cx, st_size_);
+}
+
+/**
+ * IME\x82̑O\x8C\xE3\x8EQ\x8Fƕϊ\xB7\x8B@\x94\\x97p\x8D\\x91\xA2\x91̂\xF0\x8D쐬\x82\xB7\x82\xE9
+ * unicode\x83E\x83B\x83\x93\x83h\x83E\x97p
+ *		msg == WM_IME_REQUEST,wParam == IMR_DOCUMENTFEED \x82̉\x9E\x93\x9A\x82Ɏg\x82\xA4
+ * str_ptr		\x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+ * str_count	\x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82̕\xB6\x8E\x9A\x90\x94(wchar_t\x90\x94)
+ * cx			\x83J\x81[\x83\\x83\x8B\x88ʒu(wchar_t\x92P\x88\xCA)
+ * st_size		\x90\xB6\x90\xAC\x82\xB5\x82\xBD\x8D\\x91\xA2\x91̂̃T\x83C\x83Y(byte)
+ * \x96߂\xE8\x92l		\x8D\\x91\xA2\x91̂ւ̃|\x83C\x83\x93\x83^
+ *				\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free()\x82\xB7\x82邱\x82\xC6
+ */
+void *CreateReconvStringStW(
+	HWND hWnd, const wchar_t *str_ptr, size_t str_count,
+	size_t cx, size_t *st_size_)
+{
+	assert(IsWindowUnicode(hWnd) == TRUE);
+	return CreateReconvStringSt(hWnd, TRUE, str_ptr, str_count, cx, st_size_);
+}

Modified: trunk/teraterm/teraterm/ttime.h
===================================================================
--- trunk/teraterm/teraterm/ttime.h	2019-03-14 15:54:31 UTC (rev 7486)
+++ trunk/teraterm/teraterm/ttime.h	2019-03-16 16:20:33 UTC (rev 7487)
@@ -41,8 +41,14 @@
 void SetConversionLogFont(HWND HWnd, PLOGFONTA lf);
 BOOL GetIMEOpenStatus(HWND hWnd);
 void SetIMEOpenStatus(HWND hWnd, BOOL stat);
-const wchar_t *GetConvString(HWND hWnd, UINT wParam, LPARAM lParam, size_t *len);
-LRESULT ReplyIMERequestDocumentfeed(HWND hWnd, LPARAM lParam, int NumOfColumns);
+const wchar_t *GetConvStringW(HWND hWnd, LPARAM lParam, size_t *len);
+//const char *GetConvStringA(HWND hWnd, LPARAM lParam, size_t *len);
+void *CreateReconvStringStW(HWND hWnd,
+							const wchar_t *str_ptr, size_t str_count,
+							size_t cx, size_t *st_size_);
+void *CreateReconvStringStA(HWND hWnd,
+							const char *str_ptr, size_t str_count,
+							size_t cx, size_t *st_size_);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2019-03-14 15:54:31 UTC (rev 7486)
+++ trunk/teraterm/teraterm/vtwin.cpp	2019-03-16 16:20:33 UTC (rev 7487)
@@ -71,6 +71,7 @@
 #include <windowsx.h>
 #include <imm.h>
 #include <Dbt.h>
+#include <assert.h>
 
 #include "tt_res.h"
 #include "vtwin.h"
@@ -3224,7 +3225,7 @@
 {
 	if (CanUseIME()) {
 		size_t len;
-		const wchar_t *lpstr = GetConvString(HVTWin, wParam, lParam, &len);
+		const wchar_t *lpstr = GetConvStringW(HVTWin, lParam, &len);
 		if (lpstr != NULL) {
 			const wchar_t *output_wstr = lpstr;
 			if (len == 1 && ControlKey()) {
@@ -3302,6 +3303,67 @@
 	return CFrameWnd::DefWindowProc(WM_IME_NOTIFY,wParam,lParam);
 }
 
+static LRESULT ReplyIMERequestDocumentfeed(HWND hWnd, LPARAM lParam)
+{
+	static RECONVERTSTRING *pReconvPtrSave;		// TODO leak
+	static size_t ReconvSizeSave;
+	LRESULT result;
+
+	if (lParam == 0)
+	{  // 1\x89\xF1\x96ڂ̌Ăяo\x82\xB5 \x83T\x83C\x83Y\x82\xBE\x82\xAF\x82\xF0\x95Ԃ\xB7
+		char buf[512];			// \x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E󂯎\xE6\x82\xE9\x83o\x83b\x83t\x83@
+		size_t str_len_count;
+		int cx;
+		assert(IsWindowUnicode(hWnd) == FALSE);
+
+		// \x8EQ\x8Fƕ\xB6\x8E\x9A\x97\xF1\x8E擾\x81A1\x8Ds\x8E\xE6\x82\xE8\x8Fo\x82\xB7
+		{	// \x83J\x81[\x83\\x83\x8B\x82\xA9\x82\xE7\x8C\xE3\x82\xEB\x81A\x83X\x83y\x81[\x83X\x88ȊO\x82\xAA\x8C\xA9\x82‚\xA9\x82\xC1\x82\xBD\x82Ƃ\xB1\x82\xEB\x82\xF0\x8Ds\x96\x96\x82Ƃ\xB7\x82\xE9
+			int x;
+			int len;
+			cx = BuffGetCurrentLineData(buf, sizeof(buf));
+			len = cx;
+			for (x=cx; x < NumOfColumns; x++) {
+				const char c = buf[x];
+				if (c != 0 && c != 0x20) {
+					len = x+1;
+				}
+			}
+			str_len_count = len;
+		}
+
+		// IME\x82ɕԂ\xB7\x8D\\x91\xA2\x91̂\xF0\x8D쐬\x82\xB7\x82\xE9
+		if (pReconvPtrSave != NULL) {
+			free(pReconvPtrSave);
+		}
+		pReconvPtrSave = (RECONVERTSTRING *)CreateReconvStringStA(
+			hWnd, buf, str_len_count, cx, &ReconvSizeSave);
+
+		// 1\x89\xF1\x96ڂ̓T\x83C\x83Y\x82\xBE\x82\xAF\x82\xF0\x95Ԃ\xB7
+		result = ReconvSizeSave;
+	}
+	else {
+		// 2\x89\xF1\x96ڂ̌Ăяo\x82\xB5 \x8D\\x91\xA2\x91̂\xF0\x93n\x82\xB7
+		if (pReconvPtrSave != NULL) {
+			RECONVERTSTRING *pReconv = (RECONVERTSTRING*)lParam;
+			memcpy(pReconv, pReconvPtrSave, ReconvSizeSave);
+			result = ReconvSizeSave;
+			free(pReconvPtrSave);
+			pReconvPtrSave = NULL;
+			ReconvSizeSave = 0;
+		} else {
+			// 3\x89\xF1\x96\xDA?
+			result = 0;
+		}
+	}
+
+#if 0
+	OutputDebugPrintf("WM_IME_REQUEST,IMR_DOCUMENTFEED lp=%p LRESULT %d\n",
+		lParam, result);
+#endif
+
+	return result;
+}
+
 LRESULT CVTWindow::OnIMERequest(WPARAM wParam, LPARAM lParam)
 {
 	// "IME=off"\x82̏ꍇ\x82́A\x89\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2\x81B
@@ -3308,7 +3370,7 @@
 	if (ts.UseIME > 0) {
 		switch(wParam) {
 		case IMR_DOCUMENTFEED:
-			return ReplyIMERequestDocumentfeed(HVTWin, lParam, NumOfColumns);
+			return ReplyIMERequestDocumentfeed(HVTWin, lParam);
 		default:
 			break;
 		}


Ttssh2-commit メーリングリストの案内