From 854d7021b80a68370d7d3a69af04881e11681abc Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 27 May 2025 17:04:00 +0200 Subject: [PATCH] a11y uia: Report locale via UIA_CulturePropertyId Map QAccessible::Attribute::Locale to UIA_CulturePropertyId [1] in the Windows UIA accessibility bridge: > Identifies the Culture property, which contains a > locale identifier for the automation element (for > example, 0x0409 for "en-US" or English (United States)). In a test with 2 spinboxes whose locales were explicitly set to * QLocale(QLocale::English, QLocale::UnitedStates)) * QLocale(QLocale::Chinese, QLocale::China)) , retrieving the current value of UIA_CulturePropertyId (30015) using NVDA's Python console gives the expected result: With the spinbox whose locale is set to English/United States: >>> hex(focus.UIAElement.GetCurrentPropertyValue(30015)) '0x409' With the spinbox whose locale is set to Chinese/China: >>> hex(focus.UIAElement.GetCurrentPropertyValue(30015)) '0x804' as "[MS-LCID]: Windows Language Code Identifier (LCID) Reference" [2] lists these identifiers as follows: * 0x0409 en-US * 0x0804 zh-CN [1] https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-automation-element-propids [2] https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f Task-number: QTBUG-137144 Change-Id: I2b0cad9ab7ede9f01dee3d7f3efddb8c5335caaf Reviewed-by: Volker Hilsheimer --- .../uiautomation/qwindowsuiamainprovider.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index ef1f212bc4f..5eaba7fbb37 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -535,6 +535,20 @@ HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pR *pRetVal = QComVariant{ className }.release(); } break; + case UIA_CulturePropertyId: + { + QLocale locale; + if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) { + const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale); + if (localeVariant.isValid()) { + Q_ASSERT(localeVariant.canConvert()); + locale = localeVariant.toLocale(); + } + } + LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0); + *pRetVal = QComVariant{ long(lcid) }.release(); + break; + } case UIA_DescribedByPropertyId: fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal); break;