Skip to content

Commit 06fc934

Browse files
authored
feat: Implement the UIA Culture property (#631)
1 parent 5ef75e0 commit 06fc934

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

platforms/windows/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ windows-core = "0.61.0"
2626
version = "0.61.1"
2727
features = [
2828
"Win32_Foundation",
29+
"Win32_Globalization",
2930
"Win32_Graphics_Gdi",
3031
"Win32_System_Com",
3132
"Win32_System_LibraryLoader",

platforms/windows/examples/hello_world.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl InnerWindowState {
9595
if self.announcement.is_some() {
9696
node.push_child(ANNOUNCEMENT_ID);
9797
}
98+
node.set_language("en");
9899
node
99100
}
100101
}

platforms/windows/src/node.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ impl NodeWrapper<'_> {
276276
self.0.description()
277277
}
278278

279+
fn culture(&self) -> Option<LocaleName<'_>> {
280+
self.0.language().map(LocaleName)
281+
}
282+
279283
fn placeholder(&self) -> Option<&str> {
280284
self.0.placeholder()
281285
}
@@ -962,6 +966,7 @@ properties! {
962966
(UIA_LocalizedControlTypePropertyId, localized_control_type),
963967
(UIA_NamePropertyId, name),
964968
(UIA_FullDescriptionPropertyId, description),
969+
(UIA_CulturePropertyId, culture),
965970
(UIA_HelpTextPropertyId, placeholder),
966971
(UIA_IsContentElementPropertyId, is_content_element),
967972
(UIA_IsControlElementPropertyId, is_content_element),

platforms/windows/src/util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use windows::{
1414
core::*,
1515
Win32::{
1616
Foundation::*,
17+
Globalization::*,
1718
Graphics::Gdi::*,
1819
System::{Com::*, Ole::*, Variant::*},
1920
UI::{Accessibility::*, WindowsAndMessaging::*},
@@ -43,6 +44,16 @@ impl From<WideString> for BSTR {
4344
}
4445
}
4546

47+
#[derive(Debug, PartialEq, Eq)]
48+
pub(crate) struct LocaleName<'a>(pub(crate) &'a str);
49+
50+
impl From<LocaleName<'_>> for Variant {
51+
fn from(value: LocaleName) -> Self {
52+
let lcid = unsafe { LocaleNameToLCID(&HSTRING::from(value.0), LOCALE_ALLOW_NEUTRAL_NAMES) };
53+
(lcid != 0).then_some(lcid as i32).into()
54+
}
55+
}
56+
4657
pub(crate) struct Variant(VARIANT);
4758

4859
impl From<Variant> for VARIANT {

0 commit comments

Comments
 (0)