Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/libs/bindgen/src/types/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ impl Delegate {
}
}
}
#cfg
impl<#constraints #fn_constraint> From<windows_core::DelegateFn<F>> for #name {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions crates/libs/core/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ where
unsafe fn param(self) -> ParamValue<T>;
}

/// A closure that can be used as a delegate parameter.
pub struct DelegateFn<F>(pub F);

impl<T> Param<T> for Option<&T>
where
T: Type<T>,
Expand Down Expand Up @@ -74,3 +77,13 @@ where
unsafe { ParamValue::Owned(transmute_copy(&self)) }
}
}

impl<D, F> Param<D> for DelegateFn<F>
where
D: Interface,
D: From<DelegateFn<F>>,
{
unsafe fn param(self) -> ParamValue<D> {
ParamValue::Owned(D::from(self))
}
}
80 changes: 80 additions & 0 deletions crates/libs/future/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ impl<
}
}
}
impl<
F: Fn(windows_core::Ref<IAsyncAction>, AsyncStatus) -> windows_core::Result<()>
+ Send
+ 'static,
> From<windows_core::DelegateFn<F>> for AsyncActionCompletedHandler
{
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AsyncActionProgressHandler<TProgress>(
Expand Down Expand Up @@ -300,6 +310,20 @@ impl<
}
}
}
impl<
TProgress: windows_core::RuntimeType + 'static,
F: Fn(
windows_core::Ref<IAsyncActionWithProgress<TProgress>>,
windows_core::Ref<TProgress>,
) -> windows_core::Result<()>
+ Send
+ 'static,
> From<windows_core::DelegateFn<F>> for AsyncActionProgressHandler<TProgress>
{
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AsyncActionWithProgressCompletedHandler<TProgress>(
Expand Down Expand Up @@ -455,6 +479,20 @@ impl<
}
}
}
impl<
TProgress: windows_core::RuntimeType + 'static,
F: Fn(
windows_core::Ref<IAsyncActionWithProgress<TProgress>>,
AsyncStatus,
) -> windows_core::Result<()>
+ Send
+ 'static,
> From<windows_core::DelegateFn<F>> for AsyncActionWithProgressCompletedHandler<TProgress>
{
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AsyncOperationCompletedHandler<TResult>(
Expand Down Expand Up @@ -613,6 +651,17 @@ impl<
}
}
}
impl<
TResult: windows_core::RuntimeType + 'static,
F: Fn(windows_core::Ref<IAsyncOperation<TResult>>, AsyncStatus) -> windows_core::Result<()>
+ Send
+ 'static,
> From<windows_core::DelegateFn<F>> for AsyncOperationCompletedHandler<TResult>
{
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AsyncOperationProgressHandler<TResult, TProgress>(
Expand Down Expand Up @@ -789,6 +838,21 @@ impl<
}
}
}
impl<
TResult: windows_core::RuntimeType + 'static,
TProgress: windows_core::RuntimeType + 'static,
F: Fn(
windows_core::Ref<IAsyncOperationWithProgress<TResult, TProgress>>,
windows_core::Ref<TProgress>,
) -> windows_core::Result<()>
+ Send
+ 'static,
> From<windows_core::DelegateFn<F>> for AsyncOperationProgressHandler<TResult, TProgress>
{
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AsyncOperationWithProgressCompletedHandler<TResult, TProgress>(
Expand Down Expand Up @@ -960,6 +1024,22 @@ impl<
}
}
}
impl<
TResult: windows_core::RuntimeType + 'static,
TProgress: windows_core::RuntimeType + 'static,
F: Fn(
windows_core::Ref<IAsyncOperationWithProgress<TResult, TProgress>>,
AsyncStatus,
) -> windows_core::Result<()>
+ Send
+ 'static,
> From<windows_core::DelegateFn<F>>
for AsyncOperationWithProgressCompletedHandler<TResult, TProgress>
{
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct AsyncStatus(pub i32);
Expand Down
15 changes: 15 additions & 0 deletions crates/libs/windows/src/Windows/ApplicationModel/Background/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ impl<F: Fn(windows_core::Ref<IBackgroundTaskInstance>, BackgroundTaskCancellatio
}
}
}
impl<F: Fn(windows_core::Ref<IBackgroundTaskInstance>, BackgroundTaskCancellationReason) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for BackgroundTaskCanceledEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct BackgroundTaskCancellationReason(pub i32);
Expand Down Expand Up @@ -782,6 +787,11 @@ impl<F: Fn(windows_core::Ref<BackgroundTaskRegistration>, windows_core::Ref<Back
}
}
}
impl<F: Fn(windows_core::Ref<BackgroundTaskRegistration>, windows_core::Ref<BackgroundTaskCompletedEventArgs>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for BackgroundTaskCompletedEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BackgroundTaskDeferral(windows_core::IUnknown);
Expand Down Expand Up @@ -913,6 +923,11 @@ impl<F: Fn(windows_core::Ref<BackgroundTaskRegistration>, windows_core::Ref<Back
}
}
}
impl<F: Fn(windows_core::Ref<BackgroundTaskRegistration>, windows_core::Ref<BackgroundTaskProgressEventArgs>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for BackgroundTaskProgressEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BackgroundTaskRegistration(windows_core::IUnknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,11 @@ impl<F: Fn(windows_core::Ref<DataProviderRequest>) -> windows_core::Result<()> +
}
}
}
impl<F: Fn(windows_core::Ref<DataProviderRequest>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for DataProviderHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DataProviderRequest(windows_core::IUnknown);
Expand Down Expand Up @@ -2452,6 +2457,11 @@ impl<F: Fn(windows_core::Ref<ShareProviderOperation>) -> windows_core::Result<()
}
}
}
impl<F: Fn(windows_core::Ref<ShareProviderOperation>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for ShareProviderHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ShareProviderOperation(windows_core::IUnknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,11 @@ impl<F: Fn(windows_core::Ref<PaymentRequest>, windows_core::Ref<PaymentRequestCh
}
}
}
impl<F: Fn(windows_core::Ref<PaymentRequest>, windows_core::Ref<PaymentRequestChangedArgs>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for PaymentRequestChangedHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PaymentRequestChangedResult(windows_core::IUnknown);
Expand Down
10 changes: 10 additions & 0 deletions crates/libs/windows/src/Windows/Data/Text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ impl<F: Fn(windows_core::Ref<windows_collections::IIterable<SelectableWordSegmen
}
}
}
impl<F: Fn(windows_core::Ref<windows_collections::IIterable<SelectableWordSegment>>, windows_core::Ref<windows_collections::IIterable<SelectableWordSegment>>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for SelectableWordSegmentsTokenizingHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SelectableWordsSegmenter(windows_core::IUnknown);
Expand Down Expand Up @@ -1076,6 +1081,11 @@ impl<F: Fn(windows_core::Ref<windows_collections::IIterable<WordSegment>>, windo
}
}
}
impl<F: Fn(windows_core::Ref<windows_collections::IIterable<WordSegment>>, windows_core::Ref<windows_collections::IIterable<WordSegment>>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for WordSegmentsTokenizingHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WordsSegmenter(windows_core::IUnknown);
Expand Down
5 changes: 5 additions & 0 deletions crates/libs/windows/src/Windows/Devices/SmartCards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2964,6 +2964,11 @@ impl<F: Fn(windows_core::Ref<SmartCardProvisioning>, windows_core::Ref<SmartCard
}
}
}
impl<F: Fn(windows_core::Ref<SmartCardProvisioning>, windows_core::Ref<SmartCardPinResetRequest>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for SmartCardPinResetHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SmartCardPinResetRequest(windows_core::IUnknown);
Expand Down
10 changes: 10 additions & 0 deletions crates/libs/windows/src/Windows/Devices/Sms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,11 @@ impl<F: Fn(windows_core::Ref<SmsDevice>) -> windows_core::Result<()> + Send + 's
}
}
}
impl<F: Fn(windows_core::Ref<SmsDevice>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for SmsDeviceStatusChangedEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct SmsEncodedLength {
Expand Down Expand Up @@ -2420,6 +2425,11 @@ impl<F: Fn(windows_core::Ref<SmsDevice>, windows_core::Ref<SmsMessageReceivedEve
}
}
}
impl<F: Fn(windows_core::Ref<SmsDevice>, windows_core::Ref<SmsMessageReceivedEventArgs>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for SmsMessageReceivedEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SmsMessageReceivedTriggerDetails(windows_core::IUnknown);
Expand Down
10 changes: 10 additions & 0 deletions crates/libs/windows/src/Windows/Foundation/Collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,11 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
}
}
}
impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'static, F: Fn(windows_core::Ref<IObservableMap<K, V>>, windows_core::Ref<IMapChangedEventArgs<K>>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for MapChangedEventHandler<K, V> {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PropertySet(windows_core::IUnknown);
Expand Down Expand Up @@ -1148,3 +1153,8 @@ impl<T: windows_core::RuntimeType + 'static, F: Fn(windows_core::Ref<IObservable
}
}
}
impl<T: windows_core::RuntimeType + 'static, F: Fn(windows_core::Ref<IObservableVector<T>>, windows_core::Ref<IVectorChangedEventArgs>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for VectorChangedEventHandler<T> {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
15 changes: 15 additions & 0 deletions crates/libs/windows/src/Windows/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ impl<F: Fn() -> windows_core::Result<()> + Send + 'static> DeferralCompletedHand
}
}
}
impl<F: Fn() -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for DeferralCompletedHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EventHandler<T>(windows_core::IUnknown, core::marker::PhantomData<T>)
Expand Down Expand Up @@ -226,6 +231,11 @@ impl<T: windows_core::RuntimeType + 'static, F: Fn(windows_core::Ref<windows_cor
}
}
}
impl<T: windows_core::RuntimeType + 'static, F: Fn(windows_core::Ref<windows_core::IInspectable>, windows_core::Ref<T>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for EventHandler<T> {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
pub struct GuidHelper;
impl GuidHelper {
pub fn CreateNewGuid() -> windows_core::Result<windows_core::GUID> {
Expand Down Expand Up @@ -2551,6 +2561,11 @@ impl<TSender: windows_core::RuntimeType + 'static, TResult: windows_core::Runtim
}
}
}
impl<TSender: windows_core::RuntimeType + 'static, TResult: windows_core::RuntimeType + 'static, F: Fn(windows_core::Ref<TSender>, windows_core::Ref<TResult>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for TypedEventHandler<TSender, TResult> {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Uri(windows_core::IUnknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ impl<F: Fn(windows_core::Ref<GameListEntry>) -> windows_core::Result<()> + Send
}
}
}
impl<F: Fn(windows_core::Ref<GameListEntry>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for GameListChangedEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct GameListEntry(windows_core::IUnknown);
Expand Down Expand Up @@ -376,6 +381,11 @@ impl<F: Fn(&windows_core::HSTRING) -> windows_core::Result<()> + Send + 'static>
}
}
}
impl<F: Fn(&windows_core::HSTRING) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for GameListRemovedEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct GameModeConfiguration(windows_core::IUnknown);
Expand Down
5 changes: 5 additions & 0 deletions crates/libs/windows/src/Windows/Graphics/Display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,11 @@ impl<F: Fn(windows_core::Ref<windows_core::IInspectable>) -> windows_core::Resul
}
}
}
impl<F: Fn(windows_core::Ref<windows_core::IInspectable>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for DisplayPropertiesEventHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DisplayServices(windows_core::IUnknown);
Expand Down
5 changes: 5 additions & 0 deletions crates/libs/windows/src/Windows/Graphics/Printing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,11 @@ impl<F: Fn(windows_core::Ref<PrintTaskSourceRequestedArgs>) -> windows_core::Res
}
}
}
impl<F: Fn(windows_core::Ref<PrintTaskSourceRequestedArgs>) -> windows_core::Result<()> + Send + 'static> From<windows_core::DelegateFn<F>> for PrintTaskSourceRequestedHandler {
fn from(value: windows_core::DelegateFn<F>) -> Self {
Self::new(value.0)
}
}
pub struct StandardPrintTaskOptions;
impl StandardPrintTaskOptions {
pub fn MediaSize() -> windows_core::Result<windows_core::HSTRING> {
Expand Down
Loading
Loading