ReactOS  0.4.15-dev-5487-ge7bbbf0
win3.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS IMM32
3  * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE: Implementing IMM32 Win3.x compatibility
5  * COPYRIGHT: Copyright 2020-2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #include "precomp.h"
9 
11 
12 #ifdef IMM_WIN3_SUPPORT /* 3.x support */
13 
14 /* Win: JTransCompositionA */
16 Imm32JTransCompA(LPINPUTCONTEXTDX pIC, LPCOMPOSITIONSTRING pCS,
17  const TRANSMSG *pSrc, LPTRANSMSG pDest)
18 {
19  FIXME("\n");
20  *pDest = *pSrc;
21  return 1;
22 }
23 
24 /* Win: JTransCompositionW */
26 Imm32JTransCompW(LPINPUTCONTEXTDX pIC, LPCOMPOSITIONSTRING pCS,
27  const TRANSMSG *pSrc, LPTRANSMSG pDest)
28 {
29  FIXME("\n");
30  *pDest = *pSrc;
31  return 1;
32 }
33 
34 typedef LRESULT (WINAPI *FN_SendMessage)(HWND, UINT, WPARAM, LPARAM);
35 
37 WINNLSTranslateMessageJ(DWORD dwCount, LPTRANSMSG pTrans, LPINPUTCONTEXTDX pIC,
38  LPCOMPOSITIONSTRING pCS, BOOL bAnsi)
39 {
40  DWORD ret = 0;
41  HWND hWnd, hwndDefIME;
42  LPTRANSMSG pTempList, pEntry, pNext;
43  DWORD dwIndex, iCandForm, dwNumber, cbTempList;
44  HGLOBAL hGlobal;
45  CANDIDATEFORM CandForm;
46  FN_SendMessage pSendMessage;
47 
48  hWnd = pIC->hWnd;
49  hwndDefIME = ImmGetDefaultIMEWnd(hWnd);
50  pSendMessage = (IsWindowUnicode(hWnd) ? SendMessageW : SendMessageA);
51 
52  // clone the message list
53  cbTempList = (dwCount + 1) * sizeof(TRANSMSG);
54  pTempList = ImmLocalAlloc(HEAP_ZERO_MEMORY, cbTempList);
55  if (IS_NULL_UNEXPECTEDLY(pTempList))
56  return 0;
57  RtlCopyMemory(pTempList, pTrans, dwCount * sizeof(TRANSMSG));
58 
59  if (pIC->dwUIFlags & 0x2)
60  {
61  // find WM_IME_ENDCOMPOSITION
62  pEntry = pTempList;
63  for (dwIndex = 0; dwIndex < dwCount; ++dwIndex, ++pEntry)
64  {
65  if (pEntry->message == WM_IME_ENDCOMPOSITION)
66  break;
67  }
68 
69  if (pEntry->message == WM_IME_ENDCOMPOSITION) // if found
70  {
71  // move WM_IME_ENDCOMPOSITION to the end of the list
72  for (pNext = pEntry + 1; pNext->message != 0; ++pEntry, ++pNext)
73  *pEntry = *pNext;
74 
75  pEntry->message = WM_IME_ENDCOMPOSITION;
76  pEntry->wParam = 0;
77  pEntry->lParam = 0;
78  }
79  }
80 
81  for (pEntry = pTempList; pEntry->message != 0; ++pEntry)
82  {
83  switch (pEntry->message)
84  {
85  case WM_IME_STARTCOMPOSITION:
86  if (!(pIC->dwUIFlags & 0x2))
87  {
88  // send IR_OPENCONVERT
89  if (pIC->cfCompForm.dwStyle != CFS_DEFAULT)
90  pSendMessage(hWnd, WM_IME_REPORT, IR_OPENCONVERT, 0);
91 
92  goto DoDefault;
93  }
94  break;
95 
96  case WM_IME_ENDCOMPOSITION:
97  if (pIC->dwUIFlags & 0x2)
98  {
99  // send IR_UNDETERMINE
100  hGlobal = GlobalAlloc(GHND | GMEM_SHARE, sizeof(UNDETERMINESTRUCT));
101  if (hGlobal)
102  {
103  pSendMessage(hWnd, WM_IME_REPORT, IR_UNDETERMINE, (LPARAM)hGlobal);
104  GlobalFree(hGlobal);
105  }
106  }
107  else
108  {
109  // send IR_CLOSECONVERT
110  if (pIC->cfCompForm.dwStyle != CFS_DEFAULT)
111  pSendMessage(hWnd, WM_IME_REPORT, IR_CLOSECONVERT, 0);
112 
113  goto DoDefault;
114  }
115  break;
116 
117  case WM_IME_COMPOSITION:
118  if (bAnsi)
119  dwNumber = Imm32JTransCompA(pIC, pCS, pEntry, pTrans);
120  else
121  dwNumber = Imm32JTransCompW(pIC, pCS, pEntry, pTrans);
122 
123  ret += dwNumber;
124  pTrans += dwNumber;
125 
126  // send IR_CHANGECONVERT
127  if (!(pIC->dwUIFlags & 0x2))
128  {
129  if (pIC->cfCompForm.dwStyle != CFS_DEFAULT)
130  pSendMessage(hWnd, WM_IME_REPORT, IR_CHANGECONVERT, 0);
131  }
132  break;
133 
134  case WM_IME_NOTIFY:
135  if (pEntry->wParam == IMN_OPENCANDIDATE)
136  {
137  if (IsWindow(hWnd) && (pIC->dwUIFlags & 0x2))
138  {
139  // send IMC_SETCANDIDATEPOS
140  for (iCandForm = 0; iCandForm < MAX_CANDIDATEFORM; ++iCandForm)
141  {
142  if (!(pEntry->lParam & (1 << iCandForm)))
143  continue;
144 
145  CandForm.dwIndex = iCandForm;
146  CandForm.dwStyle = CFS_EXCLUDE;
147  CandForm.ptCurrentPos = pIC->cfCompForm.ptCurrentPos;
148  CandForm.rcArea = pIC->cfCompForm.rcArea;
149  pSendMessage(hwndDefIME, WM_IME_CONTROL, IMC_SETCANDIDATEPOS,
150  (LPARAM)&CandForm);
151  }
152  }
153  }
154 
155  if (!(pIC->dwUIFlags & 0x2))
156  goto DoDefault;
157 
158  // send a WM_IME_NOTIFY notification to the default ime window
159  pSendMessage(hwndDefIME, pEntry->message, pEntry->wParam, pEntry->lParam);
160  break;
161 
162 DoDefault:
163  default:
164  // default processing
165  *pTrans++ = *pEntry;
166  ++ret;
167  break;
168  }
169  }
170 
171  ImmLocalFree(pTempList);
172  return ret;
173 }
174 
176 WINNLSTranslateMessageK(DWORD dwCount, LPTRANSMSG pEntries, LPINPUTCONTEXTDX pIC,
177  LPCOMPOSITIONSTRING pCS, BOOL bAnsi)
178 {
179  FIXME("(0x%X, %p, %p, %p, %d)\n", dwCount, pEntries, pIC, pCS, bAnsi);
180  return dwCount;
181 }
182 
184 WINNLSTranslateMessage(DWORD dwCount, LPTRANSMSG pEntries, HIMC hIMC, BOOL bAnsi, WORD wLang)
185 {
186  BOOL ret = FALSE;
187  LPINPUTCONTEXTDX pIC;
189 
190  pIC = (LPINPUTCONTEXTDX)ImmLockIMC(hIMC);
191  if (IS_NULL_UNEXPECTEDLY(pIC))
192  return 0;
193 
194  pCS = ImmLockIMCC(pIC->hCompStr);
195  if (IS_NULL_UNEXPECTEDLY(pCS))
196  {
197  ImmUnlockIMC(hIMC);
198  return 0;
199  }
200 
201  if (wLang == LANG_JAPANESE)
202  ret = WINNLSTranslateMessageJ(dwCount, pEntries, pIC, pCS, bAnsi);
203  else if (wLang == LANG_KOREAN)
204  ret = WINNLSTranslateMessageK(dwCount, pEntries, pIC, pCS, bAnsi);
205 
206  ImmUnlockIMCC(pIC->hCompStr);
207  ImmUnlockIMC(hIMC);
208  return ret;
209 }
210 
211 #endif /* IMM_WIN3_SUPPORT */
212 
213 /***********************************************************************
214  * ImmSendIMEMessageExA(IMM32.@)
215  */
217 {
218  FIXME("(%p, %p)\n", hWnd, lParam);
219  return 0;
220 }
221 
222 /***********************************************************************
223  * ImmSendIMEMessageExW(IMM32.@)
224  */
226 {
227  FIXME("(%p, %p)\n", hWnd, lParam);
228  return 0;
229 }
#define WM_IME_NOTIFY
Definition: winuser.h:1820
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
DWORD dwUIFlags
Definition: immdev.h:132
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define IMC_SETCANDIDATEPOS
Definition: imm.h:279
#define IR_CLOSECONVERT
Definition: immdev.h:171
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC)
Definition: imm.c:1070
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:415
#define IR_CHANGECONVERT
Definition: immdev.h:170
#define CFS_DEFAULT
Definition: imm.h:470
HWND hWnd
Definition: settings.c:17
LPVOID WINAPI ImmLockIMCC(HIMCC imcc)
Definition: utils.c:1198
HANDLE HWND
Definition: compat.h:19
DWORD dwStyle
Definition: dimm.idl:80
#define IMN_OPENCANDIDATE
Definition: imm.h:525
UINT_PTR WPARAM
Definition: windef.h:207
WORD WINAPI ImmSendIMEMessageExA(HWND hWnd, LPARAM lParam)
Definition: win3.c:216
#define GMEM_SHARE
Definition: winbase.h:305
UINT message
Definition: imm32.c:65
#define IR_OPENCONVERT
Definition: immdev.h:169
#define GHND
Definition: winbase.h:297
#define LANG_JAPANESE
Definition: nls.h:76
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IR_UNDETERMINE
Definition: immdev.h:176
#define FIXME(fmt,...)
Definition: debug.h:111
WINE_DEFAULT_DEBUG_CHANNEL(imm)
#define WM_IME_REPORT
Definition: immdev.h:163
LONG_PTR LPARAM
Definition: windef.h:208
DWORD HIMC
Definition: dimm.idl:75
BOOL WINAPI IsWindowUnicode(_In_ HWND)
#define MAX_CANDIDATEFORM
Definition: precomp.h:53
#define WM_IME_CONTROL
Definition: winuser.h:1821
#define WINAPI
Definition: msvc.h:6
struct INPUTCONTEXTDX * LPINPUTCONTEXTDX
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define IS_NULL_UNEXPECTEDLY(p)
Definition: precomp.h:120
WORD WINAPI ImmSendIMEMessageExW(HWND hWnd, LPARAM lParam)
Definition: win3.c:225
#define ImmLocalFree(lpData)
Definition: precomp.h:89
BOOL WINAPI ImmUnlockIMCC(HIMCC imcc)
Definition: utils.c:1208
int ret
POINT ptCurrentPos
Definition: dimm.idl:81
#define LRESULT
Definition: ole.h:14
#define CFS_EXCLUDE
Definition: imm.h:475
RECT rcArea
Definition: dimm.idl:82
HWND WINAPI ImmGetDefaultIMEWnd(HWND hWnd)
Definition: ime.c:890
DWORD dwIndex
Definition: dimm.idl:79
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
unsigned int UINT
Definition: ndis.h:50
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define LANG_KOREAN
Definition: nls.h:84
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
BOOL WINAPI ImmUnlockIMC(HIMC hIMC)
Definition: imm.c:1079
LPARAM lParam
Definition: combotst.c:139
#define APIENTRY
Definition: api.h:79