ReactOS  0.4.15-dev-4872-g8a3db97
guideline.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 guidelines
5  * COPYRIGHT: Copyright 2020-2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #include "precomp.h"
9 
11 
12 // Win: ImmGetGuideLineWorker
14 ImmGetGuideLineAW(HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen, BOOL bAnsi)
15 {
16  PCLIENTIMC pClientImc;
17  LPINPUTCONTEXT pIC;
18  LPGUIDELINE pGuideLine;
19  DWORD cb, ret = 0;
20  LPVOID pvStr, pvPrivate;
21  BOOL bUsedDefault;
22 
23  pClientImc = ImmLockClientImc(hIMC);
24  if (!pClientImc)
25  return 0;
26 
27  pIC = ImmLockIMC(hIMC);
28  if (!pIC)
29  {
30  ImmUnlockClientImc(pClientImc);
31  return 0;
32  }
33 
34  pGuideLine = ImmLockIMCC(pIC->hGuideLine);
35  if (!pGuideLine)
36  {
37  ImmUnlockIMC(hIMC);
38  ImmUnlockClientImc(pClientImc);
39  return 0;
40  }
41 
42  if (dwIndex == GGL_LEVEL)
43  {
44  ret = pGuideLine->dwLevel;
45  goto Quit;
46  }
47 
48  if (dwIndex == GGL_INDEX)
49  {
50  ret = pGuideLine->dwIndex;
51  goto Quit;
52  }
53 
54  if (dwIndex == GGL_STRING)
55  {
56  pvStr = (LPBYTE)pGuideLine + pGuideLine->dwStrOffset;
57 
58  /* get size */
59  if (bAnsi)
60  {
61  if (pClientImc->dwFlags & CLIENTIMC_WIDE)
62  {
63  cb = WideCharToMultiByte(CP_ACP, 0, pvStr, pGuideLine->dwStrLen,
64  NULL, 0, NULL, &bUsedDefault);
65  }
66  else
67  {
68  cb = pGuideLine->dwStrLen * sizeof(CHAR);
69  }
70  }
71  else
72  {
73  if (pClientImc->dwFlags & CLIENTIMC_WIDE)
74  {
75  cb = pGuideLine->dwStrLen * sizeof(WCHAR);
76  }
77  else
78  {
79  cb = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pvStr, pGuideLine->dwStrLen,
80  NULL, 0) * sizeof(WCHAR);
81  }
82  }
83 
84  if (dwBufLen == 0 || cb == 0 || lpBuf == NULL || dwBufLen < cb)
85  {
86  ret = cb;
87  goto Quit;
88  }
89 
90  /* store to buffer */
91  if (bAnsi)
92  {
93  if (pClientImc->dwFlags & CLIENTIMC_WIDE)
94  {
95  ret = WideCharToMultiByte(CP_ACP, 0, pvStr, pGuideLine->dwStrLen,
96  lpBuf, dwBufLen, NULL, &bUsedDefault);
97  goto Quit;
98  }
99  }
100  else
101  {
102  if (!(pClientImc->dwFlags & CLIENTIMC_WIDE))
103  {
104  ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pvStr, pGuideLine->dwStrLen,
105  lpBuf, dwBufLen) * sizeof(WCHAR);
106  goto Quit;
107  }
108  }
109 
110  RtlCopyMemory(lpBuf, pvStr, cb);
111  ret = cb;
112  goto Quit;
113  }
114 
115  if (dwIndex == GGL_PRIVATE)
116  {
117  pvPrivate = (LPBYTE)pGuideLine + pGuideLine->dwPrivateOffset;
118 
119  /* get size */
120  if (bAnsi)
121  {
122  if ((pClientImc->dwFlags & CLIENTIMC_WIDE) &&
123  pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
124  {
125  cb = CandidateListWideToAnsi(pvPrivate, NULL, 0, CP_ACP);
126  }
127  else
128  {
129  cb = pGuideLine->dwPrivateSize;
130  }
131  }
132  else
133  {
134  if (!(pClientImc->dwFlags & CLIENTIMC_WIDE) &&
135  pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
136  {
137  cb = CandidateListAnsiToWide(pvPrivate, NULL, 0, CP_ACP);
138  }
139  else
140  {
141  cb = pGuideLine->dwPrivateSize;
142  }
143  }
144 
145  if (dwBufLen == 0 || cb == 0 || lpBuf == NULL || dwBufLen < cb)
146  {
147  ret = cb;
148  goto Quit;
149  }
150 
151  /* store to buffer */
152  if (bAnsi)
153  {
154  if ((pClientImc->dwFlags & CLIENTIMC_WIDE) &&
155  pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
156  {
157  ret = CandidateListWideToAnsi(pvPrivate, lpBuf, cb, CP_ACP);
158  goto Quit;
159  }
160  }
161  else
162  {
163  if (!(pClientImc->dwFlags & CLIENTIMC_WIDE) &&
164  pGuideLine->dwIndex == GL_ID_REVERSECONVERSION)
165  {
166  ret = CandidateListAnsiToWide(pvPrivate, lpBuf, cb, CP_ACP);
167  goto Quit;
168  }
169  }
170 
171  RtlCopyMemory(lpBuf, pvPrivate, cb);
172  ret = cb;
173  goto Quit;
174  }
175 
176 Quit:
178  ImmUnlockIMC(hIMC);
179  ImmUnlockClientImc(pClientImc);
180  return ret;
181 }
182 
183 /***********************************************************************
184  * ImmGetGuideLineA (IMM32.@)
185  */
187 {
188  TRACE("(%p, %lu, %p, %lu)\n", hIMC, dwIndex, lpBuf, dwBufLen);
189  return ImmGetGuideLineAW(hIMC, dwIndex, lpBuf, dwBufLen, TRUE);
190 }
191 
192 /***********************************************************************
193  * ImmGetGuideLineW (IMM32.@)
194  */
196 {
197  TRACE("(%p, %lu, %p, %lu)\n", hIMC, dwIndex, lpBuf, dwBufLen);
198  return ImmGetGuideLineAW(hIMC, dwIndex, lpBuf, dwBufLen, FALSE);
199 }
DWORD APIENTRY CandidateListAnsiToWide(const CANDIDATELIST *pAnsiCL, LPCANDIDATELIST pWideCL, DWORD dwBufLen, UINT uCodePage)
Definition: candidate.c:84
DWORD dwStrOffset
Definition: imm.h:199
#define WideCharToMultiByte
Definition: compat.h:111
#define TRUE
Definition: types.h:120
LPINPUTCONTEXT WINAPI ImmLockIMC(HIMC hIMC)
Definition: imm.c:1023
#define CP_ACP
Definition: compat.h:109
#define MB_PRECOMPOSED
Definition: winnls.h:281
LPVOID WINAPI ImmLockIMCC(HIMCC imcc)
Definition: utils.c:986
#define GGL_PRIVATE
Definition: imm.h:416
DWORD dwIndex
Definition: imm.h:197
DWORD WINAPI ImmGetGuideLineA(HIMC hIMC, DWORD dwIndex, LPSTR lpBuf, DWORD dwBufLen)
Definition: guideline.c:186
#define GGL_LEVEL
Definition: imm.h:413
if(dx==0 &&dy==0)
Definition: linetemp.h:174
char * LPSTR
Definition: xmlstorage.h:182
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4245
#define CLIENTIMC_WIDE
Definition: ntuser.h:1325
DWORD APIENTRY CandidateListWideToAnsi(const CANDIDATELIST *pWideCL, LPCANDIDATELIST pAnsiCL, DWORD dwBufLen, UINT uCodePage)
Definition: candidate.c:14
unsigned char * LPBYTE
Definition: typedefs.h:53
WINE_DEFAULT_DEBUG_CHANNEL(imm)
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD APIENTRY ImmGetGuideLineAW(HIMC hIMC, DWORD dwIndex, LPVOID lpBuf, DWORD dwBufLen, BOOL bAnsi)
Definition: guideline.c:14
PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc)
Definition: imm.c:909
DWORD HIMC
Definition: dimm.idl:75
DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBufLen)
Definition: guideline.c:195
DWORD dwPrivateSize
Definition: imm.h:200
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GL_ID_REVERSECONVERSION
Definition: imm.h:439
#define GGL_STRING
Definition: imm.h:415
BOOL WINAPI ImmUnlockIMCC(HIMCC imcc)
Definition: utils.c:996
int ret
DWORD dwLevel
Definition: imm.h:196
HIMCC hGuideLine
Definition: immdev.h:53
#define NULL
Definition: types.h:112
#define MultiByteToWideChar
Definition: compat.h:110
DWORD dwPrivateOffset
Definition: imm.h:201
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
DWORD dwFlags
Definition: ntuser.h:1305
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define CHAR(Char)
BOOL WINAPI ImmUnlockIMC(HIMC hIMC)
Definition: imm.c:1032
DWORD dwStrLen
Definition: imm.h:198
#define APIENTRY
Definition: api.h:79
#define GGL_INDEX
Definition: imm.h:414
VOID WINAPI ImmUnlockClientImc(PCLIENTIMC pClientImc)
Definition: imm.c:954