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 registering/unregistering words 5 * COPYRIGHT: Copyright 2020-2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 6 */ 7 8 #include "precomp.h" 9 10 WINE_DEFAULT_DEBUG_CHANNEL(imm); 11 12 typedef struct ENUM_WORD_A2W 13 { 14 REGISTERWORDENUMPROCW lpfnEnumProc; 15 LPVOID lpData; 16 UINT ret; 17 } ENUM_WORD_A2W, *LPENUM_WORD_A2W; 18 19 typedef struct ENUM_WORD_W2A 20 { 21 REGISTERWORDENUMPROCA lpfnEnumProc; 22 LPVOID lpData; 23 UINT ret; 24 } ENUM_WORD_W2A, *LPENUM_WORD_W2A; 25 26 /* 27 * These functions absorb the difference between Ansi and Wide. 28 */ 29 static INT CALLBACK 30 Imm32EnumWordProcA2W(LPCSTR pszReadingA, DWORD dwStyle, LPCSTR pszRegisterA, LPVOID lpData) 31 { 32 INT ret = 0; 33 LPENUM_WORD_A2W lpEnumData = lpData; 34 LPWSTR pszReadingW = NULL, pszRegisterW = NULL; 35 36 if (pszReadingA) 37 { 38 pszReadingW = Imm32WideFromAnsi(pszReadingA); 39 if (pszReadingW == NULL) 40 goto Quit; 41 } 42 43 if (pszRegisterA) 44 { 45 pszRegisterW = Imm32WideFromAnsi(pszRegisterA); 46 if (pszRegisterW == NULL) 47 goto Quit; 48 } 49 50 ret = lpEnumData->lpfnEnumProc(pszReadingW, dwStyle, pszRegisterW, lpEnumData->lpData); 51 lpEnumData->ret = ret; 52 53 Quit: 54 ImmLocalFree(pszReadingW); 55 ImmLocalFree(pszRegisterW); 56 return ret; 57 } 58 59 static INT CALLBACK 60 Imm32EnumWordProcW2A(LPCWSTR pszReadingW, DWORD dwStyle, LPCWSTR pszRegisterW, LPVOID lpData) 61 { 62 INT ret = 0; 63 LPENUM_WORD_W2A lpEnumData = lpData; 64 LPSTR pszReadingA = NULL, pszRegisterA = NULL; 65 66 if (pszReadingW) 67 { 68 pszReadingA = Imm32AnsiFromWide(pszReadingW); 69 if (pszReadingW == NULL) 70 goto Quit; 71 } 72 73 if (pszRegisterW) 74 { 75 pszRegisterA = Imm32AnsiFromWide(pszRegisterW); 76 if (pszRegisterA == NULL) 77 goto Quit; 78 } 79 80 ret = lpEnumData->lpfnEnumProc(pszReadingA, dwStyle, pszRegisterA, lpEnumData->lpData); 81 lpEnumData->ret = ret; 82 83 Quit: 84 ImmLocalFree(pszReadingA); 85 ImmLocalFree(pszRegisterA); 86 return ret; 87 } 88 89 /*********************************************************************** 90 * ImmEnumRegisterWordA (IMM32.@) 91 */ 92 UINT WINAPI 93 ImmEnumRegisterWordA(HKL hKL, REGISTERWORDENUMPROCA lpfnEnumProc, 94 LPCSTR lpszReading, DWORD dwStyle, 95 LPCSTR lpszRegister, LPVOID lpData) 96 { 97 UINT ret = 0; 98 LPWSTR pszReadingW = NULL, pszRegisterW = NULL; 99 ENUM_WORD_W2A EnumDataW2A; 100 PIMEDPI pImeDpi; 101 102 TRACE("(%p, %p, %s, 0x%lX, %s, %p)\n", hKL, lpfnEnumProc, debugstr_a(lpszReading), 103 dwStyle, debugstr_a(lpszRegister), lpData); 104 105 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 106 if (!pImeDpi) 107 return 0; 108 109 if (!ImeDpi_IsUnicode(pImeDpi)) 110 { 111 ret = pImeDpi->ImeEnumRegisterWord(lpfnEnumProc, lpszReading, dwStyle, 112 lpszRegister, lpData); 113 ImmUnlockImeDpi(pImeDpi); 114 return ret; 115 } 116 117 if (lpszReading) 118 { 119 pszReadingW = Imm32WideFromAnsi(lpszReading); 120 if (pszReadingW == NULL) 121 goto Quit; 122 } 123 124 if (lpszRegister) 125 { 126 pszRegisterW = Imm32WideFromAnsi(lpszRegister); 127 if (pszRegisterW == NULL) 128 goto Quit; 129 } 130 131 EnumDataW2A.lpfnEnumProc = lpfnEnumProc; 132 EnumDataW2A.lpData = lpData; 133 EnumDataW2A.ret = 0; 134 pImeDpi->ImeEnumRegisterWord(Imm32EnumWordProcW2A, pszReadingW, dwStyle, 135 pszRegisterW, &EnumDataW2A); 136 ret = EnumDataW2A.ret; 137 138 Quit: 139 ImmLocalFree(pszReadingW); 140 ImmLocalFree(pszRegisterW); 141 ImmUnlockImeDpi(pImeDpi); 142 return ret; 143 } 144 145 /*********************************************************************** 146 * ImmEnumRegisterWordW (IMM32.@) 147 */ 148 UINT WINAPI 149 ImmEnumRegisterWordW(HKL hKL, REGISTERWORDENUMPROCW lpfnEnumProc, 150 LPCWSTR lpszReading, DWORD dwStyle, 151 LPCWSTR lpszRegister, LPVOID lpData) 152 { 153 UINT ret = 0; 154 LPSTR pszReadingA = NULL, pszRegisterA = NULL; 155 ENUM_WORD_A2W EnumDataA2W; 156 PIMEDPI pImeDpi; 157 158 TRACE("(%p, %p, %s, 0x%lX, %s, %p)\n", hKL, lpfnEnumProc, debugstr_w(lpszReading), 159 dwStyle, debugstr_w(lpszRegister), lpData); 160 161 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 162 if (!pImeDpi) 163 return 0; 164 165 if (ImeDpi_IsUnicode(pImeDpi)) 166 { 167 ret = pImeDpi->ImeEnumRegisterWord(lpfnEnumProc, lpszReading, dwStyle, 168 lpszRegister, lpData); 169 ImmUnlockImeDpi(pImeDpi); 170 return ret; 171 } 172 173 if (lpszReading) 174 { 175 pszReadingA = Imm32AnsiFromWide(lpszReading); 176 if (pszReadingA == NULL) 177 goto Quit; 178 } 179 180 if (lpszRegister) 181 { 182 pszRegisterA = Imm32AnsiFromWide(lpszRegister); 183 if (pszRegisterA == NULL) 184 goto Quit; 185 } 186 187 EnumDataA2W.lpfnEnumProc = lpfnEnumProc; 188 EnumDataA2W.lpData = lpData; 189 EnumDataA2W.ret = 0; 190 pImeDpi->ImeEnumRegisterWord(Imm32EnumWordProcA2W, pszReadingA, dwStyle, 191 pszRegisterA, &EnumDataA2W); 192 ret = EnumDataA2W.ret; 193 194 Quit: 195 ImmLocalFree(pszReadingA); 196 ImmLocalFree(pszRegisterA); 197 ImmUnlockImeDpi(pImeDpi); 198 return ret; 199 } 200 201 /*********************************************************************** 202 * ImmGetRegisterWordStyleA (IMM32.@) 203 */ 204 UINT WINAPI ImmGetRegisterWordStyleA(HKL hKL, UINT nItem, LPSTYLEBUFA lpStyleBuf) 205 { 206 UINT iItem, ret = 0; 207 PIMEDPI pImeDpi; 208 LPSTYLEBUFA pDestA; 209 LPSTYLEBUFW pSrcW, pNewStylesW = NULL; 210 size_t cchW; 211 INT cchA; 212 213 TRACE("(%p, %u, %p)\n", hKL, nItem, lpStyleBuf); 214 215 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 216 if (!pImeDpi) 217 return 0; 218 219 if (!ImeDpi_IsUnicode(pImeDpi)) 220 { 221 ret = pImeDpi->ImeGetRegisterWordStyle(nItem, lpStyleBuf); 222 goto Quit; 223 } 224 225 if (nItem > 0) 226 { 227 pNewStylesW = ImmLocalAlloc(0, nItem * sizeof(STYLEBUFW)); 228 if (!pNewStylesW) 229 goto Quit; 230 } 231 232 ret = pImeDpi->ImeGetRegisterWordStyle(nItem, pNewStylesW); 233 234 if (nItem > 0) 235 { 236 /* lpStyleBuf <-- pNewStylesW */ 237 for (iItem = 0; iItem < ret; ++iItem) 238 { 239 pSrcW = &pNewStylesW[iItem]; 240 pDestA = &lpStyleBuf[iItem]; 241 pDestA->dwStyle = pSrcW->dwStyle; 242 StringCchLengthW(pSrcW->szDescription, _countof(pSrcW->szDescription), &cchW); 243 cchA = WideCharToMultiByte(CP_ACP, MB_PRECOMPOSED, 244 pSrcW->szDescription, (INT)cchW, 245 pDestA->szDescription, _countof(pDestA->szDescription), 246 NULL, NULL); 247 if (cchA > _countof(pDestA->szDescription) - 1) 248 cchA = _countof(pDestA->szDescription) - 1; 249 pDestA->szDescription[cchA] = 0; 250 } 251 } 252 253 Quit: 254 ImmLocalFree(pNewStylesW); 255 ImmUnlockImeDpi(pImeDpi); 256 return ret; 257 } 258 259 /*********************************************************************** 260 * ImmGetRegisterWordStyleW (IMM32.@) 261 */ 262 UINT WINAPI ImmGetRegisterWordStyleW(HKL hKL, UINT nItem, LPSTYLEBUFW lpStyleBuf) 263 { 264 UINT iItem, ret = 0; 265 PIMEDPI pImeDpi; 266 LPSTYLEBUFA pSrcA, pNewStylesA = NULL; 267 LPSTYLEBUFW pDestW; 268 size_t cchA; 269 INT cchW; 270 271 TRACE("(%p, %u, %p)\n", hKL, nItem, lpStyleBuf); 272 273 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 274 if (!pImeDpi) 275 return 0; 276 277 if (ImeDpi_IsUnicode(pImeDpi)) 278 { 279 ret = pImeDpi->ImeGetRegisterWordStyle(nItem, lpStyleBuf); 280 goto Quit; 281 } 282 283 if (nItem > 0) 284 { 285 pNewStylesA = ImmLocalAlloc(0, nItem * sizeof(STYLEBUFA)); 286 if (!pNewStylesA) 287 goto Quit; 288 } 289 290 ret = pImeDpi->ImeGetRegisterWordStyle(nItem, pNewStylesA); 291 292 if (nItem > 0) 293 { 294 /* lpStyleBuf <-- pNewStylesA */ 295 for (iItem = 0; iItem < ret; ++iItem) 296 { 297 pSrcA = &pNewStylesA[iItem]; 298 pDestW = &lpStyleBuf[iItem]; 299 pDestW->dwStyle = pSrcA->dwStyle; 300 StringCchLengthA(pSrcA->szDescription, _countof(pSrcA->szDescription), &cchA); 301 cchW = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, 302 pSrcA->szDescription, (INT)cchA, 303 pDestW->szDescription, _countof(pDestW->szDescription)); 304 if (cchW > _countof(pDestW->szDescription) - 1) 305 cchW = _countof(pDestW->szDescription) - 1; 306 pDestW->szDescription[cchW] = 0; 307 } 308 } 309 310 Quit: 311 ImmLocalFree(pNewStylesA); 312 ImmUnlockImeDpi(pImeDpi); 313 return ret; 314 } 315 316 /*********************************************************************** 317 * ImmRegisterWordA (IMM32.@) 318 */ 319 BOOL WINAPI 320 ImmRegisterWordA(HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszRegister) 321 { 322 BOOL ret = FALSE; 323 PIMEDPI pImeDpi; 324 LPWSTR pszReadingW = NULL, pszRegisterW = NULL; 325 326 TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_a(lpszReading), dwStyle, 327 debugstr_a(lpszRegister)); 328 329 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 330 if (!pImeDpi) 331 return FALSE; 332 333 if (!ImeDpi_IsUnicode(pImeDpi)) 334 { 335 ret = pImeDpi->ImeRegisterWord(lpszReading, dwStyle, lpszRegister); 336 ImmUnlockImeDpi(pImeDpi); 337 return ret; 338 } 339 340 if (lpszReading) 341 { 342 pszReadingW = Imm32WideFromAnsi(lpszReading); 343 if (pszReadingW == NULL) 344 goto Quit; 345 } 346 347 if (lpszRegister) 348 { 349 pszRegisterW = Imm32WideFromAnsi(lpszRegister); 350 if (pszRegisterW == NULL) 351 goto Quit; 352 } 353 354 ret = pImeDpi->ImeRegisterWord(pszReadingW, dwStyle, pszRegisterW); 355 356 Quit: 357 ImmLocalFree(pszReadingW); 358 ImmLocalFree(pszRegisterW); 359 ImmUnlockImeDpi(pImeDpi); 360 return ret; 361 } 362 363 /*********************************************************************** 364 * ImmRegisterWordW (IMM32.@) 365 */ 366 BOOL WINAPI 367 ImmRegisterWordW(HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszRegister) 368 { 369 BOOL ret = FALSE; 370 PIMEDPI pImeDpi; 371 LPSTR pszReadingA = NULL, pszRegisterA = NULL; 372 373 TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_w(lpszReading), dwStyle, 374 debugstr_w(lpszRegister)); 375 376 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 377 if (!pImeDpi) 378 return FALSE; 379 380 if (ImeDpi_IsUnicode(pImeDpi)) 381 { 382 ret = pImeDpi->ImeRegisterWord(lpszReading, dwStyle, lpszRegister); 383 ImmUnlockImeDpi(pImeDpi); 384 return ret; 385 } 386 387 if (lpszReading) 388 { 389 pszReadingA = Imm32AnsiFromWide(lpszReading); 390 if (!pszReadingA) 391 goto Quit; 392 } 393 394 if (lpszRegister) 395 { 396 pszRegisterA = Imm32AnsiFromWide(lpszRegister); 397 if (!pszRegisterA) 398 goto Quit; 399 } 400 401 ret = pImeDpi->ImeRegisterWord(pszReadingA, dwStyle, pszRegisterA); 402 403 Quit: 404 ImmLocalFree(pszReadingA); 405 ImmLocalFree(pszRegisterA); 406 ImmUnlockImeDpi(pImeDpi); 407 return ret; 408 } 409 410 /*********************************************************************** 411 * ImmUnregisterWordA (IMM32.@) 412 */ 413 BOOL WINAPI 414 ImmUnregisterWordA(HKL hKL, LPCSTR lpszReading, DWORD dwStyle, LPCSTR lpszUnregister) 415 { 416 BOOL ret = FALSE; 417 PIMEDPI pImeDpi; 418 LPWSTR pszReadingW = NULL, pszUnregisterW = NULL; 419 420 TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_a(lpszReading), dwStyle, 421 debugstr_a(lpszUnregister)); 422 423 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 424 if (pImeDpi == NULL) 425 return FALSE; 426 427 if (!ImeDpi_IsUnicode(pImeDpi)) 428 { 429 ret = pImeDpi->ImeUnregisterWord(lpszReading, dwStyle, lpszUnregister); 430 ImmUnlockImeDpi(pImeDpi); 431 return ret; 432 } 433 434 if (lpszReading) 435 { 436 pszReadingW = Imm32WideFromAnsi(lpszReading); 437 if (pszReadingW == NULL) 438 goto Quit; 439 } 440 441 if (lpszUnregister) 442 { 443 pszUnregisterW = Imm32WideFromAnsi(lpszUnregister); 444 if (pszUnregisterW == NULL) 445 goto Quit; 446 } 447 448 ret = pImeDpi->ImeUnregisterWord(pszReadingW, dwStyle, pszUnregisterW); 449 450 Quit: 451 ImmLocalFree(pszReadingW); 452 ImmLocalFree(pszUnregisterW); 453 ImmUnlockImeDpi(pImeDpi); 454 return ret; 455 } 456 457 /*********************************************************************** 458 * ImmUnregisterWordW (IMM32.@) 459 */ 460 BOOL WINAPI 461 ImmUnregisterWordW(HKL hKL, LPCWSTR lpszReading, DWORD dwStyle, LPCWSTR lpszUnregister) 462 { 463 BOOL ret = FALSE; 464 PIMEDPI pImeDpi; 465 LPSTR pszReadingA = NULL, pszUnregisterA = NULL; 466 467 TRACE("(%p, %s, 0x%lX, %s)\n", hKL, debugstr_w(lpszReading), dwStyle, 468 debugstr_w(lpszUnregister)); 469 470 pImeDpi = Imm32FindOrLoadImeDpi(hKL); 471 if (!pImeDpi) 472 return FALSE; 473 474 if (ImeDpi_IsUnicode(pImeDpi)) 475 { 476 ret = pImeDpi->ImeUnregisterWord(lpszReading, dwStyle, lpszUnregister); 477 ImmUnlockImeDpi(pImeDpi); 478 return ret; 479 } 480 481 if (lpszReading) 482 { 483 pszReadingA = Imm32AnsiFromWide(lpszReading); 484 if (!pszReadingA) 485 goto Quit; 486 } 487 488 if (lpszUnregister) 489 { 490 pszUnregisterA = Imm32AnsiFromWide(lpszUnregister); 491 if (!pszUnregisterA) 492 goto Quit; 493 } 494 495 ret = pImeDpi->ImeUnregisterWord(pszReadingA, dwStyle, pszUnregisterA); 496 497 Quit: 498 ImmLocalFree(pszReadingA); 499 ImmLocalFree(pszUnregisterA); 500 ImmUnlockImeDpi(pImeDpi); 501 return ret; 502 } 503