winemac.drv: Use UCCompareText in char_matches_string.

This commit is contained in:
Marc-Aurel Zent 2024-03-15 09:02:48 +01:00 committed by Alexandre Julliard
parent 5a97ad97dc
commit c9d9ff6129

View file

@ -398,18 +398,18 @@ static const struct {
{ VK_VOLUME_UP | 0x100, "Volume Up" }, { VK_VOLUME_UP | 0x100, "Volume Up" },
}; };
static BOOL char_matches_string(WCHAR wchar, UniChar *string, BOOL ignore_diacritics) static Boolean char_matches_string(WCHAR wchar, UniChar *string, CollatorRef collatorRef)
{ {
BOOL ret; Boolean equivalent;
CFStringRef s1 = CFStringCreateWithCharactersNoCopy(NULL, (UniChar*)&wchar, 1, kCFAllocatorNull); OSStatus status;
CFStringRef s2 = CFStringCreateWithCharactersNoCopy(NULL, string, wcslen(string), kCFAllocatorNull);
CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNonliteral | kCFCompareWidthInsensitive; status = UCCompareText(collatorRef, (UniChar*)&wchar, 1, string, wcslen(string), &equivalent, NULL);
if (ignore_diacritics) if (status != noErr)
flags |= kCFCompareDiacriticInsensitive; {
ret = (CFStringCompare(s1, s2, flags) == kCFCompareEqualTo); WARN("Failed to compare %s to %s\n", debugstr_wn(&wchar, 1), debugstr_w(string));
CFRelease(s1); return FALSE;
CFRelease(s2); }
return ret; return equivalent;
} }
@ -657,6 +657,9 @@ void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data)
int keyc; int keyc;
WCHAR vkey; WCHAR vkey;
const UCKeyboardLayout *uchr; const UCKeyboardLayout *uchr;
LocaleRef localeRef;
CollatorRef collatorRef, caseInsensitiveCollatorRef, diacriticInsensitiveCollatorRef;
UCCollateOptions collateOptions = 0;
const UInt32 modifier_combos[] = { const UInt32 modifier_combos[] = {
0, 0,
shiftKey >> 8, shiftKey >> 8,
@ -778,6 +781,13 @@ void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data)
uchr = (const UCKeyboardLayout*)CFDataGetBytePtr(thread_data->keyboard_layout_uchr); uchr = (const UCKeyboardLayout*)CFDataGetBytePtr(thread_data->keyboard_layout_uchr);
LocaleRefFromLocaleString("POSIX", &localeRef);
UCCreateCollator(localeRef, 0, collateOptions, &collatorRef);
collateOptions |= kUCCollateComposeInsensitiveMask | kUCCollateWidthInsensitiveMask | kUCCollateCaseInsensitiveMask;
UCCreateCollator(localeRef, 0, collateOptions, &caseInsensitiveCollatorRef);
collateOptions |= kUCCollateDiacritInsensitiveMask;
UCCreateCollator(localeRef, 0, collateOptions, &diacriticInsensitiveCollatorRef);
/* Using the keyboard layout, build a map of key code + modifiers -> characters. */ /* Using the keyboard layout, build a map of key code + modifiers -> characters. */
memset(map, 0, sizeof(map)); memset(map, 0, sizeof(map));
for (keyc = 0; keyc < ARRAY_SIZE(map); keyc++) for (keyc = 0; keyc < ARRAY_SIZE(map); keyc++)
@ -824,7 +834,7 @@ void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data)
if (thread_data->keyc2vkey[keyc] || !map[keyc][combo][0]) if (thread_data->keyc2vkey[keyc] || !map[keyc][combo][0])
continue; continue;
if (char_matches_string(vkey, map[keyc][combo], ignore_diacritics)) if (char_matches_string(vkey, map[keyc][combo], ignore_diacritics ? diacriticInsensitiveCollatorRef : caseInsensitiveCollatorRef))
{ {
thread_data->keyc2vkey[keyc] = vkey; thread_data->keyc2vkey[keyc] = vkey;
vkey_used[vkey] = 1; vkey_used[vkey] = 1;
@ -850,7 +860,7 @@ void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data)
if (thread_data->keyc2vkey[keyc] || !map[keyc][combo][0]) if (thread_data->keyc2vkey[keyc] || !map[keyc][combo][0])
continue; continue;
if (char_matches_string(vkey, map[keyc][combo], FALSE)) if (char_matches_string(vkey, map[keyc][combo], collatorRef))
{ {
thread_data->keyc2vkey[keyc] = vkey; thread_data->keyc2vkey[keyc] = vkey;
vkey_used[vkey] = 1; vkey_used[vkey] = 1;
@ -879,7 +889,7 @@ void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data)
if (thread_data->keyc2vkey[keyc] || !map[keyc][combo][0]) if (thread_data->keyc2vkey[keyc] || !map[keyc][combo][0])
continue; continue;
if (char_matches_string(symbol_vkeys[i].wchar, map[keyc][combo], FALSE)) if (char_matches_string(symbol_vkeys[i].wchar, map[keyc][combo], collatorRef))
{ {
thread_data->keyc2vkey[keyc] = vkey; thread_data->keyc2vkey[keyc] = vkey;
vkey_used[vkey] = 1; vkey_used[vkey] = 1;
@ -982,6 +992,10 @@ void macdrv_compute_keyboard_layout(struct macdrv_thread_data *thread_data)
vkey_used[vkey] = 1; vkey_used[vkey] = 1;
TRACE("keyc 0x%04x -> vkey 0x%04x (spare vkey)\n", keyc, vkey); TRACE("keyc 0x%04x -> vkey 0x%04x (spare vkey)\n", keyc, vkey);
} }
UCDisposeCollator(&collatorRef);
UCDisposeCollator(&caseInsensitiveCollatorRef);
UCDisposeCollator(&diacriticInsensitiveCollatorRef);
} }