objc2-app-kit 0.3.2

Bindings to the AppKit 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_foundation::*;

use crate::*;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscandidatelisttouchbaritem?language=objc)
    #[unsafe(super(NSTouchBarItem, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "NSTouchBarItem")]
    pub struct NSCandidateListTouchBarItem<CandidateType: ?Sized = AnyObject>;
);

#[cfg(feature = "NSTouchBarItem")]
impl<CandidateType: ?Sized + Message> NSCandidateListTouchBarItem<CandidateType> {
    /// Unchecked conversion of the generic parameter.
    ///
    /// # Safety
    ///
    /// The generic must be valid to reinterpret as the given type.
    #[inline]
    pub unsafe fn cast_unchecked<NewCandidateType: ?Sized + Message>(
        &self,
    ) -> &NSCandidateListTouchBarItem<NewCandidateType> {
        unsafe { &*((self as *const Self).cast()) }
    }
}

#[cfg(feature = "NSTouchBarItem")]
extern_conformance!(
    unsafe impl<CandidateType: ?Sized + NSCoding> NSCoding
        for NSCandidateListTouchBarItem<CandidateType>
    {
    }
);

#[cfg(feature = "NSTouchBarItem")]
extern_conformance!(
    unsafe impl<CandidateType: ?Sized> NSObjectProtocol for NSCandidateListTouchBarItem<CandidateType> {}
);

#[cfg(feature = "NSTouchBarItem")]
impl<CandidateType: Message> NSCandidateListTouchBarItem<CandidateType> {
    extern_methods!(
        #[cfg(all(
            feature = "NSResponder",
            feature = "NSTextInputClient",
            feature = "NSView"
        ))]
        #[unsafe(method(client))]
        #[unsafe(method_family = none)]
        pub fn client(&self) -> Option<Retained<NSView>>;

        #[cfg(all(
            feature = "NSResponder",
            feature = "NSTextInputClient",
            feature = "NSView"
        ))]
        /// Setter for [`client`][Self::client].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        ///
        /// # Safety
        ///
        /// `client` must implement NSTextInputClient.
        #[unsafe(method(setClient:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setClient(&self, client: Option<&NSView>);

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

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn NSCandidateListTouchBarItemDelegate>>,
        );

        #[unsafe(method(isCollapsed))]
        #[unsafe(method_family = none)]
        pub fn isCollapsed(&self) -> bool;

        /// Setter for [`isCollapsed`][Self::isCollapsed].
        #[unsafe(method(setCollapsed:))]
        #[unsafe(method_family = none)]
        pub fn setCollapsed(&self, collapsed: bool);

        #[unsafe(method(allowsCollapsing))]
        #[unsafe(method_family = none)]
        pub fn allowsCollapsing(&self) -> bool;

        /// Setter for [`allowsCollapsing`][Self::allowsCollapsing].
        #[unsafe(method(setAllowsCollapsing:))]
        #[unsafe(method_family = none)]
        pub fn setAllowsCollapsing(&self, allows_collapsing: bool);

        #[unsafe(method(isCandidateListVisible))]
        #[unsafe(method_family = none)]
        pub fn isCandidateListVisible(&self) -> bool;

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

        #[unsafe(method(allowsTextInputContextCandidates))]
        #[unsafe(method_family = none)]
        pub fn allowsTextInputContextCandidates(&self) -> bool;

        /// Setter for [`allowsTextInputContextCandidates`][Self::allowsTextInputContextCandidates].
        #[unsafe(method(setAllowsTextInputContextCandidates:))]
        #[unsafe(method_family = none)]
        pub fn setAllowsTextInputContextCandidates(
            &self,
            allows_text_input_context_candidates: bool,
        );

        #[cfg(feature = "block2")]
        /// # Safety
        ///
        /// The returned block's argument 1 must be a valid pointer.
        #[unsafe(method(attributedStringForCandidate))]
        #[unsafe(method_family = none)]
        pub unsafe fn attributedStringForCandidate(
            &self,
        ) -> *mut block2::DynBlock<
            dyn Fn(NonNull<CandidateType>, NSInteger) -> NonNull<NSAttributedString>,
        >;

        #[cfg(feature = "block2")]
        /// Setter for [`attributedStringForCandidate`][Self::attributedStringForCandidate].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `attributed_string_for_candidate` block's return must be a valid pointer.
        #[unsafe(method(setAttributedStringForCandidate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAttributedStringForCandidate(
            &self,
            attributed_string_for_candidate: Option<
                &block2::DynBlock<
                    dyn Fn(NonNull<CandidateType>, NSInteger) -> NonNull<NSAttributedString>,
                >,
            >,
        );

        #[unsafe(method(candidates))]
        #[unsafe(method_family = none)]
        pub fn candidates(&self) -> Retained<NSArray<CandidateType>>;

        #[unsafe(method(setCandidates:forSelectedRange:inString:))]
        #[unsafe(method_family = none)]
        pub fn setCandidates_forSelectedRange_inString(
            &self,
            candidates: &NSArray<CandidateType>,
            selected_range: NSRange,
            original_string: Option<&NSString>,
        );

        #[unsafe(method(customizationLabel))]
        #[unsafe(method_family = none)]
        pub fn customizationLabel(&self) -> Retained<NSString>;

        /// Setter for [`customizationLabel`][Self::customizationLabel].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setCustomizationLabel:))]
        #[unsafe(method_family = none)]
        pub fn setCustomizationLabel(&self, customization_label: Option<&NSString>);
    );
}

/// Methods declared on superclass `NSTouchBarItem`.
#[cfg(feature = "NSTouchBarItem")]
impl<CandidateType: Message> NSCandidateListTouchBarItem<CandidateType> {
    extern_methods!(
        #[unsafe(method(initWithIdentifier:))]
        #[unsafe(method_family = init)]
        pub fn initWithIdentifier(
            this: Allocated<Self>,
            identifier: &NSTouchBarItemIdentifier,
        ) -> 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>>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

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

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscandidatelisttouchbaritemdelegate?language=objc)
    pub unsafe trait NSCandidateListTouchBarItemDelegate:
        NSObjectProtocol + MainThreadOnly
    {
        #[cfg(feature = "NSTouchBarItem")]
        /// # Safety
        ///
        /// `an_item` generic should be of the correct type.
        #[optional]
        #[unsafe(method(candidateListTouchBarItem:beginSelectingCandidateAtIndex:))]
        #[unsafe(method_family = none)]
        unsafe fn candidateListTouchBarItem_beginSelectingCandidateAtIndex(
            &self,
            an_item: &NSCandidateListTouchBarItem,
            index: NSInteger,
        );

        #[cfg(feature = "NSTouchBarItem")]
        /// # Safety
        ///
        /// `an_item` generic should be of the correct type.
        #[optional]
        #[unsafe(method(candidateListTouchBarItem:changeSelectionFromCandidateAtIndex:toIndex:))]
        #[unsafe(method_family = none)]
        unsafe fn candidateListTouchBarItem_changeSelectionFromCandidateAtIndex_toIndex(
            &self,
            an_item: &NSCandidateListTouchBarItem,
            previous_index: NSInteger,
            index: NSInteger,
        );

        #[cfg(feature = "NSTouchBarItem")]
        /// # Safety
        ///
        /// `an_item` generic should be of the correct type.
        #[optional]
        #[unsafe(method(candidateListTouchBarItem:endSelectingCandidateAtIndex:))]
        #[unsafe(method_family = none)]
        unsafe fn candidateListTouchBarItem_endSelectingCandidateAtIndex(
            &self,
            an_item: &NSCandidateListTouchBarItem,
            index: NSInteger,
        );

        #[cfg(feature = "NSTouchBarItem")]
        /// # Safety
        ///
        /// `an_item` generic should be of the correct type.
        #[optional]
        #[unsafe(method(candidateListTouchBarItem:changedCandidateListVisibility:))]
        #[unsafe(method_family = none)]
        unsafe fn candidateListTouchBarItem_changedCandidateListVisibility(
            &self,
            an_item: &NSCandidateListTouchBarItem,
            is_visible: bool,
        );
    }
);

/// NSCandidateListTouchBarItem.
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
impl NSView {
    extern_methods!(
        #[cfg(feature = "NSTouchBarItem")]
        #[unsafe(method(candidateListTouchBarItem))]
        #[unsafe(method_family = none)]
        pub fn candidateListTouchBarItem(&self) -> Option<Retained<NSCandidateListTouchBarItem>>;
    );
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstouchbaritemidentifiercandidatelist?language=objc)
    #[cfg(feature = "NSTouchBarItem")]
    pub static NSTouchBarItemIdentifierCandidateList: &'static NSTouchBarItemIdentifier;
}