[Ttssh2-commit] [7470] ime関連修正

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 3月 10日 (日) 23:32:45 JST


Revision: 7470
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7470
Author:   zmatsuo
Date:     2019-03-10 23:32:45 +0900 (Sun, 10 Mar 2019)
Log Message:
-----------
ime関連修正

Modified Paths:
--------------
    branches/cmake/teraterm/teraterm/ttime.c
    branches/cmake/teraterm/teraterm/ttime.h

-------------- next part --------------
Modified: branches/cmake/teraterm/teraterm/ttime.c
===================================================================
--- branches/cmake/teraterm/teraterm/ttime.c	2019-03-10 14:32:33 UTC (rev 7469)
+++ branches/cmake/teraterm/teraterm/ttime.c	2019-03-10 14:32:45 UTC (rev 7470)
@@ -1,4 +1,4 @@
-/*
+/*
  * Copyright (C) 1994-1998 T. Teranishi
  * (C) 2007-2017 TeraTerm Project
  * All rights reserved.
@@ -67,7 +67,7 @@
 typedef BOOL (WINAPI *TImmGetOpenStatus)(HIMC);
 typedef BOOL (WINAPI *TImmSetOpenStatus)(HIMC, BOOL);
 
-static TImmGetCompositionString PImmGetCompositionString;
+static TImmGetCompositionString PImmGetCompositionStringW;
 static TImmGetContext PImmGetContext;
 static TImmReleaseContext PImmReleaseContext;
 static TImmSetCompositionFont PImmSetCompositionFont;
@@ -115,9 +115,9 @@
 
   Err = FALSE;
 
-  PImmGetCompositionString = (TImmGetCompositionString)GetProcAddress(
-    HIMEDLL, "ImmGetCompositionStringA");
-  if (PImmGetCompositionString==NULL) Err = TRUE;
+  PImmGetCompositionStringW = (TImmGetCompositionString)GetProcAddress(
+    HIMEDLL, "ImmGetCompositionStringW");
+  if (PImmGetCompositionStringW==NULL) Err = TRUE;
 
   PImmGetContext = (TImmGetContext)GetProcAddress(
     HIMEDLL, "ImmGetContext");
@@ -189,61 +189,69 @@
   else
     cf.dwStyle = CFS_DEFAULT;
   (*PImmSetCompositionWindow)(hIMC,&cf);
+  (*PImmReleaseContext)(HVTWin,hIMC);
+}
 
+void SetConversionLogFont(HWND HWin, PLOGFONT lf)
+{
+  HIMC	hIMC;
+  if (HIMEDLL == NULL) return;
+
+  memcpy(&lfIME,lf,sizeof(LOGFONT));
+
+  hIMC = (*PImmGetContext)(HVTWin);
   // Set font for the conversion window
   (*PImmSetCompositionFont)(hIMC,&lfIME);
   (*PImmReleaseContext)(HVTWin,hIMC);
 }
 
-void SetConversionLogFont(PLOGFONTA lf)
+/*
+ *	@param[in,out]	*len	wchar_t文字数
+ *	@reterun		変換wchar_t文字列へのポインタ
+ *					NULLの場合変換確定していない(またはエラー)
+ *					文字列は使用後free()すること
+ */
+const wchar_t *GetConvString(HWND hWnd, UINT wParam, LPARAM lParam, size_t *len)
 {
-  memcpy(&lfIME,lf,sizeof(*lf));
-}
-
-HGLOBAL GetConvString(UINT wParam, LPARAM lParam)
-{
-	HIMC hIMC;
-	HGLOBAL hstr = NULL;
-	//LPSTR lpstr;
 	wchar_t *lpstr;
-	DWORD dwSize;
 
+	*len = 0;
 	if (HIMEDLL==NULL) return NULL;
-	hIMC = (*PImmGetContext)(HVTWin);
-	if (hIMC==0) return NULL;
 
-	if ((lParam & GCS_RESULTSTR)==0)
-		goto skip;
+	if ((lParam & GCS_RESULTSTR) != 0) {
+		HIMC hIMC;
+		LONG size;
 
-	// Get the size of the result string.
-	//dwSize = (*PImmGetCompositionString)(hIMC, GCS_RESULTSTR, NULL, 0);
-	dwSize = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
-	dwSize += sizeof(WCHAR);
-	hstr = GlobalAlloc(GHND,dwSize);
-	if (hstr != NULL)
-	{
-//		lpstr = (LPSTR)GlobalLock(hstr);
-		lpstr = GlobalLock(hstr);
-		if (lpstr != NULL)
-		{
-#if 0
-			// Get the result strings that is generated by IME into lpstr.
-			(*PImmGetCompositionString)
-				(hIMC, GCS_RESULTSTR, lpstr, dwSize);
-#else
-			ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpstr, dwSize);
-#endif
-			GlobalUnlock(hstr);
+		hIMC = (*PImmGetContext)(hWnd);
+		if (hIMC==0) return NULL;
+
+		// Get the size of the result string.
+		//		注意 ImmGetCompositionStringW() の戻り値は byte 数
+		size = PImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
+		if (size <= 0) {
+			lpstr = NULL;		// エラー
+		} 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;	// ターミネートする
+				}
+			}
 		}
-		else {
-			GlobalFree(hstr);
-			hstr = NULL;
-		}
+
+		(*PImmReleaseContext)(hWnd, hIMC);
+
+	} else {
+		lpstr = NULL;
 	}
 
-skip:
-	(*PImmReleaseContext)(HVTWin, hIMC);
-	return hstr;
+	return lpstr;
 }
 
 BOOL GetIMEOpenStatus()

Modified: branches/cmake/teraterm/teraterm/ttime.h
===================================================================
--- branches/cmake/teraterm/teraterm/ttime.h	2019-03-10 14:32:33 UTC (rev 7469)
+++ branches/cmake/teraterm/teraterm/ttime.h	2019-03-10 14:32:45 UTC (rev 7470)
@@ -38,12 +38,11 @@
 void FreeIME();
 BOOL CanUseIME();
 void SetConversionWindow(HWND HWin, int X, int Y);
-void SetConversionLogFont(PLOGFONTA lf);
+void SetConversionLogFont(HWND HWin, PLOGFONTA lf);
 BOOL GetIMEOpenStatus(void);
 void SetIMEOpenStatus(BOOL stat);
+const wchar_t *GetConvString(HWND hWnd, UINT wParam, LPARAM lParam, size_t *len);
 
-HGLOBAL GetConvString(UINT wParam, LPARAM lParam);
-
 #ifndef WM_IME_COMPOSITION
 #define WM_IME_COMPOSITION              0x010F
 #endif


Ttssh2-commit メーリングリストの案内
Back to archive index