objc2-security-interface 0.3.2

Bindings to the SecurityInterface framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_app_kit::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-security")]
use objc2_security::*;
#[cfg(feature = "objc2-security-foundation")]
use objc2_security_foundation::*;

use crate::*;

/// Defines the current state of the authorization view.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfauthorizationviewstate?language=objc)
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SFAuthorizationViewState(pub c_uint);
impl SFAuthorizationViewState {
    #[doc(alias = "SFAuthorizationStartupState")]
    pub const StartupState: Self = Self(0);
    #[doc(alias = "SFAuthorizationViewLockedState")]
    pub const ViewLockedState: Self = Self(1);
    #[doc(alias = "SFAuthorizationViewInProgressState")]
    pub const ViewInProgressState: Self = Self(2);
    #[doc(alias = "SFAuthorizationViewUnlockedState")]
    pub const ViewUnlockedState: Self = Self(3);
}

unsafe impl Encode for SFAuthorizationViewState {
    const ENCODING: Encoding = c_uint::ENCODING;
}

unsafe impl RefEncode for SFAuthorizationViewState {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfauthorizationview?language=objc)
    #[unsafe(super(NSView, NSResponder, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct SFAuthorizationView;
);

extern_conformance!(
    unsafe impl NSAccessibility for SFAuthorizationView {}
);

extern_conformance!(
    unsafe impl NSAccessibilityElementProtocol for SFAuthorizationView {}
);

extern_conformance!(
    unsafe impl NSAnimatablePropertyContainer for SFAuthorizationView {}
);

extern_conformance!(
    unsafe impl NSAppearanceCustomization for SFAuthorizationView {}
);

extern_conformance!(
    unsafe impl NSCoding for SFAuthorizationView {}
);

extern_conformance!(
    unsafe impl NSDraggingDestination for SFAuthorizationView {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for SFAuthorizationView {}
);

extern_conformance!(
    unsafe impl NSUserInterfaceItemIdentification for SFAuthorizationView {}
);

impl SFAuthorizationView {
    extern_methods!(
        #[cfg(feature = "objc2-security")]
        /// A convenience method to specify an authorization rights set containing a single item with the name set to the specified string.
        ///
        /// Parameter `authorizationString`: Authorization string.
        ///
        /// # Safety
        ///
        /// `authorization_string` must be a valid pointer.
        #[unsafe(method(setString:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setString(&self, authorization_string: AuthorizationString);

        #[cfg(feature = "objc2-security")]
        /// Sets the authorization rights for this view.
        ///
        /// Parameter `authorizationRights`: Authorization rights.
        ///
        /// # Safety
        ///
        /// `authorization_rights` must be a valid pointer.
        #[unsafe(method(setAuthorizationRights:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAuthorizationRights(
            &self,
            authorization_rights: *const AuthorizationRights,
        );

        #[cfg(feature = "objc2-security")]
        /// Returns the authorization rights for this view.
        #[unsafe(method(authorizationRights))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationRights(&self) -> *mut AuthorizationRights;

        #[cfg(feature = "objc2-security-foundation")]
        /// Returns the authorization object associated with this view.
        #[unsafe(method(authorization))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorization(&self) -> Option<Retained<SFAuthorization>>;

        /// This method is called when the state of the authorization object has changed.
        ///
        /// Parameter `inSender`: The action that is marked for updateStatus.
        ///
        /// # Safety
        ///
        /// - `in_sender` should be of the correct type.
        /// - `in_sender` might not allow `None`.
        #[unsafe(method(updateStatus:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateStatus(&self, in_sender: Option<&AnyObject>) -> bool;

        #[unsafe(method(setAutoupdate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAutoupdate(&self, autoupdate: bool);

        #[unsafe(method(setAutoupdate:interval:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAutoupdate_interval(&self, autoupdate: bool, interval: NSTimeInterval);

        /// Returns the current state of the authorization view.
        #[unsafe(method(authorizationState))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationState(&self) -> SFAuthorizationViewState;

        /// Sets the current state of the authorization view.
        ///
        /// Parameter `enabled`: Enable flag.
        #[unsafe(method(setEnabled:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEnabled(&self, enabled: bool);

        /// Indicates if the authorization view is enabled or disabled.
        #[unsafe(method(isEnabled))]
        #[unsafe(method_family = none)]
        pub unsafe fn isEnabled(&self) -> bool;

        #[cfg(feature = "objc2-security")]
        /// Sets the current authorization flags for the view.
        ///
        /// Parameter `flags`: Authorization flags.
        #[unsafe(method(setFlags:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFlags(&self, flags: AuthorizationFlags);

        /// Sets the delegate for this authorization view. If you want to hear state changes (for example, the user clicked the button), set your delegate and implement the delegate methods mentioned for SFAuthorizationViewDelegate
        ///
        /// Parameter `delegate`: The client's delegate object.
        ///
        /// # Safety
        ///
        /// - `delegate` should be of the correct type.
        /// - `delegate` might not allow `None`.
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>);

        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(&self) -> Option<Retained<AnyObject>>;

        /// # Safety
        ///
        /// - `in_sender` should be of the correct type.
        /// - `in_sender` might not allow `None`.
        #[unsafe(method(authorize:))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorize(&self, in_sender: Option<&AnyObject>) -> bool;

        /// # Safety
        ///
        /// - `in_sender` should be of the correct type.
        /// - `in_sender` might not allow `None`.
        #[unsafe(method(deauthorize:))]
        #[unsafe(method_family = none)]
        pub unsafe fn deauthorize(&self, in_sender: Option<&AnyObject>) -> bool;
    );
}

/// Methods declared on superclass `NSView`.
impl SFAuthorizationView {
    extern_methods!(
        #[unsafe(method(initWithFrame:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;

        /// # Safety
        ///
        /// `coder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;
    );
}

/// Methods declared on superclass `NSResponder`.
impl SFAuthorizationView {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl SFAuthorizationView {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}

mod private_NSObjectSFAuthorizationViewDelegate {
    pub trait Sealed {}
}

/// Category "SFAuthorizationViewDelegate" on [`NSObject`].
///
/// Optionally implement these delegate methods to obtain the state of the authorization object.
#[doc(alias = "SFAuthorizationViewDelegate")]
pub unsafe trait NSObjectSFAuthorizationViewDelegate:
    ClassType + Sized + private_NSObjectSFAuthorizationViewDelegate::Sealed
{
    extern_methods!(
        /// Parameter `view`:
        ///
        /// # Safety
        ///
        /// `view` might not allow `None`.
        #[unsafe(method(authorizationViewDidAuthorize:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationViewDidAuthorize(&self, view: Option<&SFAuthorizationView>);

        /// Parameter `view`:
        ///
        /// # Safety
        ///
        /// `view` might not allow `None`.
        #[unsafe(method(authorizationViewDidDeauthorize:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationViewDidDeauthorize(&self, view: Option<&SFAuthorizationView>);

        /// Parameter `view`:
        ///
        /// # Safety
        ///
        /// `view` might not allow `None`.
        #[unsafe(method(authorizationViewShouldDeauthorize:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationViewShouldDeauthorize(
            &self,
            view: Option<&SFAuthorizationView>,
        ) -> bool;

        /// Parameter `view`:
        ///
        /// # Safety
        ///
        /// `view` might not allow `None`.
        #[unsafe(method(authorizationViewCreatedAuthorization:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationViewCreatedAuthorization(&self, view: Option<&SFAuthorizationView>);

        /// Parameter `view`:
        ///
        /// # Safety
        ///
        /// `view` might not allow `None`.
        #[unsafe(method(authorizationViewReleasedAuthorization:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationViewReleasedAuthorization(&self, view: Option<&SFAuthorizationView>);

        /// Parameter `view`:
        ///
        /// # Safety
        ///
        /// `view` might not allow `None`.
        #[unsafe(method(authorizationViewDidHide:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationViewDidHide(&self, view: Option<&SFAuthorizationView>);
    );
}

impl private_NSObjectSFAuthorizationViewDelegate::Sealed for NSObject {}
unsafe impl NSObjectSFAuthorizationViewDelegate for NSObject {}