xref: /reactos/dll/win32/imm32/guideline.c (revision c2a94365)
1b4557a60SKatayama Hirofumi MZ /*
2b4557a60SKatayama Hirofumi MZ  * PROJECT:     ReactOS IMM32
3b4557a60SKatayama Hirofumi MZ  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4b4557a60SKatayama Hirofumi MZ  * PURPOSE:     Implementing IMM32 guidelines
5b4557a60SKatayama Hirofumi MZ  * COPYRIGHT:   Copyright 2020-2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6b4557a60SKatayama Hirofumi MZ  */
7b4557a60SKatayama Hirofumi MZ 
8b4557a60SKatayama Hirofumi MZ #include "precomp.h"
9b4557a60SKatayama Hirofumi MZ 
10b4557a60SKatayama Hirofumi MZ WINE_DEFAULT_DEBUG_CHANNEL(imm);
11b4557a60SKatayama Hirofumi MZ 
1289846a29SKatayama Hirofumi MZ // Win: ImmGetGuideLineWorker
13b4557a60SKatayama Hirofumi MZ DWORD APIENTRY
ImmGetGuideLineAW(HIMC hIMC,DWORD dwIndex,LPVOID lpBuf,DWORD dwBufLen,BOOL bAnsi)14b4557a60SKatayama Hirofumi MZ ImmGetGuideLineAW(HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen, BOOL bAnsi)
15b4557a60SKatayama Hirofumi MZ {
16b4557a60SKatayama Hirofumi MZ     PCLIENTIMC pClientImc;
17b4557a60SKatayama Hirofumi MZ     LPINPUTCONTEXT pIC;
18b4557a60SKatayama Hirofumi MZ     LPGUIDELINE pGuideLine;
19b4557a60SKatayama Hirofumi MZ     DWORD cb, ret = 0;
20b4557a60SKatayama Hirofumi MZ     LPVOID pvStr, pvPrivate;
21b4557a60SKatayama Hirofumi MZ     BOOL bUsedDefault;
2265858036SKatayama Hirofumi MZ     UINT uCodePage;
23b4557a60SKatayama Hirofumi MZ 
24b4557a60SKatayama Hirofumi MZ     pClientImc = ImmLockClientImc(hIMC);
25*c2a94365SKatayama Hirofumi MZ     if (IS_NULL_UNEXPECTEDLY(pClientImc))
26b4557a60SKatayama Hirofumi MZ         return 0;
27b4557a60SKatayama Hirofumi MZ 
2865858036SKatayama Hirofumi MZ     uCodePage = pClientImc->uCodePage;
2965858036SKatayama Hirofumi MZ 
30b4557a60SKatayama Hirofumi MZ     pIC = ImmLockIMC(hIMC);
31*c2a94365SKatayama Hirofumi MZ     if (IS_NULL_UNEXPECTEDLY(pIC))
32b4557a60SKatayama Hirofumi MZ     {
33b4557a60SKatayama Hirofumi MZ         ImmUnlockClientImc(pClientImc);
34b4557a60SKatayama Hirofumi MZ         return 0;
35b4557a60SKatayama Hirofumi MZ     }
36b4557a60SKatayama Hirofumi MZ 
37b4557a60SKatayama Hirofumi MZ     pGuideLine = ImmLockIMCC(pIC->hGuideLine);
38*c2a94365SKatayama Hirofumi MZ     if (IS_NULL_UNEXPECTEDLY(pGuideLine))
39b4557a60SKatayama Hirofumi MZ     {
40b4557a60SKatayama Hirofumi MZ         ImmUnlockIMC(hIMC);
41b4557a60SKatayama Hirofumi MZ         ImmUnlockClientImc(pClientImc);
42b4557a60SKatayama Hirofumi MZ         return 0;
43b4557a60SKatayama Hirofumi MZ     }
44b4557a60SKatayama Hirofumi MZ 
45b4557a60SKatayama Hirofumi MZ     if (dwIndex == GGL_LEVEL)
46b4557a60SKatayama Hirofumi MZ     {
47b4557a60SKatayama Hirofumi MZ         ret = pGuideLine->dwLevel;
48b4557a60SKatayama Hirofumi MZ         goto Quit;
49b4557a60SKatayama Hirofumi MZ     }
50b4557a60SKatayama Hirofumi MZ 
51b4557a60SKatayama Hirofumi MZ     if (dwIndex == GGL_INDEX)
52b4557a60SKatayama Hirofumi MZ     {
53b4557a60SKatayama Hirofumi MZ         ret = pGuideLine->dwIndex;
54b4557a60SKatayama Hirofumi MZ         goto Quit;
55b4557a60SKatayama Hirofumi MZ     }
56b4557a60SKatayama Hirofumi MZ 
57b4557a60SKatayama Hirofumi MZ     if (dwIndex == GGL_STRING)
58b4557a60SKatayama Hirofumi MZ     {
59b4557a60SKatayama Hirofumi MZ         pvStr = (LPBYTE)pGuideLine + pGuideLine->dwStrOffset;
60b4557a60SKatayama Hirofumi MZ 
61b4557a60SKatayama Hirofumi MZ         /* get size */
62b4557a60SKatayama Hirofumi MZ         if (bAnsi)
63b4557a60SKatayama Hirofumi MZ         {
64b4557a60SKatayama Hirofumi MZ             if (pClientImc->dwFlags & CLIENTIMC_WIDE)
65b4557a60SKatayama Hirofumi MZ             {
6665858036SKatayama Hirofumi MZ                 cb = WideCharToMultiByte(uCodePage, 0, pvStr, pGuideLine->dwStrLen,
67b4557a60SKatayama Hirofumi MZ                                          NULL, 0, NULL, &bUsedDefault);
68b4557a60SKatayama Hirofumi MZ             }
69b4557a60SKatayama Hirofumi MZ             else
70b4557a60SKatayama Hirofumi MZ             {
71b4557a60SKatayama Hirofumi MZ                 cb = pGuideLine->dwStrLen * sizeof(CHAR);
72b4557a60SKatayama Hirofumi MZ             }
73b4557a60SKatayama Hirofumi MZ         }
74b4557a60SKatayama Hirofumi MZ         else
75b4557a60SKatayama Hirofumi MZ         {
76b4557a60SKatayama Hirofumi MZ             if (pClientImc->dwFlags & CLIENTIMC_WIDE)
77b4557a60SKatayama Hirofumi MZ             {
78b4557a60SKatayama Hirofumi MZ                 cb = pGuideLine->dwStrLen * sizeof(WCHAR);
79b4557a60SKatayama Hirofumi MZ             }
80b4557a60SKatayama Hirofumi MZ             else
81b4557a60SKatayama Hirofumi MZ             {
8265858036SKatayama Hirofumi MZ                 cb = MultiByteToWideChar(uCodePage, MB_PRECOMPOSED, pvStr, pGuideLine->dwStrLen,
83b4557a60SKatayama Hirofumi MZ                                          NULL, 0) * sizeof(WCHAR);
84b4557a60SKatayama Hirofumi MZ             }
85b4557a60SKatayama Hirofumi MZ         }
86b4557a60SKatayama Hirofumi MZ 
87b4557a60SKatayama Hirofumi MZ         if (dwBufLen == 0 || cb == 0 || lpBuf == NULL || dwBufLen < cb)
88b4557a60SKatayama Hirofumi MZ         {
89b4557a60SKatayama Hirofumi MZ             ret = cb;
90b4557a60SKatayama Hirofumi MZ             goto Quit;
91b4557a60SKatayama Hirofumi MZ         }
92b4557a60SKatayama Hirofumi MZ 
93b4557a60SKatayama Hirofumi MZ         /* store to buffer */
94b4557a60SKatayama Hirofumi MZ         if (bAnsi)
95b4557a60SKatayama Hirofumi MZ         {
96b4557a60SKatayama Hirofumi MZ             if (pClientImc->dwFlags & CLIENTIMC_WIDE)
97b4557a60SKatayama Hirofumi MZ             {
9865858036SKatayama Hirofumi MZ                 ret = WideCharToMultiByte(uCodePage, 0, pvStr, pGuideLine->dwStrLen,
99b4557a60SKatayama Hirofumi MZ                                           lpBuf, dwBufLen, NULL, &bUsedDefault);
100b4557a60SKatayama Hirofumi MZ                 goto Quit;
101b4557a60SKatayama Hirofumi MZ             }
102b4557a60SKatayama Hirofumi MZ         }
103b4557a60SKatayama Hirofumi MZ         else
104b4557a60SKatayama Hirofumi MZ         {
105b4557a60SKatayama Hirofumi MZ             if (!(pClientImc->dwFlags & CLIENTIMC_WIDE))
106b4557a60SKatayama Hirofumi MZ             {
10765858036SKatayama Hirofumi MZ                 ret = MultiByteToWideChar(uCodePage, MB_PRECOMPOSED, pvStr, pGuideLine->dwStrLen,
108b4557a60SKatayama Hirofumi MZ                                           lpBuf, dwBufLen) * sizeof(WCHAR);
109b4557a60SKatayama Hirofumi MZ                 goto Quit;
110b4557a60SKatayama Hirofumi MZ             }
111b4557a60SKatayama Hirofumi MZ         }
112b4557a60SKatayama Hirofumi MZ 
113b4557a60SKatayama Hirofumi MZ         RtlCopyMemory(lpBuf, pvStr, cb);
114b4557a60SKatayama Hirofumi MZ         ret = cb;
115b4557a60SKatayama Hirofumi MZ         goto Quit;
116b4557a60SKatayama Hirofumi MZ     }
117b4557a60SKatayama Hirofumi MZ 
118b4557a60SKatayama Hirofumi MZ     if (dwIndex == GGL_PRIVATE)
119b4557a60SKatayama Hirofumi MZ     {
120b4557a60SKatayama Hirofumi MZ         pvPrivate = (LPBYTE)pGuideLine + pGuideLine->dwPrivateOffset;
121b4557a60SKatayama Hirofumi MZ 
122b4557a60SKatayama Hirofumi MZ         /* get size */
123b4557a60SKatayama Hirofumi MZ         if (bAnsi)
124b4557a60SKatayama Hirofumi MZ         {
125b4557a60SKatayama Hirofumi MZ             if ((pClientImc->dwFlags & CLIENTIMC_WIDE) &&
126b4557a60SKatayama Hirofumi MZ                 pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
127b4557a60SKatayama Hirofumi MZ             {
12865858036SKatayama Hirofumi MZ                 cb = CandidateListWideToAnsi(pvPrivate, NULL, 0, uCodePage);
129b4557a60SKatayama Hirofumi MZ             }
130b4557a60SKatayama Hirofumi MZ             else
131b4557a60SKatayama Hirofumi MZ             {
132b4557a60SKatayama Hirofumi MZ                 cb = pGuideLine->dwPrivateSize;
133b4557a60SKatayama Hirofumi MZ             }
134b4557a60SKatayama Hirofumi MZ         }
135b4557a60SKatayama Hirofumi MZ         else
136b4557a60SKatayama Hirofumi MZ         {
137b4557a60SKatayama Hirofumi MZ             if (!(pClientImc->dwFlags & CLIENTIMC_WIDE) &&
138b4557a60SKatayama Hirofumi MZ                 pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
139b4557a60SKatayama Hirofumi MZ             {
14065858036SKatayama Hirofumi MZ                 cb = CandidateListAnsiToWide(pvPrivate, NULL, 0, uCodePage);
141b4557a60SKatayama Hirofumi MZ             }
142b4557a60SKatayama Hirofumi MZ             else
143b4557a60SKatayama Hirofumi MZ             {
144b4557a60SKatayama Hirofumi MZ                 cb = pGuideLine->dwPrivateSize;
145b4557a60SKatayama Hirofumi MZ             }
146b4557a60SKatayama Hirofumi MZ         }
147b4557a60SKatayama Hirofumi MZ 
148b4557a60SKatayama Hirofumi MZ         if (dwBufLen == 0 || cb == 0 || lpBuf == NULL || dwBufLen < cb)
149b4557a60SKatayama Hirofumi MZ         {
150b4557a60SKatayama Hirofumi MZ             ret = cb;
151b4557a60SKatayama Hirofumi MZ             goto Quit;
152b4557a60SKatayama Hirofumi MZ         }
153b4557a60SKatayama Hirofumi MZ 
154b4557a60SKatayama Hirofumi MZ         /* store to buffer */
155b4557a60SKatayama Hirofumi MZ         if (bAnsi)
156b4557a60SKatayama Hirofumi MZ         {
157b4557a60SKatayama Hirofumi MZ             if ((pClientImc->dwFlags & CLIENTIMC_WIDE) &&
158b4557a60SKatayama Hirofumi MZ                 pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
159b4557a60SKatayama Hirofumi MZ             {
16065858036SKatayama Hirofumi MZ                 ret = CandidateListWideToAnsi(pvPrivate, lpBuf, cb, uCodePage);
161b4557a60SKatayama Hirofumi MZ                 goto Quit;
162b4557a60SKatayama Hirofumi MZ             }
163b4557a60SKatayama Hirofumi MZ         }
164b4557a60SKatayama Hirofumi MZ         else
165b4557a60SKatayama Hirofumi MZ         {
166b4557a60SKatayama Hirofumi MZ             if (!(pClientImc->dwFlags & CLIENTIMC_WIDE) &&
167b4557a60SKatayama Hirofumi MZ                 pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
168b4557a60SKatayama Hirofumi MZ             {
16965858036SKatayama Hirofumi MZ                 ret = CandidateListAnsiToWide(pvPrivate, lpBuf, cb, uCodePage);
170b4557a60SKatayama Hirofumi MZ                 goto Quit;
171b4557a60SKatayama Hirofumi MZ             }
172b4557a60SKatayama Hirofumi MZ         }
173b4557a60SKatayama Hirofumi MZ 
174b4557a60SKatayama Hirofumi MZ         RtlCopyMemory(lpBuf, pvPrivate, cb);
175b4557a60SKatayama Hirofumi MZ         ret = cb;
176b4557a60SKatayama Hirofumi MZ         goto Quit;
177b4557a60SKatayama Hirofumi MZ     }
178b4557a60SKatayama Hirofumi MZ 
179b4557a60SKatayama Hirofumi MZ Quit:
180b4557a60SKatayama Hirofumi MZ     ImmUnlockIMCC(pIC->hGuideLine);
181b4557a60SKatayama Hirofumi MZ     ImmUnlockIMC(hIMC);
182b4557a60SKatayama Hirofumi MZ     ImmUnlockClientImc(pClientImc);
18365858036SKatayama Hirofumi MZ     TRACE("ret: 0x%X\n", ret);
184b4557a60SKatayama Hirofumi MZ     return ret;
185b4557a60SKatayama Hirofumi MZ }
186b4557a60SKatayama Hirofumi MZ 
187b4557a60SKatayama Hirofumi MZ /***********************************************************************
188b4557a60SKatayama Hirofumi MZ  *		ImmGetGuideLineA (IMM32.@)
189b4557a60SKatayama Hirofumi MZ  */
ImmGetGuideLineA(HIMC hIMC,DWORD dwIndex,LPSTR lpBuf,DWORD dwBufLen)190b4557a60SKatayama Hirofumi MZ DWORD WINAPI ImmGetGuideLineA(HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
191b4557a60SKatayama Hirofumi MZ {
192b4557a60SKatayama Hirofumi MZ     TRACE("(%p, %lu, %p, %lu)\n", hIMC, dwIndex, lpBuf, dwBufLen);
193b4557a60SKatayama Hirofumi MZ     return ImmGetGuideLineAW(hIMC, dwIndex, lpBuf, dwBufLen, TRUE);
194b4557a60SKatayama Hirofumi MZ }
195b4557a60SKatayama Hirofumi MZ 
196b4557a60SKatayama Hirofumi MZ /***********************************************************************
197b4557a60SKatayama Hirofumi MZ  *		ImmGetGuideLineW (IMM32.@)
198b4557a60SKatayama Hirofumi MZ  */
ImmGetGuideLineW(HIMC hIMC,DWORD dwIndex,LPWSTR lpBuf,DWORD dwBufLen)199b4557a60SKatayama Hirofumi MZ DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
200b4557a60SKatayama Hirofumi MZ {
201b4557a60SKatayama Hirofumi MZ     TRACE("(%p, %lu, %p, %lu)\n", hIMC, dwIndex, lpBuf, dwBufLen);
202b4557a60SKatayama Hirofumi MZ     return ImmGetGuideLineAW(hIMC, dwIndex, lpBuf, dwBufLen, FALSE);
203b4557a60SKatayama Hirofumi MZ }
204