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