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::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextselectiongranularity?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionGranularity(pub NSInteger);
impl NSTextSelectionGranularity {
    #[doc(alias = "NSTextSelectionGranularityCharacter")]
    pub const Character: Self = Self(0);
    #[doc(alias = "NSTextSelectionGranularityWord")]
    pub const Word: Self = Self(1);
    #[doc(alias = "NSTextSelectionGranularityParagraph")]
    pub const Paragraph: Self = Self(2);
    #[doc(alias = "NSTextSelectionGranularityLine")]
    pub const Line: Self = Self(3);
    #[doc(alias = "NSTextSelectionGranularitySentence")]
    pub const Sentence: Self = Self(4);
}

unsafe impl Encode for NSTextSelectionGranularity {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

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

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextselectionaffinity?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionAffinity(pub NSInteger);
impl NSTextSelectionAffinity {
    #[doc(alias = "NSTextSelectionAffinityUpstream")]
    pub const Upstream: Self = Self(0);
    #[doc(alias = "NSTextSelectionAffinityDownstream")]
    pub const Downstream: Self = Self(1);
}

unsafe impl Encode for NSTextSelectionAffinity {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

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

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

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

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

extern_conformance!(
    unsafe impl NSSecureCoding for NSTextSelection {}
);

impl NSTextSelection {
    extern_methods!(
        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(initWithRanges:affinity:granularity:))]
        #[unsafe(method_family = init)]
        pub fn initWithRanges_affinity_granularity(
            this: Allocated<Self>,
            text_ranges: &NSArray<NSTextRange>,
            affinity: NSTextSelectionAffinity,
            granularity: NSTextSelectionGranularity,
        ) -> 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>>;

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(initWithRange:affinity:granularity:))]
        #[unsafe(method_family = init)]
        pub fn initWithRange_affinity_granularity(
            this: Allocated<Self>,
            range: &NSTextRange,
            affinity: NSTextSelectionAffinity,
            granularity: NSTextSelectionGranularity,
        ) -> Retained<Self>;

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(initWithLocation:affinity:))]
        #[unsafe(method_family = init)]
        pub fn initWithLocation_affinity(
            this: Allocated<Self>,
            location: &ProtocolObject<dyn NSTextLocation>,
            affinity: NSTextSelectionAffinity,
        ) -> Retained<Self>;

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

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(textRanges))]
        #[unsafe(method_family = none)]
        pub fn textRanges(&self) -> Retained<NSArray<NSTextRange>>;

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

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

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

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(anchorPositionOffset))]
        #[unsafe(method_family = none)]
        pub fn anchorPositionOffset(&self) -> CGFloat;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`anchorPositionOffset`][Self::anchorPositionOffset].
        #[unsafe(method(setAnchorPositionOffset:))]
        #[unsafe(method_family = none)]
        pub fn setAnchorPositionOffset(&self, anchor_position_offset: CGFloat);

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

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

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(secondarySelectionLocation))]
        #[unsafe(method_family = none)]
        pub fn secondarySelectionLocation(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;

        #[cfg(feature = "NSTextRange")]
        /// Setter for [`secondarySelectionLocation`][Self::secondarySelectionLocation].
        #[unsafe(method(setSecondarySelectionLocation:))]
        #[unsafe(method_family = none)]
        pub fn setSecondarySelectionLocation(
            &self,
            secondary_selection_location: Option<&ProtocolObject<dyn NSTextLocation>>,
        );

        #[unsafe(method(typingAttributes))]
        #[unsafe(method_family = none)]
        pub fn typingAttributes(&self) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;

        /// Setter for [`typingAttributes`][Self::typingAttributes].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `typing_attributes` generic should be of the correct type.
        #[unsafe(method(setTypingAttributes:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTypingAttributes(
            &self,
            typing_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
        );

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(textSelectionWithTextRanges:))]
        #[unsafe(method_family = none)]
        pub fn textSelectionWithTextRanges(
            &self,
            text_ranges: &NSArray<NSTextRange>,
        ) -> Retained<NSTextSelection>;
    );
}

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