win_wrap/uia/pattern/
legacy.rs1use crate::{
15 msaa::object::AccessibleObject,
16 uia::pattern::{PatternCreator, PatternError},
17};
18use std::fmt::{Debug, Formatter};
19use windows::{
20 core::{Result, BSTR},
21 Win32::UI::Accessibility::{
22 IUIAutomationLegacyIAccessiblePattern, UIA_LegacyIAccessiblePatternId, UIA_PATTERN_ID,
23 },
24};
25
26pub struct UiAutomationIAccessiblePattern(IUIAutomationLegacyIAccessiblePattern);
31
32impl TryFrom<IUIAutomationLegacyIAccessiblePattern> for UiAutomationIAccessiblePattern {
33 type Error = PatternError;
34
35 fn try_from(
36 value: IUIAutomationLegacyIAccessiblePattern,
37 ) -> std::result::Result<Self, Self::Error> {
38 Ok(Self(value))
39 }
40}
41
42impl PatternCreator<IUIAutomationLegacyIAccessiblePattern> for UiAutomationIAccessiblePattern {
43 const PATTERN: UIA_PATTERN_ID = UIA_LegacyIAccessiblePatternId;
44}
45
46impl UiAutomationIAccessiblePattern {
48 pub fn get_name(&self) -> String {
52 unsafe { self.0.CurrentName() }
53 .unwrap_or(BSTR::default())
54 .to_string()
55 }
56
57 pub fn get_description(&self) -> String {
61 unsafe { self.0.CurrentDescription() }
62 .unwrap_or(BSTR::default())
63 .to_string()
64 }
65
66 pub fn get_help(&self) -> String {
70 unsafe { self.0.CurrentHelp() }
71 .unwrap_or(BSTR::default())
72 .to_string()
73 }
74
75 pub fn get_state(&self) -> u32 {
79 unsafe { self.0.CurrentState() }.unwrap_or(0)
80 }
81
82 pub fn get_role(&self) -> u32 {
86 unsafe { self.0.CurrentRole() }.unwrap_or(0)
87 }
88
89 pub fn get_object(&self) -> Result<AccessibleObject> {
93 match unsafe { self.0.GetIAccessible() } {
94 Ok(o) => Ok(AccessibleObject::from_raw(
95 o,
96 unsafe { self.0.CurrentChildId() }.unwrap_or(0),
97 )),
98 Err(e) => Err(e),
99 }
100 }
101}
102
103impl Debug for UiAutomationIAccessiblePattern {
104 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
105 write!(
106 f,
107 "UiAutomationIAccessiblePattern(name:{}, description:{}, role:{})",
108 self.get_name(),
109 self.get_description(),
110 self.get_role()
111 )
112 }
113}