diff --git a/crates/libs/bindgen/src/types/delegate.rs b/crates/libs/bindgen/src/types/delegate.rs index f0134f4eb89..6be0361dd9a 100644 --- a/crates/libs/bindgen/src/types/delegate.rs +++ b/crates/libs/bindgen/src/types/delegate.rs @@ -176,6 +176,12 @@ impl Delegate { } } } + #cfg + impl<#constraints #fn_constraint> From> for #name { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } + } } } diff --git a/crates/libs/core/src/param.rs b/crates/libs/core/src/param.rs index 5ebf3add08f..a18ebb5efa9 100644 --- a/crates/libs/core/src/param.rs +++ b/crates/libs/core/src/param.rs @@ -13,6 +13,9 @@ where unsafe fn param(self) -> ParamValue; } +/// A closure that can be used as a delegate parameter. +pub struct DelegateFn(pub F); + impl Param for Option<&T> where T: Type, @@ -74,3 +77,13 @@ where unsafe { ParamValue::Owned(transmute_copy(&self)) } } } + +impl Param for DelegateFn +where + D: Interface, + D: From>, +{ + unsafe fn param(self) -> ParamValue { + ParamValue::Owned(D::from(self)) + } +} diff --git a/crates/libs/future/src/bindings.rs b/crates/libs/future/src/bindings.rs index ca60743cdc5..76a26a69dde 100644 --- a/crates/libs/future/src/bindings.rs +++ b/crates/libs/future/src/bindings.rs @@ -128,6 +128,16 @@ impl< } } } +impl< + F: Fn(windows_core::Ref, AsyncStatus) -> windows_core::Result<()> + + Send + + 'static, + > From> for AsyncActionCompletedHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct AsyncActionProgressHandler( @@ -300,6 +310,20 @@ impl< } } } +impl< + TProgress: windows_core::RuntimeType + 'static, + F: Fn( + windows_core::Ref>, + windows_core::Ref, + ) -> windows_core::Result<()> + + Send + + 'static, + > From> for AsyncActionProgressHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct AsyncActionWithProgressCompletedHandler( @@ -455,6 +479,20 @@ impl< } } } +impl< + TProgress: windows_core::RuntimeType + 'static, + F: Fn( + windows_core::Ref>, + AsyncStatus, + ) -> windows_core::Result<()> + + Send + + 'static, + > From> for AsyncActionWithProgressCompletedHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct AsyncOperationCompletedHandler( @@ -613,6 +651,17 @@ impl< } } } +impl< + TResult: windows_core::RuntimeType + 'static, + F: Fn(windows_core::Ref>, AsyncStatus) -> windows_core::Result<()> + + Send + + 'static, + > From> for AsyncOperationCompletedHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct AsyncOperationProgressHandler( @@ -789,6 +838,21 @@ impl< } } } +impl< + TResult: windows_core::RuntimeType + 'static, + TProgress: windows_core::RuntimeType + 'static, + F: Fn( + windows_core::Ref>, + windows_core::Ref, + ) -> windows_core::Result<()> + + Send + + 'static, + > From> for AsyncOperationProgressHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct AsyncOperationWithProgressCompletedHandler( @@ -960,6 +1024,22 @@ impl< } } } +impl< + TResult: windows_core::RuntimeType + 'static, + TProgress: windows_core::RuntimeType + 'static, + F: Fn( + windows_core::Ref>, + AsyncStatus, + ) -> windows_core::Result<()> + + Send + + 'static, + > From> + for AsyncOperationWithProgressCompletedHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct AsyncStatus(pub i32); diff --git a/crates/libs/windows/src/Windows/ApplicationModel/Background/mod.rs b/crates/libs/windows/src/Windows/ApplicationModel/Background/mod.rs index 8d1f5d49282..51d11a95e87 100644 --- a/crates/libs/windows/src/Windows/ApplicationModel/Background/mod.rs +++ b/crates/libs/windows/src/Windows/ApplicationModel/Background/mod.rs @@ -653,6 +653,11 @@ impl, BackgroundTaskCancellatio } } } +impl, BackgroundTaskCancellationReason) -> windows_core::Result<()> + Send + 'static> From> for BackgroundTaskCanceledEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct BackgroundTaskCancellationReason(pub i32); @@ -782,6 +787,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for BackgroundTaskCompletedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct BackgroundTaskDeferral(windows_core::IUnknown); @@ -913,6 +923,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for BackgroundTaskProgressEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct BackgroundTaskRegistration(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/ApplicationModel/DataTransfer/mod.rs b/crates/libs/windows/src/Windows/ApplicationModel/DataTransfer/mod.rs index 465677b8eff..d4d162168c1 100644 --- a/crates/libs/windows/src/Windows/ApplicationModel/DataTransfer/mod.rs +++ b/crates/libs/windows/src/Windows/ApplicationModel/DataTransfer/mod.rs @@ -1198,6 +1198,11 @@ impl) -> windows_core::Result<()> + } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for DataProviderHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct DataProviderRequest(windows_core::IUnknown); @@ -2452,6 +2457,11 @@ impl) -> windows_core::Result<() } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for ShareProviderHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct ShareProviderOperation(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/ApplicationModel/Payments/mod.rs b/crates/libs/windows/src/Windows/ApplicationModel/Payments/mod.rs index b21f8e11f22..63efedd067d 100644 --- a/crates/libs/windows/src/Windows/ApplicationModel/Payments/mod.rs +++ b/crates/libs/windows/src/Windows/ApplicationModel/Payments/mod.rs @@ -1440,6 +1440,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for PaymentRequestChangedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct PaymentRequestChangedResult(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Data/Text/mod.rs b/crates/libs/windows/src/Windows/Data/Text/mod.rs index 95f8b93c121..cfdbb1fc8b3 100644 --- a/crates/libs/windows/src/Windows/Data/Text/mod.rs +++ b/crates/libs/windows/src/Windows/Data/Text/mod.rs @@ -399,6 +399,11 @@ impl>, windows_core::Ref>) -> windows_core::Result<()> + Send + 'static> From> for SelectableWordSegmentsTokenizingHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct SelectableWordsSegmenter(windows_core::IUnknown); @@ -1076,6 +1081,11 @@ impl>, windo } } } +impl>, windows_core::Ref>) -> windows_core::Result<()> + Send + 'static> From> for WordSegmentsTokenizingHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct WordsSegmenter(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Devices/SmartCards/mod.rs b/crates/libs/windows/src/Windows/Devices/SmartCards/mod.rs index bc8af36bae6..b6d1e7952e2 100644 --- a/crates/libs/windows/src/Windows/Devices/SmartCards/mod.rs +++ b/crates/libs/windows/src/Windows/Devices/SmartCards/mod.rs @@ -2964,6 +2964,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for SmartCardPinResetHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct SmartCardPinResetRequest(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Devices/Sms/mod.rs b/crates/libs/windows/src/Windows/Devices/Sms/mod.rs index b2ce1a66aed..e853275dd48 100644 --- a/crates/libs/windows/src/Windows/Devices/Sms/mod.rs +++ b/crates/libs/windows/src/Windows/Devices/Sms/mod.rs @@ -2048,6 +2048,11 @@ impl) -> windows_core::Result<()> + Send + 's } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for SmsDeviceStatusChangedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct SmsEncodedLength { @@ -2420,6 +2425,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for SmsMessageReceivedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct SmsMessageReceivedTriggerDetails(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Foundation/Collections/mod.rs b/crates/libs/windows/src/Windows/Foundation/Collections/mod.rs index ff3f19e5d64..b01264879d2 100644 --- a/crates/libs/windows/src/Windows/Foundation/Collections/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/Collections/mod.rs @@ -734,6 +734,11 @@ impl>, windows_core::Ref>) -> windows_core::Result<()> + Send + 'static> From> for MapChangedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct PropertySet(windows_core::IUnknown); @@ -1148,3 +1153,8 @@ impl>, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for VectorChangedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} diff --git a/crates/libs/windows/src/Windows/Foundation/mod.rs b/crates/libs/windows/src/Windows/Foundation/mod.rs index 06cb2328fbf..ed2508b623b 100644 --- a/crates/libs/windows/src/Windows/Foundation/mod.rs +++ b/crates/libs/windows/src/Windows/Foundation/mod.rs @@ -130,6 +130,11 @@ impl windows_core::Result<()> + Send + 'static> DeferralCompletedHand } } } +impl windows_core::Result<()> + Send + 'static> From> for DeferralCompletedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct EventHandler(windows_core::IUnknown, core::marker::PhantomData) @@ -226,6 +231,11 @@ impl, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for EventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} pub struct GuidHelper; impl GuidHelper { pub fn CreateNewGuid() -> windows_core::Result { @@ -2551,6 +2561,11 @@ impl, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for TypedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct Uri(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Gaming/Preview/GamesEnumeration/mod.rs b/crates/libs/windows/src/Windows/Gaming/Preview/GamesEnumeration/mod.rs index fcb49f66e81..10602add4bf 100644 --- a/crates/libs/windows/src/Windows/Gaming/Preview/GamesEnumeration/mod.rs +++ b/crates/libs/windows/src/Windows/Gaming/Preview/GamesEnumeration/mod.rs @@ -169,6 +169,11 @@ impl) -> windows_core::Result<()> + Send } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for GameListChangedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct GameListEntry(windows_core::IUnknown); @@ -376,6 +381,11 @@ impl windows_core::Result<()> + Send + 'static> } } } +impl windows_core::Result<()> + Send + 'static> From> for GameListRemovedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct GameModeConfiguration(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Graphics/Display/mod.rs b/crates/libs/windows/src/Windows/Graphics/Display/mod.rs index 3cb6bbda4db..9e9ae9a2cc0 100644 --- a/crates/libs/windows/src/Windows/Graphics/Display/mod.rs +++ b/crates/libs/windows/src/Windows/Graphics/Display/mod.rs @@ -1057,6 +1057,11 @@ impl) -> windows_core::Resul } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for DisplayPropertiesEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct DisplayServices(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Graphics/Printing/mod.rs b/crates/libs/windows/src/Windows/Graphics/Printing/mod.rs index b1f35fc5329..4ea6e034af0 100644 --- a/crates/libs/windows/src/Windows/Graphics/Printing/mod.rs +++ b/crates/libs/windows/src/Windows/Graphics/Printing/mod.rs @@ -2141,6 +2141,11 @@ impl) -> windows_core::Res } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for PrintTaskSourceRequestedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} pub struct StandardPrintTaskOptions; impl StandardPrintTaskOptions { pub fn MediaSize() -> windows_core::Result { diff --git a/crates/libs/windows/src/Windows/Graphics/Printing3D/mod.rs b/crates/libs/windows/src/Windows/Graphics/Printing3D/mod.rs index a6da4e86725..e00c335cb4c 100644 --- a/crates/libs/windows/src/Windows/Graphics/Printing3D/mod.rs +++ b/crates/libs/windows/src/Windows/Graphics/Printing3D/mod.rs @@ -921,6 +921,11 @@ impl) -> windows_core::R } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for Print3DTaskSourceRequestedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct Printing3D3MFPackage(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Management/Setup/mod.rs b/crates/libs/windows/src/Windows/Management/Setup/mod.rs index 8cabc21371f..112c2003621 100644 --- a/crates/libs/windows/src/Windows/Management/Setup/mod.rs +++ b/crates/libs/windows/src/Windows/Management/Setup/mod.rs @@ -236,6 +236,11 @@ impl) -> w } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for DeploymentSessionHeartbeatRequested { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct DeploymentSessionHeartbeatRequestedEventArgs(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Media/Capture/mod.rs b/crates/libs/windows/src/Windows/Media/Capture/mod.rs index ff133578f78..341b5787a74 100644 --- a/crates/libs/windows/src/Windows/Media/Capture/mod.rs +++ b/crates/libs/windows/src/Windows/Media/Capture/mod.rs @@ -7131,6 +7131,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for MediaCaptureFailedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct MediaCaptureFocusChangedEventArgs(windows_core::IUnknown); @@ -8081,6 +8086,11 @@ impl) -> windows_core::Result<()> + Send + } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for RecordLimitationExceededEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct StreamingCaptureMode(pub i32); diff --git a/crates/libs/windows/src/Windows/Media/Devices/mod.rs b/crates/libs/windows/src/Windows/Media/Devices/mod.rs index ee306e34933..837bd08954e 100644 --- a/crates/libs/windows/src/Windows/Media/Devices/mod.rs +++ b/crates/libs/windows/src/Windows/Media/Devices/mod.rs @@ -572,6 +572,11 @@ impl) -> windows_core::Result<()> + Send + } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for CallControlEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct CameraOcclusionInfo(windows_core::IUnknown); @@ -930,6 +935,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for DialRequestedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct DigitalWindowBounds(windows_core::IUnknown); @@ -3193,6 +3203,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for KeypadPressedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct LowLagPhotoControl(windows_core::IUnknown); @@ -3896,6 +3911,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for RedialRequestedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct RegionOfInterest(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/Media/Protection/mod.rs b/crates/libs/windows/src/Windows/Media/Protection/mod.rs index 57f34108379..784eef6357d 100644 --- a/crates/libs/windows/src/Windows/Media/Protection/mod.rs +++ b/crates/libs/windows/src/Windows/Media/Protection/mod.rs @@ -109,6 +109,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for ComponentLoadFailedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} pub struct ComponentRenewal; impl ComponentRenewal { pub fn RenewSystemComponentsAsync(information: P0) -> windows_core::Result> @@ -717,6 +722,11 @@ impl) -> windows_core::Result<() } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for RebootNeededEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct RenewalStatus(pub i32); @@ -987,3 +997,8 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for ServiceRequestedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} diff --git a/crates/libs/windows/src/Windows/Networking/Connectivity/mod.rs b/crates/libs/windows/src/Windows/Networking/Connectivity/mod.rs index d5ee1e1f263..f7201f33e32 100644 --- a/crates/libs/windows/src/Windows/Networking/Connectivity/mod.rs +++ b/crates/libs/windows/src/Windows/Networking/Connectivity/mod.rs @@ -1839,6 +1839,11 @@ impl) -> windows_core::Resul } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for NetworkStatusChangedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct NetworkTypes(pub u32); diff --git a/crates/libs/windows/src/Windows/Networking/Proximity/mod.rs b/crates/libs/windows/src/Windows/Networking/Proximity/mod.rs index 6adb74d9c7c..83b0da1e91e 100644 --- a/crates/libs/windows/src/Windows/Networking/Proximity/mod.rs +++ b/crates/libs/windows/src/Windows/Networking/Proximity/mod.rs @@ -99,6 +99,11 @@ impl) -> windows_core::Result<()> + Sen } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for DeviceArrivedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(DeviceDepartedEventHandler, DeviceDepartedEventHandler_Vtbl, 0xefa9da69_f6e2_49c9_a49e_8e0fc58fb911); impl windows_core::RuntimeType for DeviceDepartedEventHandler { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -175,6 +180,11 @@ impl) -> windows_core::Result<()> + Sen } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for DeviceDepartedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(IConnectionRequestedEventArgs, IConnectionRequestedEventArgs_Vtbl, 0xeb6891ae_4f1e_4c66_bd0d_46924a942e08); impl windows_core::RuntimeType for IConnectionRequestedEventArgs { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -444,6 +454,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for MessageReceivedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(MessageTransmittedHandler, MessageTransmittedHandler_Vtbl, 0xefaa0b4a_f6e2_4d7d_856c_78fc8efc021e); impl windows_core::RuntimeType for MessageTransmittedHandler { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -520,6 +535,11 @@ impl, i64) -> windows_core::Result<()> } } } +impl, i64) -> windows_core::Result<()> + Send + 'static> From> for MessageTransmittedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct PeerDiscoveryTypes(pub u32); diff --git a/crates/libs/windows/src/Windows/Security/Credentials/mod.rs b/crates/libs/windows/src/Windows/Security/Credentials/mod.rs index 8671a258627..98e8e53eb8e 100644 --- a/crates/libs/windows/src/Windows/Security/Credentials/mod.rs +++ b/crates/libs/windows/src/Windows/Security/Credentials/mod.rs @@ -92,6 +92,12 @@ impl) -> window } } } +#[cfg(feature = "Storage_Streams")] +impl) -> windows_core::Result + Send + 'static> From> for AttestationChallengeHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct ChallengeResponseKind(pub i32); diff --git a/crates/libs/windows/src/Windows/Security/Isolation/mod.rs b/crates/libs/windows/src/Windows/Security/Isolation/mod.rs index 710f8c4d868..30e03f38a45 100644 --- a/crates/libs/windows/src/Windows/Security/Isolation/mod.rs +++ b/crates/libs/windows/src/Windows/Security/Isolation/mod.rs @@ -74,6 +74,11 @@ impl>) -> windows_core::Result<()> + Send + 'static> From> for HostMessageReceivedCallback { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(IIsolatedWindowsEnvironment, IIsolatedWindowsEnvironment_Vtbl, 0x41d24597_c328_4467_b37f_4dfc6f60b6bc); impl windows_core::RuntimeType for IIsolatedWindowsEnvironment { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -1864,3 +1869,8 @@ impl>) -> windows_core::Result<()> + Send + 'static> From> for MessageReceivedCallback { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} diff --git a/crates/libs/windows/src/Windows/Storage/Provider/mod.rs b/crates/libs/windows/src/Windows/Storage/Provider/mod.rs index 07ac15aab55..df90b4af610 100644 --- a/crates/libs/windows/src/Windows/Storage/Provider/mod.rs +++ b/crates/libs/windows/src/Windows/Storage/Provider/mod.rs @@ -2548,6 +2548,11 @@ impl) -> wind } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for StorageProviderKnownFolderSyncRequestedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct StorageProviderKnownFolderSyncStatus(pub i32); diff --git a/crates/libs/windows/src/Windows/Storage/mod.rs b/crates/libs/windows/src/Windows/Storage/mod.rs index ec429b8e7ea..b31f7a4abb1 100644 --- a/crates/libs/windows/src/Windows/Storage/mod.rs +++ b/crates/libs/windows/src/Windows/Storage/mod.rs @@ -684,6 +684,11 @@ impl) -> windows_core::Result<()> + S } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for ApplicationDataSetVersionHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} pub struct CachedFileManager; impl CachedFileManager { #[cfg(feature = "Storage_Streams")] @@ -5768,6 +5773,12 @@ impl) -> windows_core::Result<( } } } +#[cfg(feature = "Storage_Streams")] +impl) -> windows_core::Result<()> + Send + 'static> From> for StreamedFileDataRequestedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct StreamedFileFailureMode(pub i32); diff --git a/crates/libs/windows/src/Windows/System/RemoteDesktop/Input/mod.rs b/crates/libs/windows/src/Windows/System/RemoteDesktop/Input/mod.rs index 4fa40458e1b..0b989334b1a 100644 --- a/crates/libs/windows/src/Windows/System/RemoteDesktop/Input/mod.rs +++ b/crates/libs/windows/src/Windows/System/RemoteDesktop/Input/mod.rs @@ -249,6 +249,11 @@ impl windows_core::Result + Send + 'static> RemoteTextConn } } } +impl windows_core::Result + Send + 'static> From> for RemoteTextConnectionDataHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct RemoteTextConnectionOptions(pub u32); diff --git a/crates/libs/windows/src/Windows/System/Threading/Core/mod.rs b/crates/libs/windows/src/Windows/System/Threading/Core/mod.rs index cd917f7305a..154d97b4141 100644 --- a/crates/libs/windows/src/Windows/System/Threading/Core/mod.rs +++ b/crates/libs/windows/src/Windows/System/Threading/Core/mod.rs @@ -176,6 +176,11 @@ impl, bool) -> windows_core::Result<()> } } } +impl, bool) -> windows_core::Result<()> + Send + 'static> From> for SignalHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct SignalNotifier(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/System/Threading/mod.rs b/crates/libs/windows/src/Windows/System/Threading/mod.rs index 4b9c069cf5e..ebf8a93490b 100644 --- a/crates/libs/windows/src/Windows/System/Threading/mod.rs +++ b/crates/libs/windows/src/Windows/System/Threading/mod.rs @@ -228,6 +228,11 @@ impl) -> windows_core::Result<()> + Sen } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for TimerDestroyedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(TimerElapsedHandler, TimerElapsedHandler_Vtbl, 0xfaaea667_fbeb_49cb_adb2_71184c556e43); impl windows_core::RuntimeType for TimerElapsedHandler { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -304,6 +309,11 @@ impl) -> windows_core::Result<()> + Sen } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for TimerElapsedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(WorkItemHandler, WorkItemHandler_Vtbl, 0x1d1a8b8b_fa66_414f_9cbd_b65fc99d17fa); impl windows_core::RuntimeType for WorkItemHandler { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -380,6 +390,11 @@ impl) -> windows_core::Res } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for WorkItemHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct WorkItemOptions(pub u32); diff --git a/crates/libs/windows/src/Windows/System/mod.rs b/crates/libs/windows/src/Windows/System/mod.rs index e065f806dea..fef473ac515 100644 --- a/crates/libs/windows/src/Windows/System/mod.rs +++ b/crates/libs/windows/src/Windows/System/mod.rs @@ -1270,6 +1270,11 @@ impl windows_core::Result<()> + Send + 'static> DispatcherQueueHandle } } } +impl windows_core::Result<()> + Send + 'static> From> for DispatcherQueueHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct DispatcherQueuePriority(pub i32); diff --git a/crates/libs/windows/src/Windows/UI/ApplicationSettings/mod.rs b/crates/libs/windows/src/Windows/UI/ApplicationSettings/mod.rs index 794fed4a64a..7bdeb73c7b2 100644 --- a/crates/libs/windows/src/Windows/UI/ApplicationSettings/mod.rs +++ b/crates/libs/windows/src/Windows/UI/ApplicationSettings/mod.rs @@ -304,6 +304,11 @@ impl) -> windows_core::Result<()> + S } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for CredentialCommandCredentialDeletedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(IAccountsSettingsPane, IAccountsSettingsPane_Vtbl, 0x81ea942c_4f09_4406_a538_838d9b14b7e6); impl windows_core::RuntimeType for IAccountsSettingsPane { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -954,6 +959,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for WebAccountCommandInvokedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct WebAccountInvokedArgs(windows_core::IUnknown); @@ -1099,3 +1109,8 @@ impl) -> windows_core::Result } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for WebAccountProviderCommandInvokedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} diff --git a/crates/libs/windows/src/Windows/UI/Core/mod.rs b/crates/libs/windows/src/Windows/UI/Core/mod.rs index 9322826d84b..f67d6abc277 100644 --- a/crates/libs/windows/src/Windows/UI/Core/mod.rs +++ b/crates/libs/windows/src/Windows/UI/Core/mod.rs @@ -2271,6 +2271,11 @@ impl windows_core::Result<()> + Send + 'static> DispatchedHandlerBox< } } } +impl windows_core::Result<()> + Send + 'static> From> for DispatchedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(IAcceleratorKeyEventArgs, IAcceleratorKeyEventArgs_Vtbl, 0xff1c4c4a_9287_470b_836e_9086e3126ade); impl windows_core::RuntimeType for IAcceleratorKeyEventArgs { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -4973,6 +4978,11 @@ impl) -> windows_core::Result } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for IdleDispatchedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct IdleDispatchedHandlerArgs(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/UI/Popups/mod.rs b/crates/libs/windows/src/Windows/UI/Popups/mod.rs index a27cc45b6e3..65bd577cce0 100644 --- a/crates/libs/windows/src/Windows/UI/Popups/mod.rs +++ b/crates/libs/windows/src/Windows/UI/Popups/mod.rs @@ -579,6 +579,11 @@ impl) -> windows_core::Result<()> + Send + ' } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for UICommandInvokedHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct UICommandSeparator(windows_core::IUnknown); diff --git a/crates/libs/windows/src/Windows/UI/WebUI/mod.rs b/crates/libs/windows/src/Windows/UI/WebUI/mod.rs index 7fed3588e26..ff67a4754a5 100644 --- a/crates/libs/windows/src/Windows/UI/WebUI/mod.rs +++ b/crates/libs/windows/src/Windows/UI/WebUI/mod.rs @@ -101,6 +101,12 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for ActivatedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct ActivatedOperation(windows_core::IUnknown); @@ -241,6 +247,12 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for BackgroundActivatedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[cfg(feature = "ApplicationModel")] #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] @@ -357,6 +369,12 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for EnteredBackgroundEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[cfg(feature = "Graphics_Printing")] #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] @@ -983,6 +1001,12 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for LeavingBackgroundEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!(NavigatedEventHandler, NavigatedEventHandler_Vtbl, 0x7af46fe6_40ca_4e49_a7d6_dbdb330cd1a3); impl windows_core::RuntimeType for NavigatedEventHandler { const SIGNATURE: windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::for_interface::(); @@ -1060,6 +1084,11 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for NavigatedEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct NewWebUIViewCreatedEventArgs(windows_core::IUnknown); @@ -1197,6 +1226,11 @@ impl) -> windows_core::Resul } } } +impl) -> windows_core::Result<()> + Send + 'static> From> for ResumingEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[cfg(feature = "ApplicationModel")] #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] @@ -1336,6 +1370,12 @@ impl, windows_core::Ref, windows_core::Ref) -> windows_core::Result<()> + Send + 'static> From> for SuspendingEventHandler { + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} +#[cfg(feature = "ApplicationModel")] #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct SuspendingOperation(windows_core::IUnknown); diff --git a/crates/tests/libs/bindgen/src/class_with_handler.rs b/crates/tests/libs/bindgen/src/class_with_handler.rs index 11771f5240a..6a26164edc4 100644 --- a/crates/tests/libs/bindgen/src/class_with_handler.rs +++ b/crates/tests/libs/bindgen/src/class_with_handler.rs @@ -167,6 +167,13 @@ impl windows_core::Result<()> + Send + 'static> DeferralCompletedHand } } } +impl windows_core::Result<()> + Send + 'static> From> + for DeferralCompletedHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} windows_core::imp::define_interface!( IClosable, IClosable_Vtbl, diff --git a/crates/tests/libs/bindgen/src/delegate.rs b/crates/tests/libs/bindgen/src/delegate.rs index 3a5649e95b8..e6b6a241b3d 100644 --- a/crates/tests/libs/bindgen/src/delegate.rs +++ b/crates/tests/libs/bindgen/src/delegate.rs @@ -108,3 +108,10 @@ impl windows_core::Result<()> + Send + 'static> DeferralCompletedHand } } } +impl windows_core::Result<()> + Send + 'static> From> + for DeferralCompletedHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} diff --git a/crates/tests/libs/bindgen/src/delegate_generic.rs b/crates/tests/libs/bindgen/src/delegate_generic.rs index eb5250db2ea..488ff92dcbd 100644 --- a/crates/tests/libs/bindgen/src/delegate_generic.rs +++ b/crates/tests/libs/bindgen/src/delegate_generic.rs @@ -169,3 +169,17 @@ impl< } } } +impl< + T: windows_core::RuntimeType + 'static, + F: Fn( + windows_core::Ref, + windows_core::Ref, + ) -> windows_core::Result<()> + + Send + + 'static, + > From> for EventHandler +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} diff --git a/crates/tests/misc/component/src/bindings.rs b/crates/tests/misc/component/src/bindings.rs index e1f85da719b..7830eb72728 100644 --- a/crates/tests/misc/component/src/bindings.rs +++ b/crates/tests/misc/component/src/bindings.rs @@ -127,6 +127,13 @@ impl windows_core::Result + Send + 'static> CallbackBox { } } } +impl windows_core::Result + Send + 'static> From> + for Callback +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct Class(windows_core::IUnknown); diff --git a/crates/tests/misc/component_client/src/bindings.rs b/crates/tests/misc/component_client/src/bindings.rs index 4f5f7da14f9..8ffb89719cb 100644 --- a/crates/tests/misc/component_client/src/bindings.rs +++ b/crates/tests/misc/component_client/src/bindings.rs @@ -127,6 +127,13 @@ impl windows_core::Result + Send + 'static> CallbackBox { } } } +impl windows_core::Result + Send + 'static> From> + for Callback +{ + fn from(value: windows_core::DelegateFn) -> Self { + Self::new(value.0) + } +} #[repr(transparent)] #[derive(Clone, Debug, Eq, PartialEq)] pub struct Class(windows_core::IUnknown); diff --git a/crates/tests/winrt/old/tests/delegates.rs b/crates/tests/winrt/old/tests/delegates.rs index ae4d5cf2fc0..0778b1a2c7a 100644 --- a/crates/tests/winrt/old/tests/delegates.rs +++ b/crates/tests/winrt/old/tests/delegates.rs @@ -22,8 +22,6 @@ fn non_generic() -> windows::core::Result<()> { Ok(()) }); - // TODO: delegates are function objects (logically) and we should be able - // to call them without an explicit `invoke` method e.g. `d(args);` d.Invoke(None, AsyncStatus::Completed)?; assert!(rx.recv().unwrap()); @@ -65,12 +63,7 @@ fn event() -> windows::core::Result<()> { let (tx, rx) = std::sync::mpsc::channel(); let set_clone = set.clone(); - // TODO: Should be able to elide the delegate construction and simply say: - // set.MapChanged(|sender, args| {...})?; - set.MapChanged(&MapChangedEventHandler::< - windows::core::HSTRING, - windows::core::IInspectable, - >::new(move |_, args| { + set.MapChanged(&MapChangedEventHandler::new(move |_, args| { let args = args.as_ref().unwrap(); tx.send(true).unwrap(); let set = set_clone.clone();