Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Diff of /trunk/teraterm/teraterm/ttime.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3226 by maya, Tue Mar 24 09:37:20 2009 UTC revision 3227 by maya, Tue Mar 24 15:10:33 2009 UTC
# Line 1  Line 1 
1  /* Tera Term */  /* Tera Term */
2  /* TERATERM.EXE, IME interface */  /* TERATERM.EXE, IME interface */
3    
4  #include "teraterm.h"  #include "teraterm.h"
5  #include "tttypes.h"  #include "tttypes.h"
6  #include <stdlib.h>  #include <stdlib.h>
7  #include <string.h>  #include <string.h>
8  #include <imm.h>  #include <imm.h>
9    
10  #include "ttwinman.h"  #include "ttwinman.h"
11  #include "ttcommon.h"  #include "ttcommon.h"
12    
13  #include "ttime.h"  #include "ttime.h"
14  #include "ttlib.h"  #include "ttlib.h"
15    
16  #ifndef _IMM_  #ifndef _IMM_
17    #define _IMM_    #define _IMM_
18    
19    typedef DWORD HIMC;    typedef DWORD HIMC;
20    
21    typedef struct tagCOMPOSITIONFORM {    typedef struct tagCOMPOSITIONFORM {
22      DWORD dwStyle;      DWORD dwStyle;
23      POINT ptCurrentPos;      POINT ptCurrentPos;
24      RECT  rcArea;      RECT  rcArea;
25    } COMPOSITIONFORM, *PCOMPOSITIONFORM, NEAR *NPCOMPOSITIONFORM, FAR *LPCOMPOSITIONFORM;    } COMPOSITIONFORM, *PCOMPOSITIONFORM, NEAR *NPCOMPOSITIONFORM, FAR *LPCOMPOSITIONFORM;
26  #endif //_IMM_  #endif //_IMM_
27    
28  #define GCS_RESULTSTR 0x0800  #define GCS_RESULTSTR 0x0800
29    
30  typedef LONG (WINAPI *TImmGetCompositionString)  typedef LONG (WINAPI *TImmGetCompositionString)
31          (HIMC, DWORD, LPVOID, DWORD);          (HIMC, DWORD, LPVOID, DWORD);
32  typedef HIMC (WINAPI *TImmGetContext)(HWND);  typedef HIMC (WINAPI *TImmGetContext)(HWND);
33  typedef BOOL (WINAPI *TImmReleaseContext)(HWND, HIMC);  typedef BOOL (WINAPI *TImmReleaseContext)(HWND, HIMC);
34  typedef BOOL (WINAPI *TImmSetCompositionFont)(HIMC, LPLOGFONTA);  typedef BOOL (WINAPI *TImmSetCompositionFont)(HIMC, LPLOGFONTA);
35  typedef BOOL (WINAPI *TImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM);  typedef BOOL (WINAPI *TImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM);
36    
37  static TImmGetCompositionString PImmGetCompositionString;  static TImmGetCompositionString PImmGetCompositionString;
38  static TImmGetContext PImmGetContext;  static TImmGetContext PImmGetContext;
39  static TImmReleaseContext PImmReleaseContext;  static TImmReleaseContext PImmReleaseContext;
40  static TImmSetCompositionFont PImmSetCompositionFont;  static TImmSetCompositionFont PImmSetCompositionFont;
41  static TImmSetCompositionWindow PImmSetCompositionWindow;  static TImmSetCompositionWindow PImmSetCompositionWindow;
42    
43    
44  static HANDLE HIMEDLL = NULL;  static HANDLE HIMEDLL = NULL;
45  static LOGFONT lfIME;  static LOGFONT lfIME;
46    
47    
48  BOOL LoadIME()  BOOL LoadIME()
49  {  {
50    BOOL Err;    BOOL Err;
51  #if 0  #if 0
52    PTTSet tempts;    PTTSet tempts;
53  #endif  #endif
54    char uimsg[MAX_UIMSG];    char uimsg[MAX_UIMSG];
55    
56    if (HIMEDLL != NULL) return TRUE;    if (HIMEDLL != NULL) return TRUE;
57    HIMEDLL = LoadLibrary("IMM32.DLL");    HIMEDLL = LoadLibrary("IMM32.DLL");
58    if (HIMEDLL == NULL)    if (HIMEDLL == NULL)
59    {    {
60      get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg),  "Tera Term: Error", ts.UILanguageFile);      get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg),  "Tera Term: Error", ts.UILanguageFile);
61      get_lang_msg("MSG_USE_IME_ERROR", ts.UIMsg, sizeof(ts.UIMsg), "Can't use IME", ts.UILanguageFile);      get_lang_msg("MSG_USE_IME_ERROR", ts.UIMsg, sizeof(ts.UIMsg), "Can't use IME", ts.UILanguageFile);
62      MessageBox(0,ts.UIMsg,uimsg,MB_ICONEXCLAMATION);      MessageBox(0,ts.UIMsg,uimsg,MB_ICONEXCLAMATION);
63      WritePrivateProfileString("Tera Term","IME","off",ts.SetupFName);      WritePrivateProfileString("Tera Term","IME","off",ts.SetupFName);
64      ts.UseIME = 0;      ts.UseIME = 0;
65  #if 0  #if 0
66      tempts = (PTTSet)malloc(sizeof(TTTSet));      tempts = (PTTSet)malloc(sizeof(TTTSet));
67      if (tempts!=NULL)      if (tempts!=NULL)
68      {      {
69        GetDefaultSet(tempts);        GetDefaultSet(tempts);
70        tempts->UseIME = 0;        tempts->UseIME = 0;
71        ChangeDefaultSet(tempts,NULL);        ChangeDefaultSet(tempts,NULL);
72        free(tempts);        free(tempts);
73      }      }
74  #endif  #endif
75      return FALSE;      return FALSE;
76    }    }
77    
78    Err = FALSE;    Err = FALSE;
79    
80    PImmGetCompositionString = (TImmGetCompositionString)GetProcAddress(    PImmGetCompositionString = (TImmGetCompositionString)GetProcAddress(
81      HIMEDLL, "ImmGetCompositionStringA");      HIMEDLL, "ImmGetCompositionStringA");
82    if (PImmGetCompositionString==NULL) Err = TRUE;    if (PImmGetCompositionString==NULL) Err = TRUE;
83    
84    PImmGetContext = (TImmGetContext)GetProcAddress(    PImmGetContext = (TImmGetContext)GetProcAddress(
85      HIMEDLL, "ImmGetContext");      HIMEDLL, "ImmGetContext");
86    if (PImmGetContext==NULL) Err = TRUE;    if (PImmGetContext==NULL) Err = TRUE;
87    
88    PImmReleaseContext = (TImmReleaseContext)GetProcAddress(    PImmReleaseContext = (TImmReleaseContext)GetProcAddress(
89      HIMEDLL, "ImmReleaseContext");      HIMEDLL, "ImmReleaseContext");
90    if (PImmReleaseContext==NULL) Err = TRUE;    if (PImmReleaseContext==NULL) Err = TRUE;
91    
92    PImmSetCompositionFont = (TImmSetCompositionFont)GetProcAddress(    PImmSetCompositionFont = (TImmSetCompositionFont)GetProcAddress(
93      HIMEDLL, "ImmSetCompositionFontA");      HIMEDLL, "ImmSetCompositionFontA");
94    if (PImmSetCompositionFont==NULL) Err = TRUE;    if (PImmSetCompositionFont==NULL) Err = TRUE;
95    
96    PImmSetCompositionWindow = (TImmSetCompositionWindow)GetProcAddress(    PImmSetCompositionWindow = (TImmSetCompositionWindow)GetProcAddress(
97      HIMEDLL, "ImmSetCompositionWindow");      HIMEDLL, "ImmSetCompositionWindow");
98    if (PImmSetCompositionWindow==NULL) Err = TRUE;    if (PImmSetCompositionWindow==NULL) Err = TRUE;
99    
100    if ( Err )    if ( Err )
101    {    {
102      FreeLibrary(HIMEDLL);      FreeLibrary(HIMEDLL);
103      HIMEDLL = NULL;      HIMEDLL = NULL;
104      return FALSE;      return FALSE;
105    }    }
106    else    else
107      return TRUE;      return TRUE;
108  }  }
109    
110  void FreeIME()  void FreeIME()
111  {  {
112    HANDLE HTemp;    HANDLE HTemp;
113    
114    if (HIMEDLL==NULL) return;    if (HIMEDLL==NULL) return;
115    HTemp = HIMEDLL;    HTemp = HIMEDLL;
116    HIMEDLL = NULL;    HIMEDLL = NULL;
117    
118    /* position of conv. window -> default */    /* position of conv. window -> default */
119    SetConversionWindow(HVTWin,-1,0);    SetConversionWindow(HVTWin,-1,0);
120    Sleep(1); // for safety    Sleep(1); // for safety
121    FreeLibrary(HTemp);    FreeLibrary(HTemp);
122  }  }
123    
124  BOOL CanUseIME()  BOOL CanUseIME()
125  {  {
126    return (HIMEDLL != NULL);    return (HIMEDLL != NULL);
127  }  }
128    
129  void SetConversionWindow(HWND HWin, int X, int Y)  void SetConversionWindow(HWND HWin, int X, int Y)
130  {  {
131    HIMC  hIMC;    HIMC  hIMC;
132    COMPOSITIONFORM cf;    COMPOSITIONFORM cf;
133    
134    if (HIMEDLL == NULL) return;    if (HIMEDLL == NULL) return;
135  // Adjust the position of conversion window  // Adjust the position of conversion window
136    hIMC = (*PImmGetContext)(HVTWin);    hIMC = (*PImmGetContext)(HVTWin);
137    if (X>=0)    if (X>=0)
138    {    {
139      cf.dwStyle = CFS_POINT;      cf.dwStyle = CFS_POINT;
140      cf.ptCurrentPos.x = X;      cf.ptCurrentPos.x = X;
141      cf.ptCurrentPos.y = Y;      cf.ptCurrentPos.y = Y;
142    }    }
143    else    else
144      cf.dwStyle = CFS_DEFAULT;      cf.dwStyle = CFS_DEFAULT;
145    (*PImmSetCompositionWindow)(hIMC,&cf);    (*PImmSetCompositionWindow)(hIMC,&cf);
146    
147    // Set font for the conversion window    // Set font for the conversion window
148    (*PImmSetCompositionFont)(hIMC,&lfIME);    (*PImmSetCompositionFont)(hIMC,&lfIME);
149    (*PImmReleaseContext)(HVTWin,hIMC);    (*PImmReleaseContext)(HVTWin,hIMC);
150  }  }
151    
152  void SetConversionLogFont(PLOGFONT lf)  void SetConversionLogFont(PLOGFONT lf)
153  {  {
154    memcpy(&lfIME,lf,sizeof(LOGFONT));    memcpy(&lfIME,lf,sizeof(LOGFONT));
155  }  }
156    
157  HGLOBAL GetConvString(UINT wParam, LPARAM lParam)  HGLOBAL GetConvString(UINT wParam, LPARAM lParam)
158  {  {
159          HIMC hIMC;          HIMC hIMC;
160          HGLOBAL hstr = NULL;          HGLOBAL hstr = NULL;
161          //LPSTR lpstr;          //LPSTR lpstr;
162          wchar_t *lpstr;          wchar_t *lpstr;
163          DWORD dwSize;          DWORD dwSize;
164    
165          if (HIMEDLL==NULL) return NULL;          if (HIMEDLL==NULL) return NULL;
166          hIMC = (*PImmGetContext)(HVTWin);          hIMC = (*PImmGetContext)(HVTWin);
167          if (hIMC==0) return NULL;          if (hIMC==0) return NULL;
168    
169          if ((lParam & GCS_RESULTSTR)==0)          if ((lParam & GCS_RESULTSTR)==0)
170                  goto skip;                  goto skip;
171    
172          // Get the size of the result string.          // Get the size of the result string.
173          //dwSize = (*PImmGetCompositionString)(hIMC, GCS_RESULTSTR, NULL, 0);          //dwSize = (*PImmGetCompositionString)(hIMC, GCS_RESULTSTR, NULL, 0);
174          dwSize = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);          dwSize = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
175          dwSize += sizeof(WCHAR);          dwSize += sizeof(WCHAR);
176          hstr = GlobalAlloc(GHND,dwSize);          hstr = GlobalAlloc(GHND,dwSize);
177          if (hstr != NULL)          if (hstr != NULL)
178          {          {
179  //              lpstr = (LPSTR)GlobalLock(hstr);  //              lpstr = (LPSTR)GlobalLock(hstr);
180                  lpstr = GlobalLock(hstr);                  lpstr = GlobalLock(hstr);
181                  if (lpstr != NULL)                  if (lpstr != NULL)
182                  {                  {
183  #if 0  #if 0
184                          // Get the result strings that is generated by IME into lpstr.                          // Get the result strings that is generated by IME into lpstr.
185                          (*PImmGetCompositionString)                          (*PImmGetCompositionString)
186                                  (hIMC, GCS_RESULTSTR, lpstr, dwSize);                                  (hIMC, GCS_RESULTSTR, lpstr, dwSize);
187  #else  #else
188                          ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpstr, dwSize);                          ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpstr, dwSize);
189  #endif  #endif
190                          GlobalUnlock(hstr);                          GlobalUnlock(hstr);
191                  }                  }
192                  else {                  else {
193                          GlobalFree(hstr);                          GlobalFree(hstr);
194                          hstr = NULL;                          hstr = NULL;
195                  }                  }
196          }          }
197    
198  skip:  skip:
199          (*PImmReleaseContext)(HVTWin, hIMC);          (*PImmReleaseContext)(HVTWin, hIMC);
200          return hstr;          return hstr;
201  }  }

Legend:
Removed from v.3226  
changed lines
  Added in v.3227

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26