作者: Koichi Yamamoto
日時: 2002/4/11(02:17)
こんにちは、山本です。

2002年4月5日午後10頃にSFのCVSから取ってきたTkの最新ソースに
適用できるパッチ「FANTASIA2(仮)」を発作的に作りました。
このパッチには以下の効能があります。

  - Win9xでIMEのインライン入力ができるようになります。
  - 文節変換したときでもIMEのcomposition windowの位置を移動します。
  - ATOK13でもちゃんとcomposition windowが見えるようになります。

フォント制御は後日追加するかもしれません。

-----------------------------------------------------------------------
diff -r -c -P ./tk8.4a5/win/tkWinX.c.orig ./tk8.4a5/win/tkWinX.c
*** ./tk8.4a5/win/tkWinX.c.orig	Fri Apr 05 17:40:36 2002
--- ./tk8.4a5/win/tkWinX.c	Thu Apr 11 01:45:30 2002
***************
*** 608,613 ****
--- 608,614 ----
  	    result = 1;
  	    break;
  
+ #if 0
          case WM_IME_STARTCOMPOSITION: {
  	    /*
  	     * Position the IME composition window according the known
***************
*** 628,633 ****
--- 629,635 ----
  	    }
  	    break;
  	}
+ #endif
  
          case WM_IME_COMPOSITION:
              result = 0;
***************
*** 1291,1296 ****
--- 1293,1299 ----
      char * buff;
      TkWindow *winPtr;
  
+ #if 0
      if (TkWinGetPlatformId() != VER_PLATFORM_WIN32_NT) {
          /*
           * The ImmGetCompositionStringW function works only on WinNT.
***************
*** 1298,1303 ****
--- 1301,1307 ----
  
          return 0;
      }
+ #endif
  
      if ((lParam & GCS_RESULTSTR) == 0) {
          /*
***************
*** 1309,1319 ****
--- 1313,1349 ----
  
      hIMC = ImmGetContext(hwnd);
      if (hIMC) {
+         /*
+          * Use ImmGetCompositionStringA function for Win9x.
+          */
+         if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
          n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
+         } else {
+         n = ImmGetCompositionStringA(hIMC, GCS_RESULTSTR, NULL, 0);
+         }
  
          if (n > 0) {
              buff = (char*)ckalloc(n);
+             /*
+              * Use ImmGetCompositionStringA function for Win9x.
+              */
+             if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
              n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
+             } else {
+             Tcl_DString utfString, unicodeString;
+             Tcl_Encoding unicodeEncoding = Tcl_GetEncoding(NULL, "unicode");
+             n = ImmGetCompositionStringA(hIMC, GCS_RESULTSTR, buff, n);
+             Tcl_DStringInit(&utfString);
+             Tcl_ExternalToUtfDString(keyInputEncoding, buff, n, &utfString);
+             Tcl_UtfToExternalDString(unicodeEncoding, 
+                     Tcl_DStringValue(&utfString), -1, &unicodeString);
+             ckfree(buff);
+             n = Tcl_DStringLength(&unicodeString);
+             buff = (char*)ckalloc(n);
+             memcpy(buff, Tcl_DStringValue(&unicodeString), n);
+             Tcl_DStringFree(&utfString);
+             Tcl_DStringFree(&unicodeString);
+             }
  
  	    /*
  	     * Set up the fields pertinent to key event.
***************
*** 1532,1537 ****
--- 1562,1568 ----
      static HWND caretHWND = NULL;
      Window win;
      HWND   hwnd;
+     HIMC   hIMC;
  
      /*
       * We adjust to the toplevel to get the coords right, as setting
***************
*** 1551,1556 ****
--- 1582,1606 ----
      win = Tk_WindowId(tkwin);
      if (win) {
  	hwnd = Tk_GetHWND(win);
+ 
+     /*
+      * The IME composition window should be updated 
+      * whenever the caret position is changed because 
+      * a clause of the composition string may be converted 
+      * to the final characters and the other clauses still 
+      * stay on the composition window.
+      */
+     hIMC = ImmGetContext(hwnd);
+     if (hIMC) {
+     COMPOSITIONFORM cform;
+     cform.dwStyle = CFS_POINT;
+     cform.ptCurrentPos.x = x;
+     cform.ptCurrentPos.y = y;
+     ImmSetCompositionWindow(hIMC, &cform);
+     ImmReleaseContext(hwnd, hIMC);
+     }
+ 
+ #if 0
  	if (hwnd != caretHWND) {
  	    DestroyCaret();
  	    if (CreateCaret(hwnd, NULL, 0, 0)) {
***************
*** 1562,1566 ****
--- 1612,1618 ----
  	    caretHWND = hwnd;
  	    SetCaretPos(x, y);
  	}
+ #endif
+ 
      }
  }
-----------------------------------------------------------------------





--
Koichi Yamamoto, 
http://www3.ocn.ne.jp/~yamako/