From 66fe86b674c24d18fc4f71360001df03bb810fb2 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Sat, 11 Nov 2023 10:50:09 +0800 Subject: [PATCH 01/15] update config --- samples/win_update/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/win_update/Cargo.toml b/samples/win_update/Cargo.toml index 6ca45be..93d5016 100644 --- a/samples/win_update/Cargo.toml +++ b/samples/win_update/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "win-update" -version = "1.6.0" +version = "1.6.1" edition = "2021" [dependencies] @@ -8,4 +8,5 @@ edition = "2021" uiautomation = { path = "../../crates/uiautomation" } [[bin]] + name = "win-update" \ No newline at end of file From 898ff0ecbe22318362ffc0a81fdb6e0b491367c6 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Thu, 16 Nov 2023 10:37:39 +0800 Subject: [PATCH 02/15] update to windows 0.52 --- CHANGELOG.md | 4 ++++ crates/uiautomation/Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80e08c7..9a95247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,3 +110,7 @@ ## v0.7.2 + support converting `isize` to `Handle`. [issue-44](https://github.com/leexgone/uiautomation-rs/issues/44) + +## v0.7.3 + ++ update to `widnows v0.52.0` diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index 929030d..33e4270 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation" -version = "0.7.2" +version = "0.7.3" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -22,7 +22,7 @@ phf = { version = "0.11.2", features = ["macros"] } uiautomation_derive = { version = "0.2.16", path = "../uiautomation_derive" } [dependencies.windows] -version = "0.51.1" +version = "0.52.0" features = [ "Win32_Foundation", "Win32_System_Variant", From b2c0dbe9ba0b06f0d8d7be80264d92f446f035d2 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Mon, 27 Nov 2023 19:47:41 +0800 Subject: [PATCH 03/15] update deps --- crates/uiautomation_derive/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/uiautomation_derive/Cargo.toml b/crates/uiautomation_derive/Cargo.toml index e6492a9..cc847d8 100644 --- a/crates/uiautomation_derive/Cargo.toml +++ b/crates/uiautomation_derive/Cargo.toml @@ -20,4 +20,4 @@ targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows [dependencies] syn = { version = "2.0.39", features = ["full"] } quote = "1.0.33" -proc-macro2 = "1.0.69" +proc-macro2 = "1.0.70" From 98657d4e4a95f9532a60a2c90b8684d5e7e46a05 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Sun, 17 Dec 2023 17:27:44 +0800 Subject: [PATCH 04/15] update deps --- crates/uiautomation_derive/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/uiautomation_derive/Cargo.toml b/crates/uiautomation_derive/Cargo.toml index cc847d8..78f3589 100644 --- a/crates/uiautomation_derive/Cargo.toml +++ b/crates/uiautomation_derive/Cargo.toml @@ -18,6 +18,6 @@ default-target = "x86_64-pc-windows-msvc" targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"] [dependencies] -syn = { version = "2.0.39", features = ["full"] } +syn = { version = "2.0.41", features = ["full"] } quote = "1.0.33" proc-macro2 = "1.0.70" From b1a36282f3ba601d612cdce822b01cbb3ac55720 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Sat, 30 Dec 2023 11:13:22 +0800 Subject: [PATCH 05/15] update deps --- crates/uiautomation/Cargo.toml | 4 ++-- crates/uiautomation_derive/Cargo.toml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index 33e4270..99a31c9 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation" -version = "0.7.3" +version = "0.7.4" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -19,7 +19,7 @@ targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows chrono = "0.4.31" phf = { version = "0.11.2", features = ["macros"] } -uiautomation_derive = { version = "0.2.16", path = "../uiautomation_derive" } +uiautomation_derive = { version = "0.2.17", path = "../uiautomation_derive" } [dependencies.windows] version = "0.52.0" diff --git a/crates/uiautomation_derive/Cargo.toml b/crates/uiautomation_derive/Cargo.toml index 78f3589..2670025 100644 --- a/crates/uiautomation_derive/Cargo.toml +++ b/crates/uiautomation_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation_derive" -version = "0.2.16" +version = "0.2.17" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -18,6 +18,6 @@ default-target = "x86_64-pc-windows-msvc" targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"] [dependencies] -syn = { version = "2.0.41", features = ["full"] } +syn = { version = "2.0.43", features = ["full"] } quote = "1.0.33" -proc-macro2 = "1.0.70" +proc-macro2 = "1.0.71" From 283341171a16444f16be89d5a4cfa60943a49b67 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Sat, 20 Jan 2024 21:22:45 +0800 Subject: [PATCH 06/15] update deps --- crates/uiautomation/Cargo.toml | 2 +- crates/uiautomation_derive/Cargo.toml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index 99a31c9..05b1664 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation" -version = "0.7.4" +version = "0.7.5" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] diff --git a/crates/uiautomation_derive/Cargo.toml b/crates/uiautomation_derive/Cargo.toml index 2670025..1acb5a7 100644 --- a/crates/uiautomation_derive/Cargo.toml +++ b/crates/uiautomation_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation_derive" -version = "0.2.17" +version = "0.2.18" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -18,6 +18,6 @@ default-target = "x86_64-pc-windows-msvc" targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"] [dependencies] -syn = { version = "2.0.43", features = ["full"] } -quote = "1.0.33" -proc-macro2 = "1.0.71" +syn = { version = "2.0.48", features = ["full"] } +quote = "1.0.35" +proc-macro2 = "1.0.76" From e81ff8aa1d0b5274e02bf936a2bf7aa2923baf33 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Tue, 20 Feb 2024 20:59:28 +0800 Subject: [PATCH 07/15] update deps --- crates/uiautomation/Cargo.toml | 6 +++--- crates/uiautomation_derive/Cargo.toml | 6 +++--- samples/win_update/Cargo.toml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index 05b1664..875ef1d 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation" -version = "0.7.5" +version = "0.7.6" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -17,9 +17,9 @@ targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows [dependencies] -chrono = "0.4.31" +chrono = "0.4.34" phf = { version = "0.11.2", features = ["macros"] } -uiautomation_derive = { version = "0.2.17", path = "../uiautomation_derive" } +uiautomation_derive = { version = "0.2.19", path = "../uiautomation_derive" } [dependencies.windows] version = "0.52.0" diff --git a/crates/uiautomation_derive/Cargo.toml b/crates/uiautomation_derive/Cargo.toml index 1acb5a7..41c8d10 100644 --- a/crates/uiautomation_derive/Cargo.toml +++ b/crates/uiautomation_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation_derive" -version = "0.2.18" +version = "0.2.19" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -18,6 +18,6 @@ default-target = "x86_64-pc-windows-msvc" targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"] [dependencies] -syn = { version = "2.0.48", features = ["full"] } +syn = { version = "2.0.50", features = ["full"] } quote = "1.0.35" -proc-macro2 = "1.0.76" +proc-macro2 = "1.0.78" diff --git a/samples/win_update/Cargo.toml b/samples/win_update/Cargo.toml index 93d5016..a225f43 100644 --- a/samples/win_update/Cargo.toml +++ b/samples/win_update/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "win-update" -version = "1.6.1" +version = "1.6.2" edition = "2021" [dependencies] From 7d3788d8deba8398e56215a317da00b475a43899 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Thu, 7 Mar 2024 18:02:55 +0800 Subject: [PATCH 08/15] update to windows 0.54 --- CHANGELOG.md | 4 ++++ crates/uiautomation/Cargo.toml | 8 ++++---- crates/uiautomation_derive/Cargo.toml | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a95247..3a7c0e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,3 +114,7 @@ ## v0.7.3 + update to `widnows v0.52.0` + +## v0.8.0 + ++ update to `windows v0.54.0` diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index 875ef1d..b7e88dc 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation" -version = "0.7.6" +version = "0.8.0" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -17,12 +17,12 @@ targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows [dependencies] -chrono = "0.4.34" +chrono = "0.4.35" phf = { version = "0.11.2", features = ["macros"] } -uiautomation_derive = { version = "0.2.19", path = "../uiautomation_derive" } +uiautomation_derive = { version = "0.2.20", path = "../uiautomation_derive" } [dependencies.windows] -version = "0.52.0" +version = "0.54.0" features = [ "Win32_Foundation", "Win32_System_Variant", diff --git a/crates/uiautomation_derive/Cargo.toml b/crates/uiautomation_derive/Cargo.toml index 41c8d10..ade5420 100644 --- a/crates/uiautomation_derive/Cargo.toml +++ b/crates/uiautomation_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uiautomation_derive" -version = "0.2.19" +version = "0.2.20" edition = "2021" license = "Apache-2.0" authors = ["Steven Lee "] @@ -18,6 +18,6 @@ default-target = "x86_64-pc-windows-msvc" targets = ["aarch64-pc-windows-msvc", "i686-pc-windows-msvc", "x86_64-pc-windows-msvc"] [dependencies] -syn = { version = "2.0.50", features = ["full"] } +syn = { version = "2.0.52", features = ["full"] } quote = "1.0.35" proc-macro2 = "1.0.78" From c2c30905cda08bba53a939a9ee1e470f3ce7600d Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Thu, 7 Mar 2024 20:42:58 +0800 Subject: [PATCH 09/15] =?UTF-8?q?variant=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/uiautomation/Cargo.toml | 3 +- crates/uiautomation/src/types.rs | 2 +- crates/uiautomation/src/variants.rs | 120 ++++++++++++++++------------ 3 files changed, 70 insertions(+), 55 deletions(-) diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index b7e88dc..b90eb0a 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -34,5 +34,6 @@ features = [ "Win32_System_Threading", "Win32_Security", "Win32_UI_Shell_PropertiesSystem", - "UI_UIAutomation" + "UI_UIAutomation", + "implement" ] \ No newline at end of file diff --git a/crates/uiautomation/src/types.rs b/crates/uiautomation/src/types.rs index 73fbc41..1648f04 100644 --- a/crates/uiautomation/src/types.rs +++ b/crates/uiautomation/src/types.rs @@ -225,7 +225,7 @@ impl AsRef for Handle { } impl IntoParam for Handle { - fn into_param(self) -> windows::core::Param { + unsafe fn into_param(self) -> windows::core::Param { windows::core::Param::Owned(self.0) } } diff --git a/crates/uiautomation/src/variants.rs b/crates/uiautomation/src/variants.rs index 75aef35..5e9950a 100644 --- a/crates/uiautomation/src/variants.rs +++ b/crates/uiautomation/src/variants.rs @@ -1,17 +1,20 @@ +use std::ffi::c_void; use std::fmt::Display; use std::mem::ManuallyDrop; use std::ptr::null_mut; -use windows::Win32::Foundation::DECIMAL; -use windows::Win32::System::Com::*; -use windows::Win32::System::Ole::*; -use windows::Win32::System::Variant::*; +use windows::core::VARIANT; use windows::core::BSTR; use windows::core::HRESULT; use windows::core::HSTRING; use windows::core::IUnknown; use windows::core::Interface; use windows::core::PSTR; +use windows::core::imp; +use windows::Win32::Foundation::DECIMAL; +use windows::Win32::System::Com::*; +use windows::Win32::System::Ole::*; +use windows::Win32::System::Variant::*; use super::Error; use super::Result; @@ -121,40 +124,49 @@ pub struct Variant { impl Variant { /// Create a null variant. fn new_null(vt: VARENUM) -> Variant { - let mut val = VARIANT_0_0::default(); - val.vt = vt; // vt.0 as u16; - - let variant = VARIANT { - Anonymous: VARIANT_0 { - Anonymous: ManuallyDrop::new(val) - } - }; + // let mut val = VARIANT_0_0::default(); + // val.vt = vt; // vt.0 as u16; + + // let variant = VARIANT { + // Anonymous: VARIANT_0 { + // Anonymous: ManuallyDrop::new(val) + // } + // }; + let variant = VARIANT::default(); + let val = variant.as_raw(); + val.Anonymous.Anonymous.vt = vt.0; variant.into() } /// Create a `Variant` from `vt` and `value`. - fn new(vt: VARENUM, value: VARIANT_0_0_0) -> Variant { - let variant = VARIANT { - Anonymous: VARIANT_0 { - Anonymous: ManuallyDrop::new(VARIANT_0_0 { - vt: vt, //vt.0 as u16, - wReserved1: 0, - wReserved2: 0, - wReserved3: 0, - Anonymous: value - }) - } - }; + fn new(vt: VARENUM, value: imp::VARIANT_0_0_0) -> Variant { + // let variant = VARIANT { + // Anonymous: VARIANT_0 { + // Anonymous: ManuallyDrop::new(VARIANT_0_0 { + // vt: vt, //vt.0 as u16, + // wReserved1: 0, + // wReserved2: 0, + // wReserved3: 0, + // Anonymous: value + // }) + // } + // }; + let variant = VARIANT::default(); + let val = variant.as_raw(); + val.Anonymous.Anonymous.vt = vt.0; + val.Anonymous.Anonymous.Anonymous = value; variant.into() } /// Retrieve the variant type. fn vt(&self) -> VARENUM { - unsafe { - self.value.Anonymous.Anonymous.vt //as i32 - } + let val = self.value.as_raw(); + VARENUM(val.Anonymous.Anonymous.vt) + // unsafe { + // self.value.Anonymous.Anonymous.vt //as i32 + // } } /// Retrieve the variant type as `VARENUM`. @@ -164,8 +176,10 @@ impl Variant { } /// Retrieve the data of the variant. - pub(crate) unsafe fn get_data(&self) -> &VARIANT_0_0_0 { - &self.value.Anonymous.Anonymous.Anonymous + pub(crate) fn get_data(&self) -> &imp::VARIANT_0_0_0 { + // &self.value.Anonymous.Anonymous.Anonymous + let var = self.value.as_raw(); + &var.Anonymous.Anonymous.Anonymous } /// Try to get value. @@ -363,7 +377,7 @@ macro_rules! vec_to_variant { { let vt = VARENUM(VT_ARRAY.0 | $t.0); let arr: SafeArray = $v.try_into().unwrap(); - Variant::new(vt, VARIANT_0_0_0 { parray: arr.array }) + Variant::new(vt, imp::VARIANT_0_0_0 { parray: arr.array }) } }; } @@ -374,29 +388,29 @@ impl From for Variant { Value::EMPTY => Variant::new_null(VT_EMPTY), Value::NULL => Variant::new_null(VT_NULL), Value::VOID => Variant::new_null(VT_VOID), - Value::I1(v) => Variant::new(VT_I1, VARIANT_0_0_0 { bVal: v as u8 }), - Value::I2(v) => Variant::new(VT_I2, VARIANT_0_0_0 { iVal: v }), - Value::I4(v) => Variant::new(VT_I4, VARIANT_0_0_0 { lVal: v }), - Value::I8(v) => Variant::new(VT_I8, VARIANT_0_0_0 { llVal: v }), - Value::INT(v) => Variant::new(VT_INT, VARIANT_0_0_0 { lVal: v }), - Value::UI1(v) => Variant::new(VT_UI1, VARIANT_0_0_0 { bVal: v }), - Value::UI2(v) => Variant::new(VT_UI2, VARIANT_0_0_0 { uiVal: v }), - Value::UI4(v) => Variant::new(VT_UI4, VARIANT_0_0_0 { ulVal: v }), - Value::UI8(v) => Variant::new(VT_UI8, VARIANT_0_0_0 { ullVal: v }), - Value::UINT(v) => Variant::new(VT_UINT, VARIANT_0_0_0 { uintVal: v }), - Value::R4(v) => Variant::new(VT_R4, VARIANT_0_0_0 { fltVal: v }), - Value::R8(v) => Variant::new(VT_R8, VARIANT_0_0_0 { dblVal: v }), - Value::CURRENCY(v) => Variant::new(VT_CY, VARIANT_0_0_0 { cyVal: CY { int64: v} }), - Value::DATE(v) => Variant::new(VT_DATE, VARIANT_0_0_0 { date: v }), - Value::STRING(v) => Variant::new(VT_BSTR, VARIANT_0_0_0 { bstrVal: ManuallyDrop::new(BSTR::from(v)) }), - Value::UNKNOWN(v) => Variant::new(VT_UNKNOWN, VARIANT_0_0_0 { punkVal: ManuallyDrop::new(Some(v)) }), - Value::DISPATCH(v) => Variant::new(VT_DISPATCH, VARIANT_0_0_0 { pdispVal: ManuallyDrop::new(Some(v)) }), - Value::ERROR(v) => Variant::new(VT_ERROR, VARIANT_0_0_0 { intVal: v.0 }), - Value::HRESULT(v) => Variant::new(VT_HRESULT, VARIANT_0_0_0 { intVal: v.0 }), - Value::BOOL(v) => Variant::new(VT_BOOL, VARIANT_0_0_0 { boolVal: v.into() }), - Value::VARIANT(mut v) => Variant::new(VT_VARIANT, VARIANT_0_0_0 { pvarVal: &mut v.value }), - Value::DECIMAL(mut v) => Variant::new(VT_DECIMAL, VARIANT_0_0_0 { pdecVal: &mut v }), - Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, VARIANT_0_0_0 { parray: v.array }), + Value::I1(v) => Variant::new(VT_I1, imp::VARIANT_0_0_0 { bVal: v as u8 }), + Value::I2(v) => Variant::new(VT_I2, imp::VARIANT_0_0_0 { iVal: v }), + Value::I4(v) => Variant::new(VT_I4, imp::VARIANT_0_0_0 { lVal: v }), + Value::I8(v) => Variant::new(VT_I8, imp::VARIANT_0_0_0 { llVal: v }), + Value::INT(v) => Variant::new(VT_INT, imp::VARIANT_0_0_0 { lVal: v }), + Value::UI1(v) => Variant::new(VT_UI1, imp::VARIANT_0_0_0 { bVal: v }), + Value::UI2(v) => Variant::new(VT_UI2, imp::VARIANT_0_0_0 { uiVal: v }), + Value::UI4(v) => Variant::new(VT_UI4, imp::VARIANT_0_0_0 { ulVal: v }), + Value::UI8(v) => Variant::new(VT_UI8, imp::VARIANT_0_0_0 { ullVal: v }), + Value::UINT(v) => Variant::new(VT_UINT, imp::VARIANT_0_0_0 { uintVal: v }), + Value::R4(v) => Variant::new(VT_R4, imp::VARIANT_0_0_0 { fltVal: v }), + Value::R8(v) => Variant::new(VT_R8, imp::VARIANT_0_0_0 { dblVal: v }), + Value::CURRENCY(v) => Variant::new(VT_CY, imp::VARIANT_0_0_0 { cyVal: imp::CY { int64: v} }), + Value::DATE(v) => Variant::new(VT_DATE, imp::VARIANT_0_0_0 { date: v }), + Value::STRING(v) => { let s = BSTR::from(v); let v = VARIANT::from(s); v.into() }, //Variant::new(VT_BSTR, imp::VARIANT_0_0_0 { bstrVal: v.as_str() as _ }), + Value::UNKNOWN(v) => { let var = VARIANT::from(v); var.into() } //Variant::new(VT_UNKNOWN, imp::VARIANT_0_0_0 { punkVal: ManuallyDrop::new(Some(v)) }), + Value::DISPATCH(v) => Variant::new(VT_DISPATCH, imp::VARIANT_0_0_0 { pdispVal: ManuallyDrop::new(Some(v)) }), + Value::ERROR(v) => Variant::new(VT_ERROR, imp::VARIANT_0_0_0 { intVal: v.0 }), + Value::HRESULT(v) => Variant::new(VT_HRESULT, imp::VARIANT_0_0_0 { intVal: v.0 }), + Value::BOOL(v) => Variant::new(VT_BOOL, imp::VARIANT_0_0_0 { boolVal: v.into() }), + Value::VARIANT(mut v) => Variant::new(VT_VARIANT, imp::VARIANT_0_0_0 { pvarVal: &mut v.value }), + Value::DECIMAL(mut v) => Variant::new(VT_DECIMAL, imp::VARIANT_0_0_0 { pdecVal: &mut v }), + Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, imp::VARIANT_0_0_0 { parray: v.array }), Value::ArrayBool(v) => vec_to_variant!(v, VT_BOOL), //Variant::new(VT_SAFEARRAY, VARIANT_0_0_0 { parray: v.array }), Value::ArrayR8(v) => vec_to_variant!(v, VT_R8), Value::ArrayI2(v) => vec_to_variant!(v, VT_I2), From 181e0c2ca87d6d4b40fae810cd129140894624fb Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Fri, 8 Mar 2024 21:20:57 +0800 Subject: [PATCH 10/15] var --- crates/uiautomation/Cargo.toml | 2 +- crates/uiautomation/src/variants.rs | 182 +++++++++++++++++++++------- 2 files changed, 141 insertions(+), 43 deletions(-) diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index b90eb0a..10ef796 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -35,5 +35,5 @@ features = [ "Win32_Security", "Win32_UI_Shell_PropertiesSystem", "UI_UIAutomation", - "implement" + # "implement" ] \ No newline at end of file diff --git a/crates/uiautomation/src/variants.rs b/crates/uiautomation/src/variants.rs index 5e9950a..cc218d3 100644 --- a/crates/uiautomation/src/variants.rs +++ b/crates/uiautomation/src/variants.rs @@ -12,6 +12,7 @@ use windows::core::Interface; use windows::core::PSTR; use windows::core::imp; use windows::Win32::Foundation::DECIMAL; +use windows::Win32::Foundation::VARIANT_BOOL; use windows::Win32::System::Com::*; use windows::Win32::System::Ole::*; use windows::Win32::System::Variant::*; @@ -372,12 +373,21 @@ impl Display for Variant { } } +macro_rules! val_to_variant { + ($v: expr) => { + { + let variant = VARIANT::from($v); + variant.into() + } + }; +} + macro_rules! vec_to_variant { ($v: expr, $t: expr) => { { let vt = VARENUM(VT_ARRAY.0 | $t.0); let arr: SafeArray = $v.try_into().unwrap(); - Variant::new(vt, imp::VARIANT_0_0_0 { parray: arr.array }) + Variant::new(vt, imp::VARIANT_0_0_0 { parray: arr.into() }) } }; } @@ -388,29 +398,43 @@ impl From for Variant { Value::EMPTY => Variant::new_null(VT_EMPTY), Value::NULL => Variant::new_null(VT_NULL), Value::VOID => Variant::new_null(VT_VOID), - Value::I1(v) => Variant::new(VT_I1, imp::VARIANT_0_0_0 { bVal: v as u8 }), - Value::I2(v) => Variant::new(VT_I2, imp::VARIANT_0_0_0 { iVal: v }), - Value::I4(v) => Variant::new(VT_I4, imp::VARIANT_0_0_0 { lVal: v }), - Value::I8(v) => Variant::new(VT_I8, imp::VARIANT_0_0_0 { llVal: v }), - Value::INT(v) => Variant::new(VT_INT, imp::VARIANT_0_0_0 { lVal: v }), - Value::UI1(v) => Variant::new(VT_UI1, imp::VARIANT_0_0_0 { bVal: v }), - Value::UI2(v) => Variant::new(VT_UI2, imp::VARIANT_0_0_0 { uiVal: v }), - Value::UI4(v) => Variant::new(VT_UI4, imp::VARIANT_0_0_0 { ulVal: v }), - Value::UI8(v) => Variant::new(VT_UI8, imp::VARIANT_0_0_0 { ullVal: v }), - Value::UINT(v) => Variant::new(VT_UINT, imp::VARIANT_0_0_0 { uintVal: v }), - Value::R4(v) => Variant::new(VT_R4, imp::VARIANT_0_0_0 { fltVal: v }), - Value::R8(v) => Variant::new(VT_R8, imp::VARIANT_0_0_0 { dblVal: v }), + Value::I1(v) => val_to_variant!(v), // Variant::new(VT_I1, imp::VARIANT_0_0_0 { bVal: v as u8 }), + Value::I2(v) => val_to_variant!(v), // Variant::new(VT_I2, imp::VARIANT_0_0_0 { iVal: v }), + Value::I4(v) => val_to_variant!(v), // Variant::new(VT_I4, imp::VARIANT_0_0_0 { lVal: v }), + Value::I8(v) => val_to_variant!(v), // Variant::new(VT_I8, imp::VARIANT_0_0_0 { llVal: v }), + Value::INT(v) => val_to_variant!(v), // Variant::new(VT_INT, imp::VARIANT_0_0_0 { lVal: v }), + Value::UI1(v) => val_to_variant!(v), // Variant::new(VT_UI1, imp::VARIANT_0_0_0 { bVal: v }), + Value::UI2(v) => val_to_variant!(v), // Variant::new(VT_UI2, imp::VARIANT_0_0_0 { uiVal: v }), + Value::UI4(v) => val_to_variant!(v), // Variant::new(VT_UI4, imp::VARIANT_0_0_0 { ulVal: v }), + Value::UI8(v) => val_to_variant!(v), // Variant::new(VT_UI8, imp::VARIANT_0_0_0 { ullVal: v }), + Value::UINT(v) => val_to_variant!(v), // Variant::new(VT_UINT, imp::VARIANT_0_0_0 { uintVal: v }), + Value::R4(v) => val_to_variant!(v), // Variant::new(VT_R4, imp::VARIANT_0_0_0 { fltVal: v }), + Value::R8(v) => val_to_variant!(v), // Variant::new(VT_R8, imp::VARIANT_0_0_0 { dblVal: v }), Value::CURRENCY(v) => Variant::new(VT_CY, imp::VARIANT_0_0_0 { cyVal: imp::CY { int64: v} }), Value::DATE(v) => Variant::new(VT_DATE, imp::VARIANT_0_0_0 { date: v }), - Value::STRING(v) => { let s = BSTR::from(v); let v = VARIANT::from(s); v.into() }, //Variant::new(VT_BSTR, imp::VARIANT_0_0_0 { bstrVal: v.as_str() as _ }), - Value::UNKNOWN(v) => { let var = VARIANT::from(v); var.into() } //Variant::new(VT_UNKNOWN, imp::VARIANT_0_0_0 { punkVal: ManuallyDrop::new(Some(v)) }), - Value::DISPATCH(v) => Variant::new(VT_DISPATCH, imp::VARIANT_0_0_0 { pdispVal: ManuallyDrop::new(Some(v)) }), + Value::STRING(v) => val_to_variant!(BSTR::from(v)), // { let s = BSTR::from(v); let v = VARIANT::from(s); v.into() }, //Variant::new(VT_BSTR, imp::VARIANT_0_0_0 { bstrVal: v.as_str() as _ }), + Value::UNKNOWN(v) => val_to_variant!(v), // Variant::new(VT_UNKNOWN, imp::VARIANT_0_0_0 { punkVal: ManuallyDrop::new(Some(v)) }), + Value::DISPATCH(v) => val_to_variant!(v), // Variant::new(VT_DISPATCH, imp::VARIANT_0_0_0 { pdispVal: ManuallyDrop::new(Some(v)) }), Value::ERROR(v) => Variant::new(VT_ERROR, imp::VARIANT_0_0_0 { intVal: v.0 }), Value::HRESULT(v) => Variant::new(VT_HRESULT, imp::VARIANT_0_0_0 { intVal: v.0 }), - Value::BOOL(v) => Variant::new(VT_BOOL, imp::VARIANT_0_0_0 { boolVal: v.into() }), - Value::VARIANT(mut v) => Variant::new(VT_VARIANT, imp::VARIANT_0_0_0 { pvarVal: &mut v.value }), - Value::DECIMAL(mut v) => Variant::new(VT_DECIMAL, imp::VARIANT_0_0_0 { pdecVal: &mut v }), - Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, imp::VARIANT_0_0_0 { parray: v.array }), + Value::BOOL(v) => val_to_variant!(v), // Variant::new(VT_BOOL, imp::VARIANT_0_0_0 { boolVal: v.into() }), + Value::VARIANT(mut v) => { + let mut val = imp::VARIANT { + Anonymous: v.value.as_raw().Anonymous + }; + + Variant::new(VT_VARIANT, imp::VARIANT_0_0_0 { pvarVal: &mut val as *mut imp::VARIANT }) + }, + Value::DECIMAL(v) => { + let mut decimal = imp::DECIMAL { + wReserved: v.wReserved, + Anonymous1: imp::DECIMAL_0 { signscale: v.Anonymous1.signscale }, + Hi32: v.Hi32, + Anonymous2: imp::DECIMAL_1 { Lo64: v.Anonymous2.Lo64 } + }; + Variant::new(VT_DECIMAL, imp::VARIANT_0_0_0 { pdecVal: &mut decimal as _ }) + }, + Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, imp::VARIANT_0_0_0 { parray: v.into() }), Value::ArrayBool(v) => vec_to_variant!(v, VT_BOOL), //Variant::new(VT_SAFEARRAY, VARIANT_0_0_0 { parray: v.array }), Value::ArrayR8(v) => vec_to_variant!(v, VT_R8), Value::ArrayI2(v) => vec_to_variant!(v, VT_I2), @@ -541,16 +565,20 @@ impl TryInto for &Variant { }; Ok(Value::DATE(val)) } else if vt == VT_BSTR || vt == VT_LPSTR { + // let val = unsafe { + // self.get_data().bstrVal.to_string() + // }; + // Ok(Value::STRING(val)) let val = unsafe { - self.get_data().bstrVal.to_string() + BSTR::from_raw(self.get_data().bstrVal) }; - Ok(Value::STRING(val)) + Ok(Value::STRING(val.to_string())) } else if vt == VT_LPSTR { let val = unsafe { if self.get_data().pcVal.is_null() { String::from("") } else { - let lpstr = self.get_data().pcVal.0; + let lpstr = self.get_data().pcVal; let mut end = lpstr; while *end != 0 { end = end.add(1); @@ -561,21 +589,32 @@ impl TryInto for &Variant { Ok(Value::STRING(val)) } else if vt == VT_DISPATCH { - let val = unsafe { - if let Some(ref disp) = *self.get_data().ppdispVal { - Value::DISPATCH(disp.clone()) - } else { - Value::NULL - } + // let val = unsafe { + // if let Some(ref disp) = *self.get_data().ppdispVal { + // Value::DISPATCH(disp.clone()) + // } else { + // Value::NULL + // } + // }; + let val = if self.get_data().ppdispVal.is_null() { + Value::NULL + } else { + Value::DISPATCH(IDispatch::try_from(&self.value)?) }; Ok(val) } else if vt == VT_UNKNOWN { - let val = unsafe { - if let Some(ref unkown) = *self.get_data().ppunkVal { - Value::UNKNOWN(unkown.clone()) - } else { - Value::NULL - } + // let val = unsafe { + // if let Some(ref unkown) = *self.get_data().ppunkVal { + // Value::UNKNOWN(unkown.clone()) + // } else { + // Value::NULL + // } + // }; + // Ok(val) + let val = if self.get_data().ppunkVal.is_null() { + Value::NULL + } else { + Value::UNKNOWN(IUnknown::try_from(&self.value)?) }; Ok(val) } else if vt == VT_ERROR { @@ -590,24 +629,39 @@ impl TryInto for &Variant { Ok(Value::HRESULT(HRESULT(val))) } else if vt == VT_BOOL { let val = unsafe { - self.get_data().__OBSOLETE__VARIANT_BOOL.into() // != 0 + self.get_data().__OBSOLETE__VARIANT_BOOL != 0 }; Ok(Value::BOOL(val)) } else if vt == VT_VARIANT { - let val = unsafe { - (*self.get_data().pvarVal).clone() - }; + // let val = unsafe { + // (*self.get_data().pvarVal).clone() + // }; + let val = VARIANT::default(); + unsafe { + val.as_raw().Anonymous = (*self.get_data().pvarVal).Anonymous; + } + Ok(Value::VARIANT(val.into())) } else if vt == VT_DECIMAL { + // let val = unsafe { + // (*self.get_data().pdecVal).clone() + // }; + let d = self.get_data().pdecVal; let val = unsafe { - (*self.get_data().pdecVal).clone() + DECIMAL { + wReserved: (*d).wReserved, + Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: (*d).Anonymous1.signscale }, + Hi32: (*d).Hi32, + Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: (*d).Anonymous2.Lo64 } + } }; + Ok(Value::DECIMAL(val)) } else if vt == VT_SAFEARRAY { let arr = unsafe { self.get_data().parray.clone() }; - Ok(Value::SAFEARRAY(SafeArray::new(arr, false))) + Ok(Value::SAFEARRAY(SafeArray::from(arr))) } else { Err(Error::new(ERR_TYPE, "unknown variant type")) } @@ -635,7 +689,7 @@ impl TryInto for &Variant { // let vt = self.vt(); let val = unsafe { match self.get_type() { - VT_BOOL => self.get_data().boolVal, + VT_BOOL => VARIANT_BOOL(self.get_data().boolVal), VT_CY => VarBoolFromCy(self.get_data().cyVal)?, VT_DATE => VarBoolFromDate(self.get_data().date)?, VT_DECIMAL => VarBoolFromDec(self.get_data().pdecVal)?, @@ -1444,6 +1498,50 @@ impl SafeArray { } } +impl From<*mut imp::SAFEARRAY> for SafeArray { + fn from(value: *mut imp::SAFEARRAY) -> Self { + let mut array = unsafe { + SAFEARRAY { + cDims: (*value).cDims, + fFeatures: ADVANCED_FEATURE_FLAGS((*value).fFeatures), + cbElements: (*value).cbElements, + cLocks: (*value).cLocks, + pvData: (*value).pvData, + rgsabound: [SAFEARRAYBOUND { + cElements: (*value).rgsabound[0].cElements, + lLbound: (*value).rgsabound[0].lLbound + }] + } + }; + + Self { + array: &mut array as *mut SAFEARRAY, + owned: true + } + } +} + +impl Into<*mut imp::SAFEARRAY> for SafeArray { + fn into(mut self) -> *mut imp::SAFEARRAY { + let value = self.array; + let mut array = unsafe { + imp::SAFEARRAY { + cDims: (*value).cDims, + fFeatures: (*value).fFeatures.0, + cbElements: (*value).cbElements, + cLocks: (*value).cLocks, + pvData: (*value).pvData, + rgsabound: [imp::SAFEARRAYBOUND { + cElements: (*value).rgsabound[0].cElements, + lLbound: (*value).rgsabound[0].lLbound + }] + } + }; + self.owned = false; + &mut array as *mut imp::SAFEARRAY + } +} + impl From<*mut SAFEARRAY> for SafeArray { fn from(array: *mut SAFEARRAY) -> Self { Self { From 018452e7d6b38d8ee51ec1d8e23e5b6f690b9ea3 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Sun, 10 Mar 2024 21:34:59 +0800 Subject: [PATCH 11/15] refactor variants --- crates/uiautomation/Cargo.toml | 3 +- crates/uiautomation/src/variants.rs | 80 ++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/crates/uiautomation/Cargo.toml b/crates/uiautomation/Cargo.toml index 10ef796..b7e88dc 100644 --- a/crates/uiautomation/Cargo.toml +++ b/crates/uiautomation/Cargo.toml @@ -34,6 +34,5 @@ features = [ "Win32_System_Threading", "Win32_Security", "Win32_UI_Shell_PropertiesSystem", - "UI_UIAutomation", - # "implement" + "UI_UIAutomation" ] \ No newline at end of file diff --git a/crates/uiautomation/src/variants.rs b/crates/uiautomation/src/variants.rs index cc218d3..c32d772 100644 --- a/crates/uiautomation/src/variants.rs +++ b/crates/uiautomation/src/variants.rs @@ -392,6 +392,42 @@ macro_rules! vec_to_variant { }; } +macro_rules! to_cy_imp { + ($cy: expr) => { + imp::CY { int64: $cy.int64 } + }; +} + +macro_rules! from_cy_imp { + ($cy: expr) => { + CY { int64: $cy.int64 } + }; +} + +macro_rules! from_decimal_imp { + ($d: expr) => { + unsafe { + DECIMAL { + wReserved: $d.wReserved, + Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: $d.Anonymous1.signscale }, + Hi32: $d.Hi32, + Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: $d.Anonymous2.Lo64 } + } + } + }; +} + +macro_rules! to_decimal_imp { + ($d: expr) => { + imp::DECIMAL { + wReserved: $d.wReserved, + Anonymous1: imp::DECIMAL_0 { signscale: $d.Anonymous1.signscale }, + Hi32: $d.Hi32, + Anonymous2: imp::DECIMAL_1 { Lo64: $d.Anonymous2.Lo64 } + } + }; +} + impl From for Variant { fn from(value: Value) -> Self { match value { @@ -426,12 +462,13 @@ impl From for Variant { Variant::new(VT_VARIANT, imp::VARIANT_0_0_0 { pvarVal: &mut val as *mut imp::VARIANT }) }, Value::DECIMAL(v) => { - let mut decimal = imp::DECIMAL { - wReserved: v.wReserved, - Anonymous1: imp::DECIMAL_0 { signscale: v.Anonymous1.signscale }, - Hi32: v.Hi32, - Anonymous2: imp::DECIMAL_1 { Lo64: v.Anonymous2.Lo64 } - }; + // let mut decimal = imp::DECIMAL { + // wReserved: v.wReserved, + // Anonymous1: imp::DECIMAL_0 { signscale: v.Anonymous1.signscale }, + // Hi32: v.Hi32, + // Anonymous2: imp::DECIMAL_1 { Lo64: v.Anonymous2.Lo64 } + // }; + let mut decimal = to_decimal_imp!(v); Variant::new(VT_DECIMAL, imp::VARIANT_0_0_0 { pdecVal: &mut decimal as _ }) }, Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, imp::VARIANT_0_0_0 { parray: v.into() }), @@ -647,14 +684,15 @@ impl TryInto for &Variant { // (*self.get_data().pdecVal).clone() // }; let d = self.get_data().pdecVal; - let val = unsafe { - DECIMAL { - wReserved: (*d).wReserved, - Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: (*d).Anonymous1.signscale }, - Hi32: (*d).Hi32, - Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: (*d).Anonymous2.Lo64 } - } - }; + // let val = unsafe { + // DECIMAL { + // wReserved: (*d).wReserved, + // Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: (*d).Anonymous1.signscale }, + // Hi32: (*d).Hi32, + // Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: (*d).Anonymous2.Lo64 } + // } + // }; + let val = from_decimal_imp!(*d); Ok(Value::DECIMAL(val)) } else if vt == VT_SAFEARRAY { @@ -690,9 +728,13 @@ impl TryInto for &Variant { let val = unsafe { match self.get_type() { VT_BOOL => VARIANT_BOOL(self.get_data().boolVal), - VT_CY => VarBoolFromCy(self.get_data().cyVal)?, + VT_CY => VarBoolFromCy(from_cy_imp!(self.get_data().cyVal))?, VT_DATE => VarBoolFromDate(self.get_data().date)?, - VT_DECIMAL => VarBoolFromDec(self.get_data().pdecVal)?, + VT_DECIMAL => { // VarBoolFromDec(self.get_data().pdecVal)?, + let d = self.get_data().pdecVal; + let d = from_decimal_imp!(*d); + VarBoolFromDec(&d)? + }, VT_I1 => VarBoolFromI1(self.get_data().cVal)?, VT_I2 => VarBoolFromI2(self.get_data().iVal)?, VT_I4 | VT_INT => VarBoolFromI4(self.get_data().lVal)?, @@ -708,7 +750,7 @@ impl TryInto for &Variant { VT_UI2 => VarBoolFromUI2(self.get_data().uiVal)?, VT_UI4 | VT_UINT => VarBoolFromUI4(self.get_data().ulVal)?, VT_UI8 => VarBoolFromUI8(self.get_data().ullVal)?, - VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { + VT_DISPATCH => if let Ok(ref disp) = IDispatch::try_from(&self.value) { //if let Some(ref disp) = *self.get_data().pdispVal { VarBoolFromDisp(disp, 0)? } else { false.into() @@ -756,8 +798,8 @@ impl TryInto for &Variant { // let vt = self.get_type(); let str: BSTR = unsafe { match self.get_type() { - VT_BOOL => VarBstrFromBool(self.get_data().boolVal, 0, 0)?, - VT_CY => VarBstrFromCy(self.get_data().cyVal, 0, 0)?, + VT_BOOL => VarBstrFromBool(VARIANT_BOOL(self.get_data().boolVal), 0, 0)?, + VT_CY => VarBstrFromCy(from_cy_imp!(self.get_data().cyVal), 0, 0)?, VT_DATE => VarBstrFromDate(self.get_data().date, 0, 0)?, VT_DECIMAL => VarBstrFromDec(self.get_data().pdecVal, 0, 0)?, VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { From a5a472259eb1e464d3a6e86d82e0794933260ded Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Wed, 13 Mar 2024 21:15:01 +0800 Subject: [PATCH 12/15] update variants --- crates/uiautomation/src/variants.rs | 216 +++++++++++++++------------- 1 file changed, 116 insertions(+), 100 deletions(-) diff --git a/crates/uiautomation/src/variants.rs b/crates/uiautomation/src/variants.rs index c32d772..ef46b81 100644 --- a/crates/uiautomation/src/variants.rs +++ b/crates/uiautomation/src/variants.rs @@ -1,6 +1,4 @@ -use std::ffi::c_void; use std::fmt::Display; -use std::mem::ManuallyDrop; use std::ptr::null_mut; use windows::core::VARIANT; @@ -183,6 +181,27 @@ impl Variant { &var.Anonymous.Anonymous.Anonymous } + fn as_bool(&self) -> VARIANT_BOOL { + VARIANT_BOOL(self.get_data().boolVal) + } + + fn as_decimal(&self) -> DECIMAL { + let d = self.get_data().pdecVal; + + unsafe { + DECIMAL { + wReserved: (*d).wReserved, + Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: (*d).Anonymous1.signscale }, + Hi32: (*d).Hi32, + Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: (*d).Anonymous2.Lo64 } + } + } + } + + fn as_currency(&self) -> CY { + CY { int64: self.get_data().cyVal.int64 } + } + /// Try to get value. pub fn get_value(&self) -> Result { self.try_into() @@ -392,30 +411,30 @@ macro_rules! vec_to_variant { }; } -macro_rules! to_cy_imp { - ($cy: expr) => { - imp::CY { int64: $cy.int64 } - }; -} - -macro_rules! from_cy_imp { - ($cy: expr) => { - CY { int64: $cy.int64 } - }; -} - -macro_rules! from_decimal_imp { - ($d: expr) => { - unsafe { - DECIMAL { - wReserved: $d.wReserved, - Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: $d.Anonymous1.signscale }, - Hi32: $d.Hi32, - Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: $d.Anonymous2.Lo64 } - } - } - }; -} +// macro_rules! to_cy_imp { +// ($cy: expr) => { +// imp::CY { int64: $cy.int64 } +// }; +// } + +// macro_rules! from_cy_imp { +// ($cy: expr) => { +// CY { int64: $cy.int64 } +// }; +// } + +// macro_rules! from_decimal_imp { +// ($d: expr) => { +// unsafe { +// DECIMAL { +// wReserved: $d.wReserved, +// Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: $d.Anonymous1.signscale }, +// Hi32: $d.Hi32, +// Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: $d.Anonymous2.Lo64 } +// } +// } +// }; +// } macro_rules! to_decimal_imp { ($d: expr) => { @@ -431,29 +450,29 @@ macro_rules! to_decimal_imp { impl From for Variant { fn from(value: Value) -> Self { match value { - Value::EMPTY => Variant::new_null(VT_EMPTY), - Value::NULL => Variant::new_null(VT_NULL), - Value::VOID => Variant::new_null(VT_VOID), - Value::I1(v) => val_to_variant!(v), // Variant::new(VT_I1, imp::VARIANT_0_0_0 { bVal: v as u8 }), - Value::I2(v) => val_to_variant!(v), // Variant::new(VT_I2, imp::VARIANT_0_0_0 { iVal: v }), - Value::I4(v) => val_to_variant!(v), // Variant::new(VT_I4, imp::VARIANT_0_0_0 { lVal: v }), - Value::I8(v) => val_to_variant!(v), // Variant::new(VT_I8, imp::VARIANT_0_0_0 { llVal: v }), - Value::INT(v) => val_to_variant!(v), // Variant::new(VT_INT, imp::VARIANT_0_0_0 { lVal: v }), - Value::UI1(v) => val_to_variant!(v), // Variant::new(VT_UI1, imp::VARIANT_0_0_0 { bVal: v }), - Value::UI2(v) => val_to_variant!(v), // Variant::new(VT_UI2, imp::VARIANT_0_0_0 { uiVal: v }), - Value::UI4(v) => val_to_variant!(v), // Variant::new(VT_UI4, imp::VARIANT_0_0_0 { ulVal: v }), - Value::UI8(v) => val_to_variant!(v), // Variant::new(VT_UI8, imp::VARIANT_0_0_0 { ullVal: v }), - Value::UINT(v) => val_to_variant!(v), // Variant::new(VT_UINT, imp::VARIANT_0_0_0 { uintVal: v }), - Value::R4(v) => val_to_variant!(v), // Variant::new(VT_R4, imp::VARIANT_0_0_0 { fltVal: v }), - Value::R8(v) => val_to_variant!(v), // Variant::new(VT_R8, imp::VARIANT_0_0_0 { dblVal: v }), - Value::CURRENCY(v) => Variant::new(VT_CY, imp::VARIANT_0_0_0 { cyVal: imp::CY { int64: v} }), - Value::DATE(v) => Variant::new(VT_DATE, imp::VARIANT_0_0_0 { date: v }), - Value::STRING(v) => val_to_variant!(BSTR::from(v)), // { let s = BSTR::from(v); let v = VARIANT::from(s); v.into() }, //Variant::new(VT_BSTR, imp::VARIANT_0_0_0 { bstrVal: v.as_str() as _ }), - Value::UNKNOWN(v) => val_to_variant!(v), // Variant::new(VT_UNKNOWN, imp::VARIANT_0_0_0 { punkVal: ManuallyDrop::new(Some(v)) }), - Value::DISPATCH(v) => val_to_variant!(v), // Variant::new(VT_DISPATCH, imp::VARIANT_0_0_0 { pdispVal: ManuallyDrop::new(Some(v)) }), - Value::ERROR(v) => Variant::new(VT_ERROR, imp::VARIANT_0_0_0 { intVal: v.0 }), - Value::HRESULT(v) => Variant::new(VT_HRESULT, imp::VARIANT_0_0_0 { intVal: v.0 }), - Value::BOOL(v) => val_to_variant!(v), // Variant::new(VT_BOOL, imp::VARIANT_0_0_0 { boolVal: v.into() }), + Value::EMPTY => Variant::new_null(VT_EMPTY), + Value::NULL => Variant::new_null(VT_NULL), + Value::VOID => Variant::new_null(VT_VOID), + Value::I1(v) => val_to_variant!(v), // Variant::new(VT_I1, imp::VARIANT_0_0_0 { bVal: v as u8 }), + Value::I2(v) => val_to_variant!(v), // Variant::new(VT_I2, imp::VARIANT_0_0_0 { iVal: v }), + Value::I4(v) => val_to_variant!(v), // Variant::new(VT_I4, imp::VARIANT_0_0_0 { lVal: v }), + Value::I8(v) => val_to_variant!(v), // Variant::new(VT_I8, imp::VARIANT_0_0_0 { llVal: v }), + Value::INT(v) => val_to_variant!(v), // Variant::new(VT_INT, imp::VARIANT_0_0_0 { lVal: v }), + Value::UI1(v) => val_to_variant!(v), // Variant::new(VT_UI1, imp::VARIANT_0_0_0 { bVal: v }), + Value::UI2(v) => val_to_variant!(v), // Variant::new(VT_UI2, imp::VARIANT_0_0_0 { uiVal: v }), + Value::UI4(v) => val_to_variant!(v), // Variant::new(VT_UI4, imp::VARIANT_0_0_0 { ulVal: v }), + Value::UI8(v) => val_to_variant!(v), // Variant::new(VT_UI8, imp::VARIANT_0_0_0 { ullVal: v }), + Value::UINT(v) => val_to_variant!(v), // Variant::new(VT_UINT, imp::VARIANT_0_0_0 { uintVal: v }), + Value::R4(v) => val_to_variant!(v), // Variant::new(VT_R4, imp::VARIANT_0_0_0 { fltVal: v }), + Value::R8(v) => val_to_variant!(v), // Variant::new(VT_R8, imp::VARIANT_0_0_0 { dblVal: v }), + Value::CURRENCY(v) => Variant::new(VT_CY, imp::VARIANT_0_0_0 { cyVal: imp::CY { int64: v} }), + Value::DATE(v) => Variant::new(VT_DATE, imp::VARIANT_0_0_0 { date: v }), + Value::STRING(v) => val_to_variant!(BSTR::from(v)), // { let s = BSTR::from(v); let v = VARIANT::from(s); v.into() }, //Variant::new(VT_BSTR, imp::VARIANT_0_0_0 { bstrVal: v.as_str() as _ }), + Value::UNKNOWN(v) => val_to_variant!(v), // Variant::new(VT_UNKNOWN, imp::VARIANT_0_0_0 { punkVal: ManuallyDrop::new(Some(v)) }), + Value::DISPATCH(v) => val_to_variant!(v), // Variant::new(VT_DISPATCH, imp::VARIANT_0_0_0 { pdispVal: ManuallyDrop::new(Some(v)) }), + Value::ERROR(v) => Variant::new(VT_ERROR, imp::VARIANT_0_0_0 { intVal: v.0 }), + Value::HRESULT(v) => Variant::new(VT_HRESULT, imp::VARIANT_0_0_0 { intVal: v.0 }), + Value::BOOL(v) => val_to_variant!(v), // Variant::new(VT_BOOL, imp::VARIANT_0_0_0 { boolVal: v.into() }), Value::VARIANT(mut v) => { let mut val = imp::VARIANT { Anonymous: v.value.as_raw().Anonymous @@ -473,13 +492,13 @@ impl From for Variant { }, Value::SAFEARRAY(v) => Variant::new(VT_SAFEARRAY, imp::VARIANT_0_0_0 { parray: v.into() }), Value::ArrayBool(v) => vec_to_variant!(v, VT_BOOL), //Variant::new(VT_SAFEARRAY, VARIANT_0_0_0 { parray: v.array }), - Value::ArrayR8(v) => vec_to_variant!(v, VT_R8), - Value::ArrayI2(v) => vec_to_variant!(v, VT_I2), - Value::ArrayI4(v) => vec_to_variant!(v, VT_I4), - Value::ArrayI8(v) => vec_to_variant!(v, VT_I8), - Value::ArrayUI2(v) => vec_to_variant!(v, VT_UI2), - Value::ArrayUI4(v) => vec_to_variant!(v, VT_UI4), - Value::ArrayUI8(v) => vec_to_variant!(v, VT_UI8), + Value::ArrayR8(v) => vec_to_variant!(v, VT_R8), + Value::ArrayI2(v) => vec_to_variant!(v, VT_I2), + Value::ArrayI4(v) => vec_to_variant!(v, VT_I4), + Value::ArrayI8(v) => vec_to_variant!(v, VT_I8), + Value::ArrayUI2(v) => vec_to_variant!(v, VT_UI2), + Value::ArrayUI4(v) => vec_to_variant!(v, VT_UI4), + Value::ArrayUI8(v) => vec_to_variant!(v, VT_UI8), Value::ArrayString(v) => vec_to_variant!(v, VT_BSTR), } } @@ -692,7 +711,7 @@ impl TryInto for &Variant { // Anonymous2: windows::Win32::Foundation::DECIMAL_1 { Lo64: (*d).Anonymous2.Lo64 } // } // }; - let val = from_decimal_imp!(*d); + let val = self.as_decimal(); //from_decimal_imp!(*d); Ok(Value::DECIMAL(val)) } else if vt == VT_SAFEARRAY { @@ -727,14 +746,10 @@ impl TryInto for &Variant { // let vt = self.vt(); let val = unsafe { match self.get_type() { - VT_BOOL => VARIANT_BOOL(self.get_data().boolVal), - VT_CY => VarBoolFromCy(from_cy_imp!(self.get_data().cyVal))?, + VT_BOOL => self.as_bool(), //VARIANT_BOOL(self.get_data().boolVal), + VT_CY => VarBoolFromCy(self.as_currency())?, //(from_cy_imp!(self.get_data().cyVal))?, VT_DATE => VarBoolFromDate(self.get_data().date)?, - VT_DECIMAL => { // VarBoolFromDec(self.get_data().pdecVal)?, - let d = self.get_data().pdecVal; - let d = from_decimal_imp!(*d); - VarBoolFromDec(&d)? - }, + VT_DECIMAL => VarBoolFromDec(&self.as_decimal())?, // VarBoolFromDec(self.get_data().pdecVal)?, VT_I1 => VarBoolFromI1(self.get_data().cVal)?, VT_I2 => VarBoolFromI2(self.get_data().iVal)?, VT_I4 | VT_INT => VarBoolFromI4(self.get_data().lVal)?, @@ -798,11 +813,11 @@ impl TryInto for &Variant { // let vt = self.get_type(); let str: BSTR = unsafe { match self.get_type() { - VT_BOOL => VarBstrFromBool(VARIANT_BOOL(self.get_data().boolVal), 0, 0)?, - VT_CY => VarBstrFromCy(from_cy_imp!(self.get_data().cyVal), 0, 0)?, + VT_BOOL => VarBstrFromBool(self.as_bool(), 0, 0)?, //(VARIANT_BOOL(self.get_data().boolVal), 0, 0)?, + VT_CY => VarBstrFromCy(self.as_currency(), 0, 0)?, //(from_cy_imp!(self.get_data().cyVal), 0, 0)?, VT_DATE => VarBstrFromDate(self.get_data().date, 0, 0)?, - VT_DECIMAL => VarBstrFromDec(self.get_data().pdecVal, 0, 0)?, - VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { + VT_DECIMAL => VarBstrFromDec(&self.as_decimal(), 0, 0)?, //(&from_decimal_imp!(*self.get_data().pdecVal), 0, 0)?, + VT_DISPATCH => if let Ok(ref disp) = IDispatch::try_from(&self.value) { //if let Some(ref disp) = *self.get_data().pdispVal { VarBstrFromDisp(disp, 0, 0)? } else { BSTR::default() @@ -872,7 +887,8 @@ macro_rules! variant_as_type { macro_rules! dispatch_as_type { ($self:ident, $f:ident) => { { - if let Some(ref disp) = *$self.get_data().pdispVal { + //if let Some(ref disp) = *$self.get_data().pdispVal { + if let Ok(ref disp) = IDispatch::try_from(&$self.value) { $f(disp, 0)? } else { 0 as _ @@ -892,11 +908,11 @@ impl TryInto for &Variant { // VarI1FromBool(self.get_data().iVal, pc)?; // (*pc.0) as i8 // } - VT_BOOL => variant_as_i1!(VarI1FromBool, self.get_data().boolVal), - VT_CY => variant_as_i1!(VarI1FromCy, self.get_data().cyVal), + VT_BOOL => variant_as_i1!(VarI1FromBool, self.as_bool()), //self.get_data().boolVal), + VT_CY => variant_as_i1!(VarI1FromCy, self.as_currency()), //self.get_data().cyVal), VT_DATE => variant_as_i1!(VarI1FromDate, self.get_data().date), - VT_DECIMAL => variant_as_i1!(VarI1FromDec, self.get_data().pdecVal), - VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { + VT_DECIMAL => variant_as_i1!(VarI1FromDec, &self.as_decimal()), // self.get_data().pdecVal), + VT_DISPATCH => if let Ok(ref disp) = IDispatch::try_from(&self.value) { // if let Some(ref disp) = *self.get_data().pdispVal { let pc = PSTR::null(); VarI1FromDisp(disp, 0, pc)?; *pc.0 as i8 @@ -948,15 +964,15 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: i16 = unsafe { match self.get_type() { - VT_BOOL => VarI2FromBool(self.get_data().boolVal)?, - VT_CY => variant_as_type!(VarI2FromCy, i16, self.get_data().cyVal), + VT_BOOL => VarI2FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => variant_as_type!(VarI2FromCy, i16, self.as_currency()), // self.get_data().cyVal), // VT_CY => { // let mut v: [i16; 1] = [0]; // VarI2FromCy(self.get_data().cyVal, v.as_mut_ptr())?; // v[0] // }, VT_DATE => VarI2FromDate(self.get_data().date)?, - VT_DECIMAL => VarI2FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarI2FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarI2FromDisp), // VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { // VarI2FromDisp(disp, 0)? @@ -1002,10 +1018,10 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: i32 = unsafe { match self.get_type() { - VT_BOOL => VarI4FromBool(self.get_data().boolVal)?, - VT_CY => VarI4FromCy(self.get_data().cyVal)?, + VT_BOOL => VarI4FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => VarI4FromCy(self.as_currency())?, //(self.get_data().cyVal)?, VT_DATE => VarI4FromDate(self.get_data().date)?, - VT_DECIMAL => VarI4FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarI4FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarI4FromDisp), // VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { // VarI4FromDisp(disp, 0)? @@ -1051,10 +1067,10 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: i64 = unsafe { match self.get_type() { - VT_BOOL => VarI8FromBool(self.get_data().boolVal)?, - VT_CY => VarI8FromCy(self.get_data().cyVal)?, + VT_BOOL => VarI8FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => VarI8FromCy(self.as_currency())?, //(self.get_data().cyVal)?, VT_DATE => VarI8FromDate(self.get_data().date)?, - VT_DECIMAL => VarI8FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarI8FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarI8FromDisp), // VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { // VarI8FromDisp(disp, 0)? @@ -1100,15 +1116,15 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: f32 = unsafe { match self.get_type() { - VT_BOOL => VarR4FromBool(self.get_data().boolVal)?, - VT_CY => variant_as_type!(VarR4FromCy, f32, self.get_data().cyVal), + VT_BOOL => VarR4FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => variant_as_type!(VarR4FromCy, f32, self.as_currency()), //self.get_data().cyVal), // VT_CY => { // let mut v: [f32; 1] = [f32::default()]; // VarR4FromCy(self.get_data().cyVal, v.as_mut_ptr())?; // v[0] // }, VT_DATE => VarR4FromDate(self.get_data().date)?, - VT_DECIMAL => VarR4FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarR4FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarR4FromDisp), // VT_DISPATCH => if let Some(ref disp) = *self.get_data().pdispVal { // VarR4FromDisp(disp, 0)? @@ -1154,10 +1170,10 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: f64 = unsafe { match self.get_type() { - VT_BOOL => VarR8FromBool(self.get_data().boolVal)?, - VT_CY => variant_as_type!(VarR8FromCy, f64, self.get_data().cyVal), + VT_BOOL => VarR8FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => variant_as_type!(VarR8FromCy, f64, self.as_currency()), //self.get_data().cyVal), VT_DATE => VarR8FromDate(self.get_data().date)?, - VT_DECIMAL => VarR8FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarR8FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarR8FromDisp), VT_I1 => variant_as_type!(VarR8FromI1, f64, self.get_data().cVal), VT_I2 => VarR8FromI2(self.get_data().iVal)?, @@ -1198,10 +1214,10 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: u8 = unsafe { match self.get_type() { - VT_BOOL => VarUI1FromBool(self.get_data().boolVal)?, - VT_CY => VarUI1FromCy(self.get_data().cyVal)?, + VT_BOOL => VarUI1FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => VarUI1FromCy(self.as_currency())?, //(self.get_data().cyVal)?, VT_DATE => VarUI1FromDate(self.get_data().date)?, - VT_DECIMAL => VarUI1FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarUI1FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarUI1FromDisp), VT_I1 => VarUI1FromI1(self.get_data().cVal)?, VT_I2 => VarUI1FromI2(self.get_data().iVal)?, @@ -1242,10 +1258,10 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: u16 = unsafe { match self.get_type() { - VT_BOOL => VarUI2FromBool(self.get_data().boolVal)?, - VT_CY => VarUI2FromCy(self.get_data().cyVal)?, + VT_BOOL => VarUI2FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => VarUI2FromCy(self.as_currency())?, //(self.get_data().cyVal)?, VT_DATE => VarUI2FromDate(self.get_data().date)?, - VT_DECIMAL => VarUI2FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarUI2FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarUI2FromDisp), VT_I1 => VarUI2FromI1(self.get_data().cVal)?, VT_I2 => VarUI2FromI2(self.get_data().iVal)?, @@ -1286,10 +1302,10 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: u32 = unsafe { match self.get_type() { - VT_BOOL => VarUI4FromBool(self.get_data().boolVal)?, - VT_CY => VarUI4FromCy(self.get_data().cyVal)?, + VT_BOOL => VarUI4FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => VarUI4FromCy(self.as_currency())?, //(self.get_data().cyVal)?, VT_DATE => VarUI4FromDate(self.get_data().date)?, - VT_DECIMAL => VarUI4FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarUI4FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarUI4FromDisp), VT_I1 => VarUI4FromI1(self.get_data().cVal)?, VT_I2 => VarUI4FromI2(self.get_data().iVal)?, @@ -1330,10 +1346,10 @@ impl TryInto for &Variant { fn try_into(self) -> Result { let val: u64 = unsafe { match self.get_type() { - VT_BOOL => VarUI8FromBool(self.get_data().boolVal)?, - VT_CY => VarUI8FromCy(self.get_data().cyVal)?, + VT_BOOL => VarUI8FromBool(self.as_bool())?, //(self.get_data().boolVal)?, + VT_CY => VarUI8FromCy(self.as_currency())?, //(self.get_data().cyVal)?, VT_DATE => VarUI8FromDate(self.get_data().date)?, - VT_DECIMAL => VarUI8FromDec(self.get_data().pdecVal)?, + VT_DECIMAL => VarUI8FromDec(&self.as_decimal())?, //(self.get_data().pdecVal)?, VT_DISPATCH => dispatch_as_type!(self, VarUI8FromDisp), VT_I1 => VarUI8FromI1(self.get_data().cVal)?, VT_I2 => VarUI8FromI2(self.get_data().iVal)?, From 83a9079716cc69cc52efb18f1c350bba9799aa9f Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Thu, 14 Mar 2024 21:01:08 +0800 Subject: [PATCH 13/15] update to windows 0.54 --- crates/uiautomation/src/controls.rs | 84 ++--- crates/uiautomation/src/core.rs | 30 +- crates/uiautomation/src/errors.rs | 12 +- crates/uiautomation/src/patterns.rs | 132 +++---- crates/uiautomation/src/types.rs | 526 ++++++++++++++-------------- crates/uiautomation/src/variants.rs | 8 +- 6 files changed, 405 insertions(+), 387 deletions(-) diff --git a/crates/uiautomation/src/controls.rs b/crates/uiautomation/src/controls.rs index 48cdeaa..af8e7e4 100644 --- a/crates/uiautomation/src/controls.rs +++ b/crates/uiautomation/src/controls.rs @@ -37,91 +37,91 @@ macro_rules! as_control_ref { /// Defines enum for `windows::Win32::UI::Accessibility::UIA_CONTROLTYPE_ID`. /// /// Contains the named constants used to identify Microsoft UI Automation control types. -#[repr(u32)] +#[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)] pub enum ControlType { /// Identifies the Button control type. - Button = 50000u32, + Button = 50000i32, /// Identifies the Calendar control type. - Calendar = 50001u32, + Calendar = 50001i32, /// Identifies the CheckBox control type. - CheckBox = 50002u32, + CheckBox = 50002i32, /// Identifies the ComboBox control type. - ComboBox = 50003u32, + ComboBox = 50003i32, /// Identifies the Edit control type. - Edit = 50004u32, + Edit = 50004i32, /// Identifies the Hyperlink control type. - Hyperlink = 50005u32, + Hyperlink = 50005i32, /// Identifies the Image control type. - Image = 50006u32, + Image = 50006i32, /// Identifies the ListItem control type. - ListItem = 50007u32, + ListItem = 50007i32, /// Identifies the List control type. - List = 50008u32, + List = 50008i32, /// Identifies the Menu control type. - Menu = 50009u32, + Menu = 50009i32, /// Identifies the MenuBar control type. - MenuBar = 50010u32, + MenuBar = 50010i32, /// Identifies the MenuItem control type. - MenuItem = 50011u32, + MenuItem = 50011i32, /// Identifies the ProgressBar control type. - ProgressBar = 50012u32, + ProgressBar = 50012i32, /// Identifies the RadioButton control type. - RadioButton = 50013u32, + RadioButton = 50013i32, /// Identifies the ScrollBar control type. - ScrollBar = 50014u32, + ScrollBar = 50014i32, /// Identifies the Slider control type. - Slider = 50015u32, + Slider = 50015i32, /// Identifies the Spinner control type. - Spinner = 50016u32, + Spinner = 50016i32, /// Identifies the StatusBar control type. - StatusBar = 50017u32, + StatusBar = 50017i32, /// Identifies the Tab control type. - Tab = 50018u32, + Tab = 50018i32, /// Identifies the TabItem control type. - TabItem = 50019u32, + TabItem = 50019i32, /// Identifies the Text control type. - Text = 50020u32, + Text = 50020i32, /// Identifies the ToolBar control type. - ToolBar = 50021u32, + ToolBar = 50021i32, /// Identifies the ToolTip control type. - ToolTip = 50022u32, + ToolTip = 50022i32, /// Identifies the Tree control type. - Tree = 50023u32, + Tree = 50023i32, /// Identifies the TreeItem control type. - TreeItem = 50024u32, + TreeItem = 50024i32, /// Identifies the Custom control type. For more information, see Custom Properties, Events, and Control Patterns. - Custom = 50025u32, + Custom = 50025i32, /// Identifies the Group control type. - Group = 50026u32, + Group = 50026i32, /// Identifies the Thumb control type. - Thumb = 50027u32, + Thumb = 50027i32, /// Identifies the DataGrid control type. - DataGrid = 50028u32, + DataGrid = 50028i32, /// Identifies the DataItem control type. - DataItem = 50029u32, + DataItem = 50029i32, /// Identifies the Document control type. - Document = 50030u32, + Document = 50030i32, /// Identifies the SplitButton control type. - SplitButton = 50031u32, + SplitButton = 50031i32, /// Identifies the Window control type. - Window = 50032u32, + Window = 50032i32, /// Identifies the Pane control type. - Pane = 50033u32, + Pane = 50033i32, /// Identifies the Header control type. - Header = 50034u32, + Header = 50034i32, /// Identifies the HeaderItem control type. - HeaderItem = 50035u32, + HeaderItem = 50035i32, /// Identifies the Table control type. - Table = 50036u32, + Table = 50036i32, /// Identifies the TitleBar control type. - TitleBar = 50037u32, + TitleBar = 50037i32, /// Identifies the Separator control type. - Separator = 50038u32, + Separator = 50038i32, /// Identifies the SemanticZoom control type. Supported starting with Windows 8. - SemanticZoom = 50039u32, + SemanticZoom = 50039i32, /// Identifies the AppBar control type. Supported starting with Windows 8.1. - AppBar = 50040u32 + AppBar = 50040i32 } impl From for ControlType { diff --git a/crates/uiautomation/src/core.rs b/crates/uiautomation/src/core.rs index 77840fb..f4b52f1 100644 --- a/crates/uiautomation/src/core.rs +++ b/crates/uiautomation/src/core.rs @@ -4,12 +4,10 @@ use std::thread::sleep; use std::time::Duration; use chrono::Local; -use windows::Win32::Foundation::BOOL; use windows::Win32::System::Com::CLSCTX_ALL; use windows::Win32::System::Com::COINIT_MULTITHREADED; use windows::Win32::System::Com::CoCreateInstance; use windows::Win32::System::Com::CoInitializeEx; -use windows::Win32::System::Variant::VARIANT; use windows::Win32::UI::Accessibility::CUIAutomation; use windows::Win32::UI::Accessibility::IUIAutomation; use windows::Win32::UI::Accessibility::IUIAutomationAndCondition; @@ -22,7 +20,6 @@ use windows::Win32::UI::Accessibility::IUIAutomationNotCondition; use windows::Win32::UI::Accessibility::IUIAutomationOrCondition; use windows::Win32::UI::Accessibility::IUIAutomationPropertyCondition; use windows::Win32::UI::Accessibility::IUIAutomationTreeWalker; -use windows::core::ComInterface; use windows::core::IUnknown; use windows::core::Interface; use windows::core::IntoParam; @@ -64,11 +61,15 @@ impl UIAutomation { /// /// This method initializes the COM library each time, sets the thread's concurrency model as `COINIT_MULTITHREADED`. pub fn new() -> Result { - unsafe { - CoInitializeEx(None, COINIT_MULTITHREADED)?; + let result = unsafe { + CoInitializeEx(None, COINIT_MULTITHREADED) }; - UIAutomation::new_direct() + if result.is_ok() { + UIAutomation::new_direct() + } else { + Err(result.into()) + } } /// Creates a uiautomation client instance without initializing the COM library. @@ -265,12 +266,12 @@ impl UIAutomation { /// Creates a condition that selects elements that have a property with the specified value, using optional flags. pub fn create_property_condition(&self, property: UIProperty, value: Variant, flags: Option) -> Result { - let val: VARIANT = value.into(); + // let val: VARIANT = value.into(); let condition = unsafe { if let Some(flags) = flags { - self.automation.CreatePropertyConditionEx(property.into(), val, flags.into())? + self.automation.CreatePropertyConditionEx(property.into(), value, flags.into())? } else { - self.automation.CreatePropertyCondition(property.into(), val)? + self.automation.CreatePropertyCondition(property.into(), value)? } }; Ok(condition.into()) @@ -629,10 +630,9 @@ impl UIElement { /// Retrieves a point on the element that can be clicked. pub fn get_clickable_point(&self) -> Result> { let mut point = Point::default(); - let mut got = BOOL::default(); - unsafe { - self.element.GetClickablePoint(point.as_mut(), &mut got)?; - } + let mut got = unsafe { + self.element.GetClickablePoint(point.as_mut())? + }; Ok(if got.as_bool() { Some(point) @@ -789,7 +789,7 @@ impl Into for UIElement { // } impl IntoParam for UIElement { - fn into_param(self) -> windows::core::Param { + unsafe fn into_param(self) -> windows::core::Param { windows::core::Param::Owned(self.element) } } @@ -1285,7 +1285,7 @@ impl AsRef for UICondition { } impl IntoParam for UICondition { - fn into_param(self) -> windows::core::Param { + unsafe fn into_param(self) -> windows::core::Param { windows::core::Param::Owned(self.0) } } diff --git a/crates/uiautomation/src/errors.rs b/crates/uiautomation/src/errors.rs index 6fe7ac2..9cac343 100644 --- a/crates/uiautomation/src/errors.rs +++ b/crates/uiautomation/src/errors.rs @@ -45,11 +45,13 @@ impl Error { // }; // HRESULT(code).into() - if let Err(e) = error { - e.into() - } else { - HRESULT(0).into() - } + // if let Err(e) = error { + // e.into() + // } else { + // HRESULT(0).into() + // } + let result = HRESULT::from_win32(error.0); + result.into() } pub fn code(&self) -> i32 { diff --git a/crates/uiautomation/src/patterns.rs b/crates/uiautomation/src/patterns.rs index 5f9420e..d8b544e 100644 --- a/crates/uiautomation/src/patterns.rs +++ b/crates/uiautomation/src/patterns.rs @@ -1,6 +1,7 @@ use uiautomation_derive::EnumConvert; +use uiautomation_derive::map_as; +use windows::core::Interface; use windows::Win32::Foundation::BOOL; -use windows::Win32::System::Variant::VARIANT; use windows::Win32::UI::Accessibility::IUIAutomationAnnotationPattern; use windows::Win32::UI::Accessibility::IUIAutomationCustomNavigationPattern; use windows::Win32::UI::Accessibility::IUIAutomationDockPattern; @@ -39,10 +40,8 @@ use windows::Win32::UI::Accessibility::IUIAutomationVirtualizedItemPattern; use windows::Win32::UI::Accessibility::IUIAutomationWindowPattern; use windows::Win32::UI::Accessibility::SynchronizedInputType; use windows::core::BSTR; -use windows::core::ComInterface; use windows::core::IUnknown; -use crate::errors::ERR_NOTFOUND; use crate::errors::Error; use crate::Result; use crate::UIElement; @@ -69,90 +68,91 @@ use crate::variants::Variant; /// `UIPatternType` is an enum wrapper for `windows::Win32::UI::Accessibility::UIA_PATTERN_ID`. /// /// Describes the named constants that identify Microsoft UI Automation control patterns. -#[repr(u32)] +#[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)] +#[map_as(windows::Win32::UI::Accessibility::UIA_PATTERN_ID)] pub enum UIPatternType { /// Identifies the Invoke control pattern. - Invoke = 10000u32, + Invoke = 10000i32, /// Identifies the Selection control pattern. - Selection = 10001u32, + Selection = 10001i32, /// Identifies the Value control pattern. - Value = 10002u32, + Value = 10002i32, /// Identifies the RangeValue control pattern. - RangeValue = 10003u32, + RangeValue = 10003i32, /// Identifies the Scroll control pattern. - Scroll = 10004u32, + Scroll = 10004i32, /// Identifies the ExpandCollapse control pattern. - ExpandCollapse = 10005u32, + ExpandCollapse = 10005i32, /// Identifies the Grid control pattern. - Grid = 10006u32, + Grid = 10006i32, /// Identifies the GridItem control pattern. - GridItem = 10007u32, + GridItem = 10007i32, /// Identifies the MultipleView control pattern. - MultipleView = 10008u32, + MultipleView = 10008i32, /// Identifies the Window control pattern. - Window = 10009u32, + Window = 10009i32, /// Identifies the SelectionItem control pattern. - SelectionItem = 10010u32, + SelectionItem = 10010i32, /// Identifies the Dock control pattern. - Dock = 10011u32, + Dock = 10011i32, /// Identifies the Table control pattern. - Table = 10012u32, + Table = 10012i32, /// Identifies the TableItem control pattern. - TableItem = 10013u32, + TableItem = 10013i32, /// Identifies the Text control pattern. - Text = 10014u32, + Text = 10014i32, /// Identifies the Toggle control pattern. - Toggle = 10015u32, + Toggle = 10015i32, /// Identifies the Transform control pattern. - Transform = 10016u32, + Transform = 10016i32, /// Identifies the ScrollItem control pattern. - ScrollItem = 10017u32, + ScrollItem = 10017i32, /// Identifies the LegacyIAccessible control pattern. - LegacyIAccessible = 10018u32, + LegacyIAccessible = 10018i32, /// Identifies the ItemContainer control pattern. - ItemContainer = 10019u32, + ItemContainer = 10019i32, /// Identifies the VirtualizedItem control pattern. - VirtualizedItem = 10020u32, + VirtualizedItem = 10020i32, /// Identifies the SynchronizedInput control pattern. - SynchronizedInput = 10021u32, + SynchronizedInput = 10021i32, /// Identifies the ObjectModel control pattern. Supported starting with Windows 8. - ObjectModel = 10022u32, + ObjectModel = 10022i32, /// Identifies the Annotation control pattern. Supported starting with Windows 8. - Annotation = 10023u32, + Annotation = 10023i32, /// Identifies the second version of the Text control pattern. Supported starting with Windows 8. - TextP = 10024u32, + TextP = 10024i32, /// Identifies the Styles control pattern. Supported starting with Windows 8. - Styles = 10025u32, + Styles = 10025i32, /// Identifies the Spreadsheet control pattern. Supported starting with Windows 8. - Spreadsheet = 10026u32, + Spreadsheet = 10026i32, /// Identifies the SpreadsheetItem control pattern. Supported starting with Windows 8. - SpreadsheetItem = 10027u32, + SpreadsheetItem = 10027i32, /// Identifies the second version of the Transform control pattern. Supported starting with Windows 8. - TransformP = 10028u32, + TransformP = 10028i32, /// Identifies the TextChild control pattern. Supported starting with Windows 8. - TextChild = 10029u32, + TextChild = 10029i32, /// Identifies the Drag control pattern. Supported starting with Windows 8. - Drag = 10030u32, + Drag = 10030i32, /// Identifies the DropTarget control pattern. Supported starting with Windows 8. - DropTarget = 10031u32, + DropTarget = 10031i32, /// Identifies the TextEdit control pattern. Supported starting with Windows 8.1. - TextEdit = 10032u32, + TextEdit = 10032i32, /// Identifies the CustomNavigation control pattern. Supported starting with Windows 10. - CustomNavigation = 10033u32 + CustomNavigation = 10033i32 } -impl From for UIPatternType { - fn from(value: windows::Win32::UI::Accessibility::UIA_PATTERN_ID) -> Self { - value.0.try_into().unwrap() - } -} +// impl From for UIPatternType { +// fn from(value: windows::Win32::UI::Accessibility::UIA_PATTERN_ID) -> Self { +// value.0.try_into().unwrap() +// } +// } -impl Into for UIPatternType { - fn into(self) -> windows::Win32::UI::Accessibility::UIA_PATTERN_ID { - windows::Win32::UI::Accessibility::UIA_PATTERN_ID(self as _) - } -} +// impl Into for UIPatternType { +// fn into(self) -> windows::Win32::UI::Accessibility::UIA_PATTERN_ID { +// windows::Win32::UI::Accessibility::UIA_PATTERN_ID(self as _) +// } +// } /// `UIPattern` is the wrapper trait for patterns. pub trait UIPattern { @@ -738,9 +738,9 @@ pub struct UIItemContainerPattern { impl UIItemContainerPattern { pub fn find_item_by_property(&self, start_after: UIElement, property: UIProperty, value: Variant) -> Result { - let val: VARIANT = value.into(); + // let val: VARIANT = value.into(); let element = unsafe { - self.pattern.FindItemByProperty(start_after.as_ref(), property.into(), val)? + self.pattern.FindItemByProperty(start_after.as_ref(), property.into(), value)? }; Ok(element.into()) @@ -1745,17 +1745,16 @@ impl UITextPattern { pub fn get_caret_range(&self) -> Result<(bool, UITextRange)> { let pattern2: IUIAutomationTextPattern2 = self.pattern.cast()?; let mut active = BOOL::default(); - let mut range = Option::None; - unsafe { - pattern2.GetCaretRange(&mut active, &mut range)? + let range = unsafe { + pattern2.GetCaretRange(&mut active)? }; - - if range.is_some() { - let range = range.unwrap(); - Ok((active.as_bool(), range.into())) - } else { - Err(Error::new(ERR_NOTFOUND, "Range Not Found")) - } + Ok((active.as_bool(), range.into())) + // if range.is_some() { + // let range = range.unwrap(); + // Ok((active.as_bool(), range.into())) + // } else { + // Err(Error::new(ERR_NOTFOUND, "Range Not Found")) + // } } } @@ -1892,7 +1891,7 @@ impl UITextRange { pub fn find_attribute(&self, attr: TextAttribute, value: Variant, backward: bool) -> Result { let range = unsafe { - self.range.FindAttribute(attr.into(), value.into(), backward)? + self.range.FindAttribute(attr.into(), value, backward)? }; Ok(range.into()) } @@ -2415,4 +2414,15 @@ impl AsRef for UIWindowPattern { fn as_ref(&self) -> &IUIAutomationWindowPattern { &self.pattern } +} + +#[cfg(test)] +mod tests { + use super::UIPatternType; + + #[test] + fn test_uipatterntypes() { + let t = UIPatternType::try_from(10000i32).unwrap(); + assert_eq!(t, UIPatternType::Invoke); + } } \ No newline at end of file diff --git a/crates/uiautomation/src/types.rs b/crates/uiautomation/src/types.rs index 1648f04..60bbaa3 100644 --- a/crates/uiautomation/src/types.rs +++ b/crates/uiautomation/src/types.rs @@ -251,360 +251,360 @@ impl AsRef for Handle { /// Defines enum for `windows::Win32::UI::Accessibility::UIA_PROPERTY_ID`. /// /// Describes the named constants that identify the properties of Microsoft UI Automation elements. -#[repr(u32)] +#[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)] #[map_as(windows::Win32::UI::Accessibility::UIA_PROPERTY_ID)] pub enum UIProperty { /// Identifies the RuntimeId property, which is an array of integers representing the identifier for an automation element. - RuntimeId = 30000u32, + RuntimeId = 30000i32, /// Identifies the BoundingRectangle property, which specifies the coordinates of the rectangle that completely encloses the automation element. - BoundingRectangle = 30001u32, + BoundingRectangle = 30001i32, /// Identifies the ProcessId property, which is an integer representing the process identifier (ID) of the automation element. - ProcessId = 30002u32, + ProcessId = 30002i32, /// Identifies the ControlType property, which is a class that identifies the type of the automation element. - ControlType = 30003u32, + ControlType = 30003i32, /// Identifies the LocalizedControlType property, which is a text string describing the type of control that the automation element represents. - LocalizedControlType = 30004u32, + LocalizedControlType = 30004i32, /// Identifies the Name property, which is a string that holds the name of the automation element. - Name = 30005u32, + Name = 30005i32, /// Identifies the AcceleratorKey property, which is a string containing the accelerator key (also called shortcut key) combinations for the automation element. - AcceleratorKey = 30006u32, + AcceleratorKey = 30006i32, /// Identifies the AccessKey property, which is a string containing the access key character for the automation element. - AccessKey = 30007u32, + AccessKey = 30007i32, /// Identifies the HasKeyboardFocus property, which is a Boolean value that indicates whether the automation element has keyboard focus. - HasKeyboardFocus = 30008u32, + HasKeyboardFocus = 30008i32, /// Identifies the IsKeyboardFocusable property, which is a Boolean value that indicates whether the automation element can accept keyboard focus. - IsKeyboardFocusable = 30009u32, + IsKeyboardFocusable = 30009i32, /// Identifies the IsEnabled property, which is a Boolean value that indicates whether the UI item referenced by the automation element is enabled and can be interacted with. - IsEnabled = 30010u32, + IsEnabled = 30010i32, /// Identifies the AutomationId property, which is a string containing the UI Automation identifier (ID) for the automation element. - AutomationId = 30011u32, + AutomationId = 30011i32, /// Identifies the ClassName property, which is a string containing the class name for the automation element as assigned by the control developer. - ClassName = 30012u32, + ClassName = 30012i32, /// Identifies the HelpText property, which is a help text string associated with the automation element. - HelpText = 30013u32, + HelpText = 30013i32, /// Identifies the ClickablePoint property, which is a point on the automation element that can be clicked. - ClickablePoint = 30014u32, + ClickablePoint = 30014i32, /// Identifies the Culture property, which contains a locale identifier for the automation element. - Culture = 30015u32, + Culture = 30015i32, /// Identifies the IsControlElement property, which is a Boolean value that specifies whether the element appears in the control view of the automation element tree. - IsControlElement = 30016u32, + IsControlElement = 30016i32, /// Identifies the IsContentElement property, which is a Boolean value that specifies whether the element appears in the content view of the automation element tree. - IsContentElement = 30017u32, + IsContentElement = 30017i32, /// Identifies the LabeledBy property, which is an automation element that contains the text label for this element. - LabeledBy = 30018u32, + LabeledBy = 30018i32, /// Identifies the IsPassword property, which is a Boolean value that indicates whether the automation element contains protected content or a password. - IsPassword = 30019u32, + IsPassword = 30019i32, /// Identifies the NativeWindowHandle property, which is an integer that represents the handle (HWND) of the automation element window, if it exists; otherwise, this property is 0. - NativeWindowHandle = 30020u32, + NativeWindowHandle = 30020i32, /// Identifies the ItemType property, which is a text string describing the type of the automation element. - ItemType = 30021u32, + ItemType = 30021i32, /// Identifies the IsOffscreen property, which is a Boolean value that indicates whether the automation element is entirely scrolled out of view (for example, an item in a list box that is outside the viewport of the container object) or collapsed out of view (for example, an item in a tree view or menu, or in a minimized window). - IsOffscreen = 30022u32, + IsOffscreen = 30022i32, /// Identifies the Orientation property, which indicates the orientation of the control represented by the automation element. The property is expressed as a value from the OrientationType enumerated type. - Orientation = 30023u32, + Orientation = 30023i32, /// Identifies the FrameworkId property, which is a string containing the name of the underlying UI framework that the automation element belongs to. - FrameworkId = 30024u32, + FrameworkId = 30024i32, /// Identifies the IsRequiredForForm property, which is a Boolean value that indicates whether the automation element is required to be filled out on a form. - IsRequiredForForm = 30025u32, + IsRequiredForForm = 30025i32, /// Identifies the ItemStatus property, which is a text string describing the status of an item of the automation element. - ItemStatus = 30026u32, + ItemStatus = 30026i32, /// Identifies the IsDockPatternAvailable property, which indicates whether the Dock control pattern is available for the automation element. - IsDockPatternAvailable = 30027u32, + IsDockPatternAvailable = 30027i32, /// Identifies the IsExpandCollapsePatternAvailable property, which indicates whether the ExpandCollapse control pattern is available for the automation element. - IsExpandCollapsePatternAvailable = 30028u32, + IsExpandCollapsePatternAvailable = 30028i32, /// Identifies the IsGridItemPatternAvailable property, which indicates whether the GridItem control pattern is available for the automation element. - IsGridItemPatternAvailable = 30029u32, + IsGridItemPatternAvailable = 30029i32, /// Identifies the IsGridPatternAvailable property, which indicates whether the Grid control pattern is available for the automation element. - IsGridPatternAvailable = 30030u32, + IsGridPatternAvailable = 30030i32, /// Identifies the IsInvokePatternAvailable property, which indicates whether the Invoke control pattern is available for the automation element. - IsInvokePatternAvailable = 30031u32, + IsInvokePatternAvailable = 30031i32, /// Identifies the IsMultipleViewPatternAvailable property, which indicates whether the MultipleView control pattern is available for the automation element. - IsMultipleViewPatternAvailable = 30032u32, + IsMultipleViewPatternAvailable = 30032i32, /// Identifies the IsRangeValuePatternAvailable property, which indicates whether the RangeValue control pattern is available for the automation element. - IsRangeValuePatternAvailable = 30033u32, + IsRangeValuePatternAvailable = 30033i32, /// Identifies the IsScrollPatternAvailable property, which indicates whether the Scroll control pattern is available for the automation element. - IsScrollPatternAvailable = 30034u32, + IsScrollPatternAvailable = 30034i32, /// Identifies the IsScrollItemPatternAvailable property, which indicates whether the ScrollItem control pattern is available for the automation element. - IsScrollItemPatternAvailable = 30035u32, + IsScrollItemPatternAvailable = 30035i32, /// Identifies the IsSelectionItemPatternAvailable property, which indicates whether the SelectionItem control pattern is available for the automation element. - IsSelectionItemPatternAvailable = 30036u32, + IsSelectionItemPatternAvailable = 30036i32, /// Identifies the IsSelectionPatternAvailable property, which indicates whether the Selection control pattern is available for the automation element. - IsSelectionPatternAvailable = 30037u32, + IsSelectionPatternAvailable = 30037i32, /// Identifies the IsTablePatternAvailable property, which indicates whether the Table control pattern is available for the automation element. - IsTablePatternAvailable = 30038u32, + IsTablePatternAvailable = 30038i32, /// Identifies the IsTableItemPatternAvailable property, which indicates whether the TableItem control pattern is available for the automation element. - IsTableItemPatternAvailable = 30039u32, + IsTableItemPatternAvailable = 30039i32, /// Identifies the IsTextPatternAvailable property, which indicates whether the Text control pattern is available for the automation element. - IsTextPatternAvailable = 30040u32, + IsTextPatternAvailable = 30040i32, /// Identifies the IsTogglePatternAvailable property, which indicates whether the Toggle control pattern is available for the automation element. - IsTogglePatternAvailable = 30041u32, + IsTogglePatternAvailable = 30041i32, /// Identifies the IsTransformPatternAvailable property, which indicates whether the Transform control pattern is available for the automation element. - IsTransformPatternAvailable = 30042u32, + IsTransformPatternAvailable = 30042i32, /// Identifies the IsValuePatternAvailable property, which indicates whether the Value control pattern is available for the automation element. - IsValuePatternAvailable = 30043u32, + IsValuePatternAvailable = 30043i32, /// Identifies the IsWindowPatternAvailable property, which indicates whether the Window control pattern is available for the automation element. - IsWindowPatternAvailable = 30044u32, + IsWindowPatternAvailable = 30044i32, /// Identifies the Value property of the Value control pattern. - ValueValue = 30045u32, + ValueValue = 30045i32, /// Identifies the IsReadOnly property of the Value control pattern. - ValueIsReadOnly = 30046u32, + ValueIsReadOnly = 30046i32, /// Identifies the Value property of the RangeValue control pattern. - RangeValueValue = 30047u32, + RangeValueValue = 30047i32, /// Identifies the IsReadOnly property of the RangeValue control pattern. - RangeValueIsReadOnly = 30048u32, + RangeValueIsReadOnly = 30048i32, /// Identifies the Minimum property of the RangeValue control pattern. - RangeValueMinimum = 30049u32, + RangeValueMinimum = 30049i32, /// Identifies the Maximum property of the RangeValue control pattern. - RangeValueMaximum = 30050u32, + RangeValueMaximum = 30050i32, /// Identifies the LargeChange property of the RangeValue control pattern. - RangeValueLargeChange = 30051u32, + RangeValueLargeChange = 30051i32, /// Identifies the SmallChange property of the RangeValue control pattern. - RangeValueSmallChange = 30052u32, + RangeValueSmallChange = 30052i32, /// Identifies the HorizontalScrollPercent property of the Scroll control pattern. - ScrollHorizontalScrollPercent = 30053u32, + ScrollHorizontalScrollPercent = 30053i32, /// Identifies the HorizontalViewSize property of the Scroll control pattern. - ScrollHorizontalViewSize = 30054u32, + ScrollHorizontalViewSize = 30054i32, /// Identifies the VerticalScrollPercent property of the Scroll control pattern. - ScrollVerticalScrollPercent = 30055u32, + ScrollVerticalScrollPercent = 30055i32, /// Identifies the VerticalViewSize property of the Scroll control pattern. - ScrollVerticalViewSize = 30056u32, + ScrollVerticalViewSize = 30056i32, /// Identifies the HorizontallyScrollable property of the Scroll control pattern. - ScrollHorizontallyScrollable = 30057u32, + ScrollHorizontallyScrollable = 30057i32, /// Identifies the VerticallyScrollable property of the Scroll control pattern. - ScrollVerticallyScrollable = 30058u32, + ScrollVerticallyScrollable = 30058i32, /// Identifies the Selection property of the Selection control pattern. - SelectionSelection = 30059u32, + SelectionSelection = 30059i32, /// Identifies the CanSelectMultiple property of the Selection control pattern. - SelectionCanSelectMultiple = 30060u32, + SelectionCanSelectMultiple = 30060i32, /// Identifies the IsSelectionRequired property of the Selection control pattern. - SelectionIsSelectionRequired = 30061u32, + SelectionIsSelectionRequired = 30061i32, /// Identifies the RowCount property of the Grid control pattern. This property indicates the total number of rows in the grid. - GridRowCount = 30062u32, + GridRowCount = 30062i32, /// Identifies the ColumnCount property of the Grid control pattern. This property indicates the total number of columns in the grid. - GridColumnCount = 30063u32, + GridColumnCount = 30063i32, /// Identifies the Row property of the GridItem control pattern. This property is the ordinal number of the row that contains the cell or item. - GridItemRow = 30064u32, + GridItemRow = 30064i32, /// Identifies the Column property of the GridItem control pattern. This property indicates the ordinal number of the column that contains the cell or item. - GridItemColumn = 30065u32, + GridItemColumn = 30065i32, /// Identifies the RowSpan property of the GridItem control pattern. This property indicates the number of rows spanned by the cell or item. - GridItemRowSpan = 30066u32, + GridItemRowSpan = 30066i32, /// Identifies the ColumnSpan property of the GridItem control pattern. This property indicates the number of columns spanned by the cell or item. - GridItemColumnSpan = 30067u32, + GridItemColumnSpan = 30067i32, /// Identifies the ContainingGrid property of the GridItem control pattern. - GridItemContainingGrid = 30068u32, + GridItemContainingGrid = 30068i32, /// Identifies the DockPosition property of the Dock control pattern. - DockDockPosition = 30069u32, + DockDockPosition = 30069i32, /// Identifies the ExpandCollapseState property of the ExpandCollapse control pattern. - ExpandCollapseExpandCollapseState = 30070u32, + ExpandCollapseExpandCollapseState = 30070i32, /// Identifies the CurrentView property of the MultipleView control pattern. - MultipleViewCurrentView = 30071u32, + MultipleViewCurrentView = 30071i32, /// Identifies the SupportedViews property of the MultipleView control pattern. - MultipleViewSupportedViews = 30072u32, + MultipleViewSupportedViews = 30072i32, /// Identifies the CanMaximize property of the Window control pattern. - WindowCanMaximize = 30073u32, + WindowCanMaximize = 30073i32, /// Identifies the CanMinimize property of the Window control pattern. - WindowCanMinimize = 30074u32, + WindowCanMinimize = 30074i32, /// Identifies the WindowVisualState property of the Window control pattern. - WindowWindowVisualState = 30075u32, + WindowWindowVisualState = 30075i32, /// Identifies the WindowInteractionState property of the Window control pattern. - WindowWindowInteractionState = 30076u32, + WindowWindowInteractionState = 30076i32, /// Identifies the IsModal property of the Window control pattern. - WindowIsModal = 30077u32, + WindowIsModal = 30077i32, /// Identifies the IsTopmost property of the Window control pattern. - WindowIsTopmost = 30078u32, + WindowIsTopmost = 30078i32, /// Identifies the IsSelected property of the SelectionItem control pattern. - SelectionItemIsSelected = 30079u32, + SelectionItemIsSelected = 30079i32, /// Identifies the SelectionContainer property of the SelectionItem control pattern. - SelectionItemSelectionContainer = 30080u32, + SelectionItemSelectionContainer = 30080i32, /// Identifies the RowHeaders property of the Table control pattern. - TableRowHeaders = 30081u32, + TableRowHeaders = 30081i32, /// Identifies the ColumnHeaders property of the Table control pattern. - TableColumnHeaders = 30082u32, + TableColumnHeaders = 30082i32, /// Identifies the RowOrColumnMajor property of the Table control pattern. - TableRowOrColumnMajor = 30083u32, + TableRowOrColumnMajor = 30083i32, /// Identifies the RowHeaderItems property of the TableItem control pattern. - TableItemRowHeaderItems = 30084u32, + TableItemRowHeaderItems = 30084i32, /// Identifies the ColumnHeaderItems property of the TableItem control pattern. - TableItemColumnHeaderItems = 30085u32, + TableItemColumnHeaderItems = 30085i32, /// Identifies the ToggleState property of the Toggle control pattern. - ToggleToggleState = 30086u32, + ToggleToggleState = 30086i32, /// Identifies the CanMove property of the Transform control pattern. - TransformCanMove = 30087u32, + TransformCanMove = 30087i32, /// Identifies the CanResize property of the Transform control pattern. - TransformCanResize = 30088u32, + TransformCanResize = 30088i32, /// Identifies the CanRotate property of the Transform control pattern. - TransformCanRotate = 30089u32, + TransformCanRotate = 30089i32, /// Identifies the IsLegacyIAccessiblePatternAvailable property, which indicates whether the LegacyIAccessible control pattern is available for the automation element. - IsLegacyIAccessiblePatternAvailable = 30090u32, + IsLegacyIAccessiblePatternAvailable = 30090i32, /// Identifies the ChildId property of the LegacyIAccessible control pattern. - LegacyIAccessibleChildId = 30091u32, + LegacyIAccessibleChildId = 30091i32, /// Identifies the Name property of the LegacyIAccessible control pattern. - LegacyIAccessibleName = 30092u32, + LegacyIAccessibleName = 30092i32, /// Identifies the Value property of the LegacyIAccessible control pattern. - LegacyIAccessibleValue = 30093u32, + LegacyIAccessibleValue = 30093i32, /// Identifies the Description property of the LegacyIAccessible control pattern. - LegacyIAccessibleDescription = 30094u32, + LegacyIAccessibleDescription = 30094i32, /// Identifies the Roleproperty of the LegacyIAccessible control pattern. - LegacyIAccessibleRole = 30095u32, + LegacyIAccessibleRole = 30095i32, /// Identifies the State property of the LegacyIAccessible control pattern. - LegacyIAccessibleState = 30096u32, + LegacyIAccessibleState = 30096i32, /// Identifies the Help property of the LegacyIAccessible control pattern. - LegacyIAccessibleHelp = 30097u32, + LegacyIAccessibleHelp = 30097i32, /// Identifies the KeyboardShortcut property of the LegacyIAccessible control pattern. - LegacyIAccessibleKeyboardShortcut = 30098u32, + LegacyIAccessibleKeyboardShortcut = 30098i32, /// Identifies the Selection property of the LegacyIAccessible control pattern. - LegacyIAccessibleSelection = 30099u32, + LegacyIAccessibleSelection = 30099i32, /// Identifies the DefaultAction property of the LegacyIAccessible control pattern. - LegacyIAccessibleDefaultAction = 30100u32, + LegacyIAccessibleDefaultAction = 30100i32, /// Identifies the AriaRole property, which is a string containing the Accessible Rich Internet Application (ARIA) role information for the automation element. - AriaRole = 30101u32, + AriaRole = 30101i32, /// Identifies the AriaProperties property, which is a formatted string containing the Accessible Rich Internet Application (ARIA) property information for the automation element. - AriaProperties = 30102u32, + AriaProperties = 30102i32, /// Identifies the IsDataValidForForm property, which is a Boolean value that indicates whether the entered or selected value is valid for the form rule associated with the automation element. - IsDataValidForForm = 30103u32, + IsDataValidForForm = 30103i32, /// Identifies the ControllerFor property, which is an array of automation elements that are manipulated by the automation element that supports this property. - ControllerFor = 30104u32, + ControllerFor = 30104i32, /// Identifies the DescribedBy property, which is an array of elements that provide more information about the automation element. - DescribedBy = 30105u32, + DescribedBy = 30105i32, /// Identifies the FlowsTo property, which is an array of automation elements that suggests the reading order after the current automation element. - FlowsTo = 30106u32, + FlowsTo = 30106i32, /// Identifies the ProviderDescription property, which is a formatted string containing the source information of the UI Automation provider for the automation element, including proxy information. - ProviderDescription = 30107u32, + ProviderDescription = 30107i32, /// Identifies the IsItemContainerPatternAvailable property, which indicates whether the ItemContainer control pattern is available for the automation element. - IsItemContainerPatternAvailable = 30108u32, + IsItemContainerPatternAvailable = 30108i32, /// Identifies the IsVirtualizedItemPatternAvailable property, which indicates whether the VirtualizedItem control pattern is available for the automation element. - IsVirtualizedItemPatternAvailable = 30109u32, + IsVirtualizedItemPatternAvailable = 30109i32, /// Identifies the IsSynchronizedInputPatternAvailable property, which indicates whether the SynchronizedInput control pattern is available for the automation element. - IsSynchronizedInputPatternAvailable = 30110u32, + IsSynchronizedInputPatternAvailable = 30110i32, /// Identifies the OptimizeForVisualContent property, which is a Boolean value that indicates whether the provider exposes only elements that are visible. - OptimizeForVisualContent = 30111u32, + OptimizeForVisualContent = 30111i32, /// Identifies the IsObjectModelPatternAvailable property, which indicates whether the ObjectModel control pattern is available for the automation element. - IsObjectModelPatternAvailable = 30112u32, + IsObjectModelPatternAvailable = 30112i32, /// Identifies the AnnotationTypeId property of the Annotation control pattern. Supported starting with Windows 8. - AnnotationAnnotationTypeId = 30113u32, + AnnotationAnnotationTypeId = 30113i32, /// Identifies the AnnotationTypeName property of the Annotation control pattern. Supported starting with Windows 8. - AnnotationAnnotationTypeName = 30114u32, + AnnotationAnnotationTypeName = 30114i32, /// Identifies the Author property of the Annotation control pattern. Supported starting with Windows 8. - AnnotationAuthor = 30115u32, + AnnotationAuthor = 30115i32, /// Identifies the DateTime property of the Annotation control pattern. Supported starting with Windows 8. - AnnotationDateTime = 30116u32, + AnnotationDateTime = 30116i32, /// Identifies the Target property of the Annotation control pattern. Supported starting with Windows 8. - AnnotationTarget = 30117u32, + AnnotationTarget = 30117i32, /// Identifies the IsAnnotationPatternAvailable property, which indicates whether the Annotation control pattern is available for the automation element. - IsAnnotationPatternAvailable = 30118u32, + IsAnnotationPatternAvailable = 30118i32, /// Identifies the IsTextPattern2Available property, which indicates whether version two of the Text control pattern is available for the automation element. - IsTextPattern2Available = 30119u32, + IsTextPattern2Available = 30119i32, /// Identifies the StyleId property of the Styles control pattern. - StylesStyleId = 30120u32, + StylesStyleId = 30120i32, /// Identifies the StyleName property of the Styles control pattern. - StylesStyleName = 30121u32, + StylesStyleName = 30121i32, /// Identifies the FillColor property of the Styles control pattern. - StylesFillColor = 30122u32, + StylesFillColor = 30122i32, /// Identifies the FillPatternStyle property of the Styles control pattern. - StylesFillPatternStyle = 30123u32, + StylesFillPatternStyle = 30123i32, /// Identifies the Shape property of the Styles control pattern. - StylesShape = 30124u32, + StylesShape = 30124i32, /// Identifies the FillPatternColor property of the Styles control pattern. - StylesFillPatternColor = 30125u32, + StylesFillPatternColor = 30125i32, /// Identifies the ExtendedProperties property of the Styles control pattern. - StylesExtendedProperties = 30126u32, + StylesExtendedProperties = 30126i32, /// Identifies the IsStylesPatternAvailable property, which indicates whether the Styles control pattern is available for the automation element. - IsStylesPatternAvailable = 30127u32, + IsStylesPatternAvailable = 30127i32, /// Identifies the IsSpreadsheetPatternAvailable property, which indicates whether the Spreadsheet control pattern is available for the automation element. - IsSpreadsheetPatternAvailable = 30128u32, + IsSpreadsheetPatternAvailable = 30128i32, /// Identifies the Formula property of the SpreadsheetItem control pattern. - SpreadsheetItemFormula = 30129u32, + SpreadsheetItemFormula = 30129i32, /// Identifies the AnnotationObjects property of the SpreadsheetItem control pattern. - SpreadsheetItemAnnotationObjects = 30130u32, + SpreadsheetItemAnnotationObjects = 30130i32, /// Identifies the AnnotationTypes property of the SpreadsheetItem control pattern. Supported starting with Windows 8. - SpreadsheetItemAnnotationTypes = 30131u32, + SpreadsheetItemAnnotationTypes = 30131i32, /// Identifies the IsSpreadsheetItemPatternAvailable property, which indicates whether the SpreadsheetItem control pattern is available for the automation element. - IsSpreadsheetItemPatternAvailable = 30132u32, + IsSpreadsheetItemPatternAvailable = 30132i32, /// Identifies the CanZoom property of the Transform control pattern. Supported starting with Windows 8. - Transform2CanZoom = 30133u32, + Transform2CanZoom = 30133i32, /// Identifies the IsTransformPattern2Available property, which indicates whether version two of the Transform control pattern is available for the automation element. - IsTransformPattern2Available = 30134u32, + IsTransformPattern2Available = 30134i32, /// Identifies the LiveSetting property, which is supported by an automation element that represents a live region. - LiveSetting = 30135u32, + LiveSetting = 30135i32, /// Identifies the IsTextChildPatternAvailable property, which indicates whether the TextChild control pattern is available for the automation element. - IsTextChildPatternAvailable = 30136u32, + IsTextChildPatternAvailable = 30136i32, /// Identifies the IsDragPatternAvailable property, which indicates whether the Drag control pattern is available for the automation element. - IsDragPatternAvailable = 30137u32, + IsDragPatternAvailable = 30137i32, /// Identifies the IsGrabbed property of the Drag control pattern. Supported starting with Windows 8. - DragIsGrabbed = 30138u32, + DragIsGrabbed = 30138i32, /// Identifies the DropEffect property of the Drag control pattern. Supported starting with Windows 8. - DragDropEffect = 30139u32, + DragDropEffect = 30139i32, /// Identifies the DropEffects property of the Drag control pattern. Supported starting with Windows 8. - DragDropEffects = 30140u32, + DragDropEffects = 30140i32, /// Identifies the IsDropTargetPatternAvailable property, which indicates whether the DropTarget control pattern is available for the automation element. - IsDropTargetPatternAvailable = 30141u32, + IsDropTargetPatternAvailable = 30141i32, /// Identifies the DropTargetEffect property of the DropTarget control pattern. Supported starting with Windows 8. - DropTargetDropTargetEffect = 30142u32, + DropTargetDropTargetEffect = 30142i32, /// Identifies the DropTargetEffects property of the DropTarget control pattern. Supported starting with Windows 8. - DropTargetDropTargetEffects = 30143u32, + DropTargetDropTargetEffects = 30143i32, /// Identifies the GrabbedItems property of the Drag control pattern. Supported starting with Windows 8. - DragGrabbedItems = 30144u32, + DragGrabbedItems = 30144i32, /// Identifies the ZoomLevel property of the Transform control pattern. Supported starting with Windows 8. - Transform2ZoomLevel = 30145u32, + Transform2ZoomLevel = 30145i32, /// Identifies the ZoomMinimum property of the Transform control pattern. Supported starting with Windows 8. - Transform2ZoomMinimum = 30146u32, + Transform2ZoomMinimum = 30146i32, /// Identifies the ZoomMaximum property of the Transform control pattern. Supported starting with Windows 8. - Transform2ZoomMaximum = 30147u32, + Transform2ZoomMaximum = 30147i32, /// Identifies the FlowsFrom property, which is an array of automation elements that suggests the reading order before the current automation element. Supported starting with Windows 8. - FlowsFrom = 30148u32, + FlowsFrom = 30148i32, /// Identifies the IsTextEditPatternAvailable property, which indicates whether the TextEdit control pattern is available for the automation element. - IsTextEditPatternAvailable = 30149u32, + IsTextEditPatternAvailable = 30149i32, /// Identifies the IsPeripheral property, which is a Boolean value that indicates whether the automation element represents peripheral UI. - IsPeripheral = 30150u32, + IsPeripheral = 30150i32, /// Identifies the IsCustomNavigationPatternAvailable property, which indicates whether the CustomNavigation control pattern is available for the automation element. - IsCustomNavigationPatternAvailable = 30151u32, + IsCustomNavigationPatternAvailable = 30151i32, /// Identifies the PositionInSet property, which is a 1-based integer associated with an automation element. - PositionInSet = 30152u32, + PositionInSet = 30152i32, /// Identifies the SizeOfSet property, which is a 1-based integer associated with an automation element. - SizeOfSet = 30153u32, + SizeOfSet = 30153i32, /// Identifies the Level property, which is a 1-based integer associated with an automation element. - Level = 30154u32, + Level = 30154i32, /// Identifies the AnnotationTypes property, which is a list of the types of annotations in a document, such as comment, header, footer, and so on. - AnnotationTypes = 30155u32, + AnnotationTypes = 30155i32, /// Identifies the AnnotationObjects property, which is a list of annotation objects in a document, such as comment, header, footer, and so on. - AnnotationObjects = 30156u32, + AnnotationObjects = 30156i32, /// Identifies the LandmarkType property, which is a Landmark Type Identifier associated with an element. - LandmarkType = 30157u32, + LandmarkType = 30157i32, /// Identifies the LocalizedLandmarkType, which is a text string describing the type of landmark that the automation element represents. - LocalizedLandmarkType = 30158u32, + LocalizedLandmarkType = 30158i32, /// The FullDescription property exposes a localized string which can contain extended description text for an element. - FullDescription = 30159u32, + FullDescription = 30159i32, /// Identifies the FillColor property, which specifies the color used to fill the automation element. - FillColor = 30160u32, + FillColor = 30160i32, /// Identifies the OutlineColor property, which specifies the color used for the outline of the automation element. - OutlineColor = 30161u32, + OutlineColor = 30161i32, /// Identifies the FillType property, which specifies the pattern used to fill the automation element, such as none, color, gradient, picture, pattern, and so on. - FillType = 30162u32, + FillType = 30162i32, /// Identifies the VisualEffects property, which is a bit field that specifies effects on the automation element, such as shadow, reflection, glow, soft edges, or bevel. - VisualEffects = 30163u32, + VisualEffects = 30163i32, /// Identifies the OutlineThickness property, which specifies the width for the outline of the automation element. - OutlineThickness = 30164u32, + OutlineThickness = 30164i32, /// Identifies the CenterPoint property, which specifies the center X and Y point coordinates of the automation element. - CenterPoint = 30165u32, + CenterPoint = 30165i32, /// Identifies the Rotation property, which specifies the angle of rotation in unspecified units. - Rotation = 30166u32, + Rotation = 30166i32, /// Identifies the Size property, which specifies the width and height of the automation element. - Size = 30167u32, + Size = 30167i32, /// Identifies whether the Selection2 control pattern is available. - IsSelectionPattern2Available = 30168u32, + IsSelectionPattern2Available = 30168i32, /// Identifies the FirstSelectedItem property of the Selection2 control pattern. - Selection2FirstSelectedItem = 30169u32, + Selection2FirstSelectedItem = 30169i32, /// Identifies the LastSelectedItem property of the Selection2 control pattern. - Selection2LastSelectedItem = 30170u32, + Selection2LastSelectedItem = 30170i32, /// Identifies the CurrentSelectedItem property of the Selection2 control pattern. - Selection2CurrentSelectedItem = 30171u32, + Selection2CurrentSelectedItem = 30171i32, /// Identifies the ItemCount property of the Selection2 control pattern. - Selection2ItemCount = 30172u32, + Selection2ItemCount = 30172i32, /// Identifies the HeadingLevel property, which indicates the heading level of a UI Automation element. - HeadingLevel = 30173u32, + HeadingLevel = 30173i32, /// Identifies the IsDialog property, which is a Boolean value that indicates whether the automation element is a dialog window. - IsDialog = 30174u32, + IsDialog = 30174i32, } /// Defines enum for `windows::Win32::UI::Accessibility::WindowInteractionState`. @@ -883,196 +883,196 @@ pub enum TreeScope { /// Defines enum for `windows::Win32::UI::Accessibility::UIA_ANNOTATIONTYPE`. /// /// This type describes the named constants that are used to identify types of annotations in a document. -#[repr(u32)] +#[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)] #[map_as(windows::Win32::UI::Accessibility::UIA_ANNOTATIONTYPE)] pub enum AnnotationType { /// The annotation type is unknown. - Unknown = 60000u32, + Unknown = 60000i32, /// A spelling error, often denoted by a red squiggly line. - SpellingError = 60001u32, + SpellingError = 60001i32, /// A grammatical error, often denoted by a green squiggly line. - GrammarError = 60002u32, + GrammarError = 60002i32, /// A comment. Comments can take different forms depending on the application. - Comment = 60003u32, + Comment = 60003i32, /// An error in a formula. Formula errors typically include red text and exclamation marks. - FormulaError = 60004u32, + FormulaError = 60004i32, /// A change that was made to the document. - TrackChanges = 60005u32, + TrackChanges = 60005i32, /// The header for a page in a document. - Header = 60006u32, + Header = 60006i32, /// The footer for a page in a document. - Footer = 60007u32, + Footer = 60007i32, /// Highlighted content, typically denoted by a contrasting background color. - Highlighted = 60008u32, + Highlighted = 60008i32, /// The endnote for a document. - Endnote = 60009u32, + Endnote = 60009i32, /// The footnote for a page in a document. - Footnote = 60010u32, + Footnote = 60010i32, /// An insertion change that was made to the document. - InsertionChange = 60011u32, + InsertionChange = 60011i32, /// A deletion change that was made to the document. - DeletionChange = 60012u32, + DeletionChange = 60012i32, /// A move change that was made to the document. - MoveChange = 60013u32, + MoveChange = 60013i32, /// A format change that was made. - FormatChange = 60014u32, + FormatChange = 60014i32, /// An unsynced change that was made to the document. - UnsyncedChange = 60015u32, + UnsyncedChange = 60015i32, /// An editing locked change that was made to the document. - EditingLockedChange = 60016u32, + EditingLockedChange = 60016i32, /// An external change that was made to the document. - ExternalChange = 60017u32, + ExternalChange = 60017i32, /// A conflicting change that was made to the document. - ConflictingChange = 60018u32, + ConflictingChange = 60018i32, /// The author of the document. - Author = 60019u32, + Author = 60019i32, /// An advanced proofing issue. - AdvancedProofingIssue = 60020u32, + AdvancedProofingIssue = 60020i32, /// A data validation error that occurred. - DataValidationError = 60021u32, + DataValidationError = 60021i32, /// A circular reference error that occurred. - CircularReferenceError = 60022u32, + CircularReferenceError = 60022i32, /// A text range containing mathematics. - Mathematics = 60023u32, + Mathematics = 60023i32, } /// Defines enum for `windows::Win32::UI::Accessibility::UIA_STYLE_ID`. /// /// This set of constants describes the named constants used to identify the visual style of text in a document. -#[repr(u32)] +#[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)] #[map_as(windows::Win32::UI::Accessibility::UIA_STYLE_ID)] pub enum StyleType { /// A custom style. - Custom = 70000u32, + Custom = 70000i32, /// A first level heading. - Heading1 = 70001u32, + Heading1 = 70001i32, /// A second level heading. - Heading2 = 70002u32, + Heading2 = 70002i32, /// A third level heading. - Heading3 = 70003u32, + Heading3 = 70003i32, /// A fourth level heading. - Heading4 = 70004u32, + Heading4 = 70004i32, /// A fifth level heading. - Heading5 = 70005u32, + Heading5 = 70005i32, /// A sixth level heading. - Heading6 = 70006u32, + Heading6 = 70006i32, /// A seventh level heading. - Heading7 = 70007u32, + Heading7 = 70007i32, /// An eighth level heading. - Heading8 = 70008u32, + Heading8 = 70008i32, /// A ninth level heading. - Heading9 = 70009u32, + Heading9 = 70009i32, /// A title. - Title = 70010u32, + Title = 70010i32, /// A subtitle. - Subtitle = 70011u32, + Subtitle = 70011i32, /// Normal style. - Normal = 70012u32, + Normal = 70012i32, /// Text that is emphasized. - Emphasis = 70013u32, + Emphasis = 70013i32, /// A quotation. - Quote = 70014u32, + Quote = 70014i32, /// A list with bulleted items. Supported starting with Windows 8.1. - BulletedList = 70015u32, + BulletedList = 70015i32, /// A list with numbered items. Supported starting with Windows 8.1. - NumberedList = 70016u32, + NumberedList = 70016i32, } /// Defines enum for `windows::Win32::UI::Accessibility::UIA_TEXTATTRIBUTE_ID`. /// /// This type describes the named constants used to identify text attributes of a Microsoft UI Automation text range. -#[repr(u32)] +#[repr(i32)] #[derive(Debug, Clone, Copy, PartialEq, Eq, EnumConvert)] #[map_as(windows::Win32::UI::Accessibility::UIA_TEXTATTRIBUTE_ID)] pub enum TextAttribute { /// Identifies the AnimationStyle text attribute, which specifies the type of animation applied to the text. This attribute is specified as a value from the AnimationStyle enumerated type. - AnimationStyle = 40000u32, + AnimationStyle = 40000i32, /// Identifies the BackgroundColor text attribute, which specifies the background color of the text. This attribute is specified as a COLORREF; a 32-bit value used to specify an RGB or RGBA color. - BackgroundColor = 40001u32, + BackgroundColor = 40001i32, /// Identifies the BulletStyle text attribute, which specifies the style of bullets used in the text range. This attribute is specified as a value from the BulletStyle enumerated type. - BulletStyle = 40002u32, + BulletStyle = 40002i32, /// Identifies the CapStyle text attribute, which specifies the capitalization style for the text. This attribute is specified as a value from the CapStyle enumerated type. - CapStyle = 40003u32, + CapStyle = 40003i32, /// Identifies the Culture text attribute, which specifies the locale of the text by locale identifier (LCID). - Culture = 40004u32, + Culture = 40004i32, /// Identifies the FontName text attribute, which specifies the name of the font. Examples: Arial Black; Arial Narrow. The font name string is not localized. - FontName = 40005u32, + FontName = 40005i32, /// Identifies the FontSize text attribute, which specifies the point size of the font. - FontSize = 40006u32, + FontSize = 40006i32, /// Identifies the FontWeight text attribute, which specifies the relative stroke, thickness, or boldness of the font. The FontWeight attribute is modeled after the lfWeight member of the GDI LOGFONT structure, and related standards, and can be one of the following values: - FontWeight = 40007u32, + FontWeight = 40007i32, /// Identifies the ForegroundColor text attribute, which specifies the foreground color of the text. This attribute is specified as a COLORREF, a 32-bit value used to specify an RGB or RGBA color. - ForegroundColor = 40008u32, + ForegroundColor = 40008i32, /// Identifies the HorizontalTextAlignment text attribute, which specifies how the text is aligned horizontally. This attribute is specified as a value from the HorizontalTextAlignmentEnum enumerated type. - HorizontalTextAlignment = 40009u32, + HorizontalTextAlignment = 40009i32, /// Identifies the IndentationFirstLine text attribute, which specifies how far, in points, to indent the first line of a paragraph. - IndentationFirstLine = 40010u32, + IndentationFirstLine = 40010i32, /// Identifies the IndentationLeading text attribute, which specifies the leading indentation, in points. - IndentationLeading = 40011u32, + IndentationLeading = 40011i32, /// Identifies the IndentationTrailing text attribute, which specifies the trailing indentation, in points. - IndentationTrailing = 40012u32, + IndentationTrailing = 40012i32, /// Identifies the IsHidden text attribute, which indicates whether the text is hidden (TRUE) or visible (FALSE). - IsHidden = 40013u32, + IsHidden = 40013i32, /// Identifies the IsItalic text attribute, which indicates whether the text is italic (TRUE) or not (FALSE). - IsItalic = 40014u32, + IsItalic = 40014i32, /// Identifies the IsReadOnly text attribute, which indicates whether the text is read-only (TRUE) or can be modified (FALSE). - IsReadOnly = 40015u32, + IsReadOnly = 40015i32, /// Identifies the IsSubscript text attribute, which indicates whether the text is subscript (TRUE) or not (FALSE). - IsSubscript = 40016u32, + IsSubscript = 40016i32, /// Identifies the IsSuperscript text attribute, which indicates whether the text is subscript (TRUE) or not (FALSE). - IsSuperscript = 40017u32, + IsSuperscript = 40017i32, /// Identifies the MarginBottom text attribute, which specifies the size, in points, of the bottom margin applied to the page associated with the text range. - MarginBottom = 40018u32, + MarginBottom = 40018i32, /// Identifies the MarginLeading text attribute, which specifies the size, in points, of the leading margin applied to the page associated with the text range. - MarginLeading = 40019u32, + MarginLeading = 40019i32, /// Identifies the MarginTop text attribute, which specifies the size, in points, of the top margin applied to the page associated with the text range. - MarginTop = 40020u32, + MarginTop = 40020i32, /// Identifies the MarginTrailing text attribute, which specifies the size, in points, of the trailing margin applied to the page associated with the text range. - MarginTrailing = 40021u32, + MarginTrailing = 40021i32, /// Identifies the OutlineStyles text attribute, which specifies the outline style of the text. This attribute is specified as a value from the OutlineStyles enumerated type. - OutlineStyles = 40022u32, + OutlineStyles = 40022i32, /// Identifies the OverlineColor text attribute, which specifies the color of the overline text decoration. This attribute is specified as a COLORREF, a 32-bit value used to specify an RGB or RGBA color. - OverlineColor = 40023u32, + OverlineColor = 40023i32, /// Identifies the OverlineStyle text attribute, which specifies the style of the overline text decoration. This attribute is specified as a value from the TextDecorationLineStyleEnum enumerated type. - OverlineStyle = 40024u32, + OverlineStyle = 40024i32, /// Identifies the StrikethroughColor text attribute, which specifies the color of the strikethrough text decoration. This attribute is specified as a COLORREF, a 32-bit value used to specify an RGB or RGBA color. - StrikethroughColor = 40025u32, + StrikethroughColor = 40025i32, /// Identifies the StrikethroughStyle text attribute, which specifies the style of the strikethrough text decoration. This attribute is specified as a value from the TextDecorationLineStyleEnum enumerated type. - StrikethroughStyle = 40026u32, + StrikethroughStyle = 40026i32, /// Identifies the Tabs text attribute, which is an array specifying the tab stops for the text range. Each array element specifies a distance, in points, from the leading margin. - Tabs = 40027u32, + Tabs = 40027i32, /// Identifies the TextFlowDirections text attribute, which specifies the direction of text flow. This attribute is specified as a combination of values from the FlowDirections enumerated type. - TextFlowDirections = 40028u32, + TextFlowDirections = 40028i32, /// Identifies the UnderlineColor text attribute, which specifies the color of the underline text decoration. This attribute is specified as a COLORREF, a 32-bit value used to specify an RGB or RGBA color. - UnderlineColor = 40029u32, + UnderlineColor = 40029i32, /// Identifies the UnderlineStyle text attribute, which specifies the style of the underline text decoration. This attribute is specified as a value from the TextDecorationLineStyleEnum enumerated type. - UnderlineStyle = 40030u32, + UnderlineStyle = 40030i32, /// Identifies the AnnotationTypes text attribute, which maintains a list of annotation type identifiers for a range of text. For a list of possible values, see Annotation Type Identifiers. Supported starting with Windows 8. - AnnotationTypes = 40031u32, + AnnotationTypes = 40031i32, /// Identifies the AnnotationObjects text attribute, which maintains an array of IUIAutomationElement2 interfaces, one for each element in the current text range that implements the Annotation control pattern. Each element might also implement other control patterns as needed to describe the annotation. For example, an annotation that is a comment would also support the Text control pattern. Supported starting with Windows 8. - AnnotationObjects = 40032u32, + AnnotationObjects = 40032i32, /// Identifies the StyleName text attribute, which identifies the localized name of the text style in use for a text range. Supported starting with Windows 8. - StyleName = 40033u32, + StyleName = 40033i32, /// Identifies the StyleId text attribute, which indicates the text styles in use for a text range. For a list of possible values, see Style Identifiers. Supported starting with Windows 8. - StyleId = 40034u32, + StyleId = 40034i32, /// Identifies the Link text attribute, which contains the IUIAutomationTextRange interface of the text range that is the target of an internal link in a document. Supported starting with Windows 8. - Link = 40035u32, + Link = 40035i32, /// Identifies the IsActive text attribute, which indicates whether the control that contains the text range has the keyboard focus (TRUE) or not (FALSE). Supported starting with Windows 8. - IsActive = 40036u32, + IsActive = 40036i32, /// Identifies the SelectionActiveEnd text attribute, which indicates the location of the caret relative to a text range that represents the currently selected text. This attribute is specified as a value from the ActiveEnd enumeration. Supported starting with Windows 8. - SelectionActiveEnd = 40037u32, + SelectionActiveEnd = 40037i32, /// Identifies the CaretPosition text attribute, which indicates whether the caret is at the beginning or the end of a line of text in the text range. This attribute is specified as a value from the CaretPosition enumerated type. Supported starting with Windows 8. - CaretPosition = 40038u32, + CaretPosition = 40038i32, /// Identifies the CaretBidiMode text attribute, which indicates the direction of text flow in the text range. This attribute is specified as a value from the CaretBidiMode enumerated type. Supported starting with Windows 8. - CaretBidiMode = 40039u32, + CaretBidiMode = 40039i32, /// Identifies the LineSpacing text attribute, which specifies the spacing between lines of text. - LineSpacing = 40040u32, + LineSpacing = 40040i32, /// Identifies the BeforeParagraphSpacing text attribute, which specifies the size of spacing before the paragraph. - BeforeParagraphSpacing = 40041u32, + BeforeParagraphSpacing = 40041i32, /// Identifies the AfterParagraphSpacing text attribute, which specifies the size of spacing after the paragraph. - AfterParagraphSpacing = 40042u32, + AfterParagraphSpacing = 40042i32, } #[cfg(test)] diff --git a/crates/uiautomation/src/variants.rs b/crates/uiautomation/src/variants.rs index ef46b81..95efa59 100644 --- a/crates/uiautomation/src/variants.rs +++ b/crates/uiautomation/src/variants.rs @@ -162,7 +162,7 @@ impl Variant { /// Retrieve the variant type. fn vt(&self) -> VARENUM { let val = self.value.as_raw(); - VARENUM(val.Anonymous.Anonymous.vt) + unsafe { VARENUM(val.Anonymous.Anonymous.vt) } // unsafe { // self.value.Anonymous.Anonymous.vt //as i32 // } @@ -392,6 +392,12 @@ impl Display for Variant { } } +impl windows::core::IntoParam for Variant { + unsafe fn into_param(self) -> windows::core::Param { + windows::core::Param::Owned(self.value) + } +} + macro_rules! val_to_variant { ($v: expr) => { { From 953c62a7ca7aaa8fb3d84fac883ad4ca26dd5112 Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Thu, 14 Mar 2024 21:20:42 +0800 Subject: [PATCH 14/15] updated to windows 0.54!! --- crates/uiautomation/src/core.rs | 2 +- crates/uiautomation/src/variants.rs | 60 ++++++++++++++++------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/crates/uiautomation/src/core.rs b/crates/uiautomation/src/core.rs index f4b52f1..af853a2 100644 --- a/crates/uiautomation/src/core.rs +++ b/crates/uiautomation/src/core.rs @@ -630,7 +630,7 @@ impl UIElement { /// Retrieves a point on the element that can be clicked. pub fn get_clickable_point(&self) -> Result> { let mut point = Point::default(); - let mut got = unsafe { + let got = unsafe { self.element.GetClickablePoint(point.as_mut())? }; diff --git a/crates/uiautomation/src/variants.rs b/crates/uiautomation/src/variants.rs index 95efa59..5967fe9 100644 --- a/crates/uiautomation/src/variants.rs +++ b/crates/uiautomation/src/variants.rs @@ -123,6 +123,11 @@ pub struct Variant { impl Variant { /// Create a null variant. fn new_null(vt: VARENUM) -> Variant { + let mut var: imp::VARIANT = unsafe { std::mem::zeroed() }; + var.Anonymous.Anonymous.vt = vt.0; + + let variant = unsafe { VARIANT::from_raw(var) }; + // let mut val = VARIANT_0_0::default(); // val.vt = vt; // vt.0 as u16; @@ -131,9 +136,9 @@ impl Variant { // Anonymous: ManuallyDrop::new(val) // } // }; - let variant = VARIANT::default(); - let val = variant.as_raw(); - val.Anonymous.Anonymous.vt = vt.0; + // let variant = VARIANT::default(); + // let val = variant.as_raw(); + // val.Anonymous.Anonymous.vt = vt.0; variant.into() } @@ -151,11 +156,13 @@ impl Variant { // }) // } // }; - let variant = VARIANT::default(); - let val = variant.as_raw(); + // let variant = VARIANT::default(); + let mut val: imp::VARIANT = unsafe { std::mem::zeroed() }; val.Anonymous.Anonymous.vt = vt.0; val.Anonymous.Anonymous.Anonymous = value; + let variant = unsafe { VARIANT::from_raw(val) }; + variant.into() } @@ -178,17 +185,17 @@ impl Variant { pub(crate) fn get_data(&self) -> &imp::VARIANT_0_0_0 { // &self.value.Anonymous.Anonymous.Anonymous let var = self.value.as_raw(); - &var.Anonymous.Anonymous.Anonymous + unsafe { &var.Anonymous.Anonymous.Anonymous } } fn as_bool(&self) -> VARIANT_BOOL { - VARIANT_BOOL(self.get_data().boolVal) + unsafe { VARIANT_BOOL(self.get_data().boolVal) } } fn as_decimal(&self) -> DECIMAL { - let d = self.get_data().pdecVal; - unsafe { + let d = self.get_data().pdecVal; + DECIMAL { wReserved: (*d).wReserved, Anonymous1: windows::Win32::Foundation::DECIMAL_0 { signscale: (*d).Anonymous1.signscale }, @@ -199,7 +206,9 @@ impl Variant { } fn as_currency(&self) -> CY { - CY { int64: self.get_data().cyVal.int64 } + CY { + int64: unsafe { self.get_data().cyVal.int64 } + } } /// Try to get value. @@ -446,9 +455,9 @@ macro_rules! to_decimal_imp { ($d: expr) => { imp::DECIMAL { wReserved: $d.wReserved, - Anonymous1: imp::DECIMAL_0 { signscale: $d.Anonymous1.signscale }, + Anonymous1: imp::DECIMAL_0 { signscale: unsafe { $d.Anonymous1.signscale } }, Hi32: $d.Hi32, - Anonymous2: imp::DECIMAL_1 { Lo64: $d.Anonymous2.Lo64 } + Anonymous2: imp::DECIMAL_1 { Lo64: unsafe { $d.Anonymous2.Lo64 } } } }; } @@ -479,7 +488,7 @@ impl From for Variant { Value::ERROR(v) => Variant::new(VT_ERROR, imp::VARIANT_0_0_0 { intVal: v.0 }), Value::HRESULT(v) => Variant::new(VT_HRESULT, imp::VARIANT_0_0_0 { intVal: v.0 }), Value::BOOL(v) => val_to_variant!(v), // Variant::new(VT_BOOL, imp::VARIANT_0_0_0 { boolVal: v.into() }), - Value::VARIANT(mut v) => { + Value::VARIANT(v) => { let mut val = imp::VARIANT { Anonymous: v.value.as_raw().Anonymous }; @@ -658,10 +667,10 @@ impl TryInto for &Variant { // Value::NULL // } // }; - let val = if self.get_data().ppdispVal.is_null() { - Value::NULL + let val = if let Ok(disp) = IDispatch::try_from(&self.value) { + Value::DISPATCH(disp) } else { - Value::DISPATCH(IDispatch::try_from(&self.value)?) + Value::NULL }; Ok(val) } else if vt == VT_UNKNOWN { @@ -673,10 +682,10 @@ impl TryInto for &Variant { // } // }; // Ok(val) - let val = if self.get_data().ppunkVal.is_null() { - Value::NULL + let val = if let Ok(unk) = IUnknown::try_from(&self.value) { + Value::UNKNOWN(unk) } else { - Value::UNKNOWN(IUnknown::try_from(&self.value)?) + Value::NULL }; Ok(val) } else if vt == VT_ERROR { @@ -695,20 +704,17 @@ impl TryInto for &Variant { }; Ok(Value::BOOL(val)) } else if vt == VT_VARIANT { - // let val = unsafe { - // (*self.get_data().pvarVal).clone() - // }; - let val = VARIANT::default(); - unsafe { - val.as_raw().Anonymous = (*self.get_data().pvarVal).Anonymous; - } + let val = unsafe { + let v = (*self.get_data().pvarVal).clone(); + VARIANT::from_raw(v) + }; Ok(Value::VARIANT(val.into())) } else if vt == VT_DECIMAL { // let val = unsafe { // (*self.get_data().pdecVal).clone() // }; - let d = self.get_data().pdecVal; + // let d = self.get_data().pdecVal; // let val = unsafe { // DECIMAL { // wReserved: (*d).wReserved, From 921af61321f8c38b97707699326ef0388dfaaf8a Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Thu, 14 Mar 2024 21:24:40 +0800 Subject: [PATCH 15/15] refactor --- samples/win_update/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/win_update/Cargo.toml b/samples/win_update/Cargo.toml index a225f43..de402f9 100644 --- a/samples/win_update/Cargo.toml +++ b/samples/win_update/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "win-update" -version = "1.6.2" +version = "1.6.3" edition = "2021" [dependencies]