win_wrap/uia/pattern/range.rs
1/*
2 * Copyright (c) 2024. The RigelA open source project team and
3 * its contributors reserve all rights.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and limitations under the License.
12 */
13use crate::uia::pattern::{PatternCreator, PatternError};
14use windows::Win32::UI::Accessibility::{
15 IUIAutomationRangeValuePattern, UIA_RangeValuePatternId, UIA_PATTERN_ID,
16};
17
18/**
19提供对显示一系列值的控件的访问。
20*/
21pub struct UiAutomationRangeValuePattern(IUIAutomationRangeValuePattern);
22
23impl TryFrom<IUIAutomationRangeValuePattern> for UiAutomationRangeValuePattern {
24 type Error = PatternError;
25
26 fn try_from(value: IUIAutomationRangeValuePattern) -> Result<Self, Self::Error> {
27 Ok(Self(value))
28 }
29}
30
31impl PatternCreator<IUIAutomationRangeValuePattern> for UiAutomationRangeValuePattern {
32 const PATTERN: UIA_PATTERN_ID = UIA_RangeValuePatternId;
33}
34
35/// https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationrangevaluepattern
36impl UiAutomationRangeValuePattern {
37 /**
38 指示是否可以更改元素的值。
39 此属性是只读的。
40 */
41 pub fn is_read_only(&self) -> bool {
42 unsafe { self.0.CurrentIsReadOnly().unwrap_or(Default::default()) }.as_bool()
43 }
44
45 /**
46 检索在进行较大更改时(例如,按下 PAGE DOWN 键时)向控件的值添加或减去的值。
47 此属性是只读的。
48 LargeChange 属性可以支持非数字 (NaN) 值。检索此属性时,客户端可以使用 _isnan 函数来确定该属性是否为 NaN 值。
49 */
50 pub fn get_large_change(&self) -> f64 {
51 unsafe { self.0.CurrentLargeChange().unwrap_or(0f64) }
52 }
53
54 /**
55 检索控件的最大值。
56 此属性是只读的。
57 */
58 pub fn get_maximum(&self) -> f64 {
59 unsafe { self.0.CurrentMaximum().unwrap_or(0f64) }
60 }
61
62 /**
63 检索控件的最小值。
64 此属性是只读的。
65 */
66 pub fn get_minimum(&self) -> f64 {
67 unsafe { self.0.CurrentMinimum().unwrap_or(0f64) }
68 }
69
70 /**
71 检索在进行小的更改时(例如,当按下箭头键时)添加到控件的值或从控件的值中减去的值。
72 此属性是只读的。
73 SmallChange 属性可以支持非数字 (NaN) 值。检索此属性时,客户端可以使用 _isnan 函数来确定该属性是否为 NaN 值。
74 */
75 pub fn get_small_change(&self) -> f64 {
76 unsafe { self.0.CurrentSmallChange().unwrap_or(0f64) }
77 }
78
79 /**
80 检索控件的值。
81 此属性是只读的。
82 */
83 pub fn get_value(&self) -> f64 {
84 unsafe { self.0.CurrentValue().unwrap_or(0f64) }
85 }
86
87 /**
88 设置控件的值。
89 */
90 pub fn set_value(&self, value: f64) -> bool {
91 unsafe { self.0.SetValue(value) }.is_ok()
92 }
93}