//! 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::*;
#[cfg(feature = "objc2-core-graphics")]
#[cfg(target_vendor = "apple")]
use objc2_core_graphics::*;
use objc2_foundation::*;

use crate::*;

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

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsglyphproperty?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSGlyphProperty(pub NSInteger);
bitflags::bitflags! {
    impl NSGlyphProperty: NSInteger {
        #[doc(alias = "NSGlyphPropertyNull")]
        const Null = 1<<0;
        #[doc(alias = "NSGlyphPropertyControlCharacter")]
        const ControlCharacter = 1<<1;
        #[doc(alias = "NSGlyphPropertyElastic")]
        const Elastic = 1<<2;
        #[doc(alias = "NSGlyphPropertyNonBaseCharacter")]
        const NonBaseCharacter = 1<<3;
    }
}

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscontrolcharacteraction?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSControlCharacterAction(pub NSInteger);
bitflags::bitflags! {
    impl NSControlCharacterAction: NSInteger {
        #[doc(alias = "NSControlCharacterActionZeroAdvancement")]
        const ZeroAdvancement = 1<<0;
        #[doc(alias = "NSControlCharacterActionWhitespace")]
        const Whitespace = 1<<1;
        #[doc(alias = "NSControlCharacterActionHorizontalTab")]
        const HorizontalTab = 1<<2;
        #[doc(alias = "NSControlCharacterActionLineBreak")]
        const LineBreak = 1<<3;
        #[doc(alias = "NSControlCharacterActionParagraphBreak")]
        const ParagraphBreak = 1<<4;
        #[doc(alias = "NSControlCharacterActionContainerBreak")]
        const ContainerBreak = 1<<5;
    }
}

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

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

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutorientationprovider?language=objc)
    pub unsafe trait NSTextLayoutOrientationProvider {
        #[unsafe(method(layoutOrientation))]
        #[unsafe(method_family = none)]
        unsafe fn layoutOrientation(&self) -> NSTextLayoutOrientation;
    }
);

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstypesetterbehavior?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTypesetterBehavior(pub NSInteger);
impl NSTypesetterBehavior {
    #[doc(alias = "NSTypesetterLatestBehavior")]
    pub const LatestBehavior: Self = Self(-1);
    #[doc(alias = "NSTypesetterOriginalBehavior")]
    pub const OriginalBehavior: Self = Self(0);
    #[doc(alias = "NSTypesetterBehavior_10_2_WithCompatibility")]
    pub const Behavior_10_2_WithCompatibility: Self = Self(1);
    #[doc(alias = "NSTypesetterBehavior_10_2")]
    pub const Behavior_10_2: Self = Self(2);
    #[doc(alias = "NSTypesetterBehavior_10_3")]
    pub const Behavior_10_3: Self = Self(3);
    #[doc(alias = "NSTypesetterBehavior_10_4")]
    pub const Behavior_10_4: Self = Self(4);
}

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

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

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

unsafe impl NSCoding for NSLayoutManager {}

unsafe impl NSObjectProtocol for NSLayoutManager {}

unsafe impl NSSecureCoding for NSLayoutManager {}

impl NSLayoutManager {
    extern_methods!(
        /// ************************** Initialization ***************************
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;

        #[cfg(feature = "NSTextStorage")]
        /// ************************* Text storage **************************
        #[unsafe(method(textStorage))]
        #[unsafe(method_family = none)]
        pub unsafe fn textStorage(&self) -> Option<Retained<NSTextStorage>>;

        #[cfg(feature = "NSTextStorage")]
        /// Setter for [`textStorage`][Self::textStorage].
        #[unsafe(method(setTextStorage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTextStorage(&self, text_storage: Option<&NSTextStorage>);

        #[cfg(feature = "NSTextStorage")]
        #[unsafe(method(replaceTextStorage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn replaceTextStorage(&self, new_text_storage: &NSTextStorage);

        #[cfg(feature = "NSTextContainer")]
        /// ************************** Text containers ***************************
        #[unsafe(method(textContainers))]
        #[unsafe(method_family = none)]
        pub unsafe fn textContainers(&self) -> Retained<NSArray<NSTextContainer>>;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(addTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addTextContainer(&self, container: &NSTextContainer);

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(insertTextContainer:atIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn insertTextContainer_atIndex(
            &self,
            container: &NSTextContainer,
            index: NSUInteger,
        );

        #[unsafe(method(removeTextContainerAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeTextContainerAtIndex(&self, index: NSUInteger);

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(textContainerChangedGeometry:))]
        #[unsafe(method_family = none)]
        pub unsafe fn textContainerChangedGeometry(&self, container: &NSTextContainer);

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(textContainerChangedTextView:))]
        #[unsafe(method_family = none)]
        pub unsafe fn textContainerChangedTextView(&self, container: &NSTextContainer);

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

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

        /// ********************* Global layout manager options **********************
        #[unsafe(method(showsInvisibleCharacters))]
        #[unsafe(method_family = none)]
        pub unsafe fn showsInvisibleCharacters(&self) -> bool;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        #[cfg(feature = "NSCell")]
        #[unsafe(method(defaultAttachmentScaling))]
        #[unsafe(method_family = none)]
        pub unsafe fn defaultAttachmentScaling(&self) -> NSImageScaling;

        #[cfg(feature = "NSCell")]
        /// Setter for [`defaultAttachmentScaling`][Self::defaultAttachmentScaling].
        #[unsafe(method(setDefaultAttachmentScaling:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDefaultAttachmentScaling(
            &self,
            default_attachment_scaling: NSImageScaling,
        );

        #[cfg(feature = "NSTypesetter")]
        /// ********************* Typesetter **********************
        #[unsafe(method(typesetter))]
        #[unsafe(method_family = none)]
        pub unsafe fn typesetter(&self) -> Retained<NSTypesetter>;

        #[cfg(feature = "NSTypesetter")]
        /// Setter for [`typesetter`][Self::typesetter].
        #[unsafe(method(setTypesetter:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTypesetter(&self, typesetter: &NSTypesetter);

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

        /// Setter for [`typesetterBehavior`][Self::typesetterBehavior].
        #[unsafe(method(setTypesetterBehavior:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTypesetterBehavior(&self, typesetter_behavior: NSTypesetterBehavior);

        /// ************************ Invalidation *************************
        #[unsafe(method(invalidateGlyphsForCharacterRange:changeInLength:actualCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn invalidateGlyphsForCharacterRange_changeInLength_actualCharacterRange(
            &self,
            char_range: NSRange,
            delta: NSInteger,
            actual_char_range: NSRangePointer,
        );

        #[unsafe(method(invalidateLayoutForCharacterRange:actualCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn invalidateLayoutForCharacterRange_actualCharacterRange(
            &self,
            char_range: NSRange,
            actual_char_range: NSRangePointer,
        );

        #[unsafe(method(invalidateDisplayForCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn invalidateDisplayForCharacterRange(&self, char_range: NSRange);

        #[unsafe(method(invalidateDisplayForGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn invalidateDisplayForGlyphRange(&self, glyph_range: NSRange);

        #[cfg(feature = "NSTextStorage")]
        #[unsafe(method(processEditingForTextStorage:edited:range:changeInLength:invalidatedRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn processEditingForTextStorage_edited_range_changeInLength_invalidatedRange(
            &self,
            text_storage: &NSTextStorage,
            edit_mask: NSTextStorageEditActions,
            new_char_range: NSRange,
            delta: NSInteger,
            invalidated_char_range: NSRange,
        );

        /// ********************** Causing glyph generation and layout ***********************
        #[unsafe(method(ensureGlyphsForCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn ensureGlyphsForCharacterRange(&self, char_range: NSRange);

        #[unsafe(method(ensureGlyphsForGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn ensureGlyphsForGlyphRange(&self, glyph_range: NSRange);

        #[unsafe(method(ensureLayoutForCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn ensureLayoutForCharacterRange(&self, char_range: NSRange);

        #[unsafe(method(ensureLayoutForGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn ensureLayoutForGlyphRange(&self, glyph_range: NSRange);

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(ensureLayoutForTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn ensureLayoutForTextContainer(&self, container: &NSTextContainer);

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(ensureLayoutForBoundingRect:inTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn ensureLayoutForBoundingRect_inTextContainer(
            &self,
            bounds: NSRect,
            container: &NSTextContainer,
        );

        #[cfg(all(feature = "NSFont", feature = "objc2-core-graphics"))]
        #[cfg(target_vendor = "apple")]
        /// ********************** Set glyphs and glyph properties ***********************
        #[unsafe(method(setGlyphs:properties:characterIndexes:font:forGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setGlyphs_properties_characterIndexes_font_forGlyphRange(
            &self,
            glyphs: NonNull<CGGlyph>,
            props: NonNull<NSGlyphProperty>,
            char_indexes: NonNull<NSUInteger>,
            a_font: &NSFont,
            glyph_range: NSRange,
        );

        /// ********************** Get glyphs and glyph properties ***********************
        #[unsafe(method(numberOfGlyphs))]
        #[unsafe(method_family = none)]
        pub unsafe fn numberOfGlyphs(&self) -> NSUInteger;

        #[cfg(feature = "objc2-core-graphics")]
        #[cfg(target_vendor = "apple")]
        #[unsafe(method(CGGlyphAtIndex:isValidIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn CGGlyphAtIndex_isValidIndex(
            &self,
            glyph_index: NSUInteger,
            is_valid_index: *mut Bool,
        ) -> CGGlyph;

        #[cfg(feature = "objc2-core-graphics")]
        #[cfg(target_vendor = "apple")]
        #[unsafe(method(CGGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn CGGlyphAtIndex(&self, glyph_index: NSUInteger) -> CGGlyph;

        #[unsafe(method(isValidGlyphIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn isValidGlyphIndex(&self, glyph_index: NSUInteger) -> bool;

        #[unsafe(method(propertyForGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn propertyForGlyphAtIndex(&self, glyph_index: NSUInteger) -> NSGlyphProperty;

        #[unsafe(method(characterIndexForGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn characterIndexForGlyphAtIndex(&self, glyph_index: NSUInteger) -> NSUInteger;

        #[unsafe(method(glyphIndexForCharacterAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphIndexForCharacterAtIndex(&self, char_index: NSUInteger) -> NSUInteger;

        #[cfg(feature = "objc2-core-graphics")]
        #[cfg(target_vendor = "apple")]
        #[unsafe(method(getGlyphsInRange:glyphs:properties:characterIndexes:bidiLevels:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getGlyphsInRange_glyphs_properties_characterIndexes_bidiLevels(
            &self,
            glyph_range: NSRange,
            glyph_buffer: *mut CGGlyph,
            props: *mut NSGlyphProperty,
            char_index_buffer: *mut NSUInteger,
            bidi_level_buffer: *mut c_uchar,
        ) -> NSUInteger;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(setTextContainer:forGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTextContainer_forGlyphRange(
            &self,
            container: &NSTextContainer,
            glyph_range: NSRange,
        );

        #[unsafe(method(setLineFragmentRect:forGlyphRange:usedRect:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLineFragmentRect_forGlyphRange_usedRect(
            &self,
            fragment_rect: NSRect,
            glyph_range: NSRange,
            used_rect: NSRect,
        );

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(setExtraLineFragmentRect:usedRect:textContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setExtraLineFragmentRect_usedRect_textContainer(
            &self,
            fragment_rect: NSRect,
            used_rect: NSRect,
            container: &NSTextContainer,
        );

        #[unsafe(method(setLocation:forStartOfGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLocation_forStartOfGlyphRange(
            &self,
            location: NSPoint,
            glyph_range: NSRange,
        );

        #[unsafe(method(setNotShownAttribute:forGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setNotShownAttribute_forGlyphAtIndex(
            &self,
            flag: bool,
            glyph_index: NSUInteger,
        );

        #[unsafe(method(setDrawsOutsideLineFragment:forGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDrawsOutsideLineFragment_forGlyphAtIndex(
            &self,
            flag: bool,
            glyph_index: NSUInteger,
        );

        #[unsafe(method(setAttachmentSize:forGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAttachmentSize_forGlyphRange(
            &self,
            attachment_size: NSSize,
            glyph_range: NSRange,
        );

        /// ********************** Get layout information ***********************
        #[unsafe(method(getFirstUnlaidCharacterIndex:glyphIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getFirstUnlaidCharacterIndex_glyphIndex(
            &self,
            char_index: *mut NSUInteger,
            glyph_index: *mut NSUInteger,
        );

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

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

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(textContainerForGlyphAtIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn textContainerForGlyphAtIndex_effectiveRange(
            &self,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
        ) -> Option<Retained<NSTextContainer>>;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(textContainerForGlyphAtIndex:effectiveRange:withoutAdditionalLayout:))]
        #[unsafe(method_family = none)]
        pub unsafe fn textContainerForGlyphAtIndex_effectiveRange_withoutAdditionalLayout(
            &self,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
            flag: bool,
        ) -> Option<Retained<NSTextContainer>>;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(usedRectForTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn usedRectForTextContainer(&self, container: &NSTextContainer) -> NSRect;

        #[unsafe(method(lineFragmentRectForGlyphAtIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn lineFragmentRectForGlyphAtIndex_effectiveRange(
            &self,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
        ) -> NSRect;

        #[unsafe(method(lineFragmentRectForGlyphAtIndex:effectiveRange:withoutAdditionalLayout:))]
        #[unsafe(method_family = none)]
        pub unsafe fn lineFragmentRectForGlyphAtIndex_effectiveRange_withoutAdditionalLayout(
            &self,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
            flag: bool,
        ) -> NSRect;

        #[unsafe(method(lineFragmentUsedRectForGlyphAtIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn lineFragmentUsedRectForGlyphAtIndex_effectiveRange(
            &self,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
        ) -> NSRect;

        #[unsafe(method(lineFragmentUsedRectForGlyphAtIndex:effectiveRange:withoutAdditionalLayout:))]
        #[unsafe(method_family = none)]
        pub unsafe fn lineFragmentUsedRectForGlyphAtIndex_effectiveRange_withoutAdditionalLayout(
            &self,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
            flag: bool,
        ) -> NSRect;

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

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

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(extraLineFragmentTextContainer))]
        #[unsafe(method_family = none)]
        pub unsafe fn extraLineFragmentTextContainer(&self) -> Option<Retained<NSTextContainer>>;

        #[unsafe(method(locationForGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn locationForGlyphAtIndex(&self, glyph_index: NSUInteger) -> NSPoint;

        #[unsafe(method(notShownAttributeForGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn notShownAttributeForGlyphAtIndex(&self, glyph_index: NSUInteger) -> bool;

        #[unsafe(method(drawsOutsideLineFragmentForGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn drawsOutsideLineFragmentForGlyphAtIndex(
            &self,
            glyph_index: NSUInteger,
        ) -> bool;

        #[unsafe(method(attachmentSizeForGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn attachmentSizeForGlyphAtIndex(&self, glyph_index: NSUInteger) -> NSSize;

        #[unsafe(method(truncatedGlyphRangeInLineFragmentForGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn truncatedGlyphRangeInLineFragmentForGlyphAtIndex(
            &self,
            glyph_index: NSUInteger,
        ) -> NSRange;

        /// ********************** More sophisticated queries ***********************
        #[unsafe(method(glyphRangeForCharacterRange:actualCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphRangeForCharacterRange_actualCharacterRange(
            &self,
            char_range: NSRange,
            actual_char_range: NSRangePointer,
        ) -> NSRange;

        #[unsafe(method(characterRangeForGlyphRange:actualGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn characterRangeForGlyphRange_actualGlyphRange(
            &self,
            glyph_range: NSRange,
            actual_glyph_range: NSRangePointer,
        ) -> NSRange;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(glyphRangeForTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphRangeForTextContainer(&self, container: &NSTextContainer) -> NSRange;

        #[unsafe(method(rangeOfNominallySpacedGlyphsContainingIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn rangeOfNominallySpacedGlyphsContainingIndex(
            &self,
            glyph_index: NSUInteger,
        ) -> NSRange;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(boundingRectForGlyphRange:inTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn boundingRectForGlyphRange_inTextContainer(
            &self,
            glyph_range: NSRange,
            container: &NSTextContainer,
        ) -> NSRect;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(glyphRangeForBoundingRect:inTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphRangeForBoundingRect_inTextContainer(
            &self,
            bounds: NSRect,
            container: &NSTextContainer,
        ) -> NSRange;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(glyphRangeForBoundingRectWithoutAdditionalLayout:inTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphRangeForBoundingRectWithoutAdditionalLayout_inTextContainer(
            &self,
            bounds: NSRect,
            container: &NSTextContainer,
        ) -> NSRange;

        #[cfg(all(feature = "NSTextContainer", feature = "objc2-core-foundation"))]
        #[unsafe(method(glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphIndexForPoint_inTextContainer_fractionOfDistanceThroughGlyph(
            &self,
            point: NSPoint,
            container: &NSTextContainer,
            partial_fraction: *mut CGFloat,
        ) -> NSUInteger;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(glyphIndexForPoint:inTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphIndexForPoint_inTextContainer(
            &self,
            point: NSPoint,
            container: &NSTextContainer,
        ) -> NSUInteger;

        #[cfg(all(feature = "NSTextContainer", feature = "objc2-core-foundation"))]
        #[unsafe(method(fractionOfDistanceThroughGlyphForPoint:inTextContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn fractionOfDistanceThroughGlyphForPoint_inTextContainer(
            &self,
            point: NSPoint,
            container: &NSTextContainer,
        ) -> CGFloat;

        #[cfg(all(feature = "NSTextContainer", feature = "objc2-core-foundation"))]
        #[unsafe(method(characterIndexForPoint:inTextContainer:fractionOfDistanceBetweenInsertionPoints:))]
        #[unsafe(method_family = none)]
        pub unsafe fn characterIndexForPoint_inTextContainer_fractionOfDistanceBetweenInsertionPoints(
            &self,
            point: NSPoint,
            container: &NSTextContainer,
            partial_fraction: *mut CGFloat,
        ) -> NSUInteger;

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(getLineFragmentInsertionPointsForCharacterAtIndex:alternatePositions:inDisplayOrder:positions:characterIndexes:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getLineFragmentInsertionPointsForCharacterAtIndex_alternatePositions_inDisplayOrder_positions_characterIndexes(
            &self,
            char_index: NSUInteger,
            a_flag: bool,
            d_flag: bool,
            positions: *mut CGFloat,
            char_indexes: *mut NSUInteger,
        ) -> NSUInteger;

        #[cfg(all(feature = "NSTextContainer", feature = "block2"))]
        #[unsafe(method(enumerateLineFragmentsForGlyphRange:usingBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn enumerateLineFragmentsForGlyphRange_usingBlock(
            &self,
            glyph_range: NSRange,
            block: &block2::Block<
                dyn Fn(NSRect, NSRect, NonNull<NSTextContainer>, NSRange, NonNull<Bool>),
            >,
        );

        #[cfg(all(feature = "NSTextContainer", feature = "block2"))]
        #[unsafe(method(enumerateEnclosingRectsForGlyphRange:withinSelectedGlyphRange:inTextContainer:usingBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn enumerateEnclosingRectsForGlyphRange_withinSelectedGlyphRange_inTextContainer_usingBlock(
            &self,
            glyph_range: NSRange,
            selected_range: NSRange,
            text_container: &NSTextContainer,
            block: &block2::Block<dyn Fn(NSRect, NonNull<Bool>)>,
        );

        /// ********************** Drawing support ***********************
        #[unsafe(method(drawBackgroundForGlyphRange:atPoint:))]
        #[unsafe(method_family = none)]
        pub unsafe fn drawBackgroundForGlyphRange_atPoint(
            &self,
            glyphs_to_show: NSRange,
            origin: NSPoint,
        );

        #[unsafe(method(drawGlyphsForGlyphRange:atPoint:))]
        #[unsafe(method_family = none)]
        pub unsafe fn drawGlyphsForGlyphRange_atPoint(
            &self,
            glyphs_to_show: NSRange,
            origin: NSPoint,
        );

        #[cfg(all(
            feature = "NSFont",
            feature = "objc2-core-foundation",
            feature = "objc2-core-graphics"
        ))]
        #[cfg(target_vendor = "apple")]
        #[unsafe(method(showCGGlyphs:positions:count:font:textMatrix:attributes:inContext:))]
        #[unsafe(method_family = none)]
        pub unsafe fn showCGGlyphs_positions_count_font_textMatrix_attributes_inContext(
            &self,
            glyphs: NonNull<CGGlyph>,
            positions: NonNull<CGPoint>,
            glyph_count: NSInteger,
            font: &NSFont,
            text_matrix: CGAffineTransform,
            attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
            cg_context: &CGContext,
        );

        #[cfg(feature = "NSColor")]
        #[unsafe(method(fillBackgroundRectArray:count:forCharacterRange:color:))]
        #[unsafe(method_family = none)]
        pub unsafe fn fillBackgroundRectArray_count_forCharacterRange_color(
            &self,
            rect_array: NonNull<NSRect>,
            rect_count: NSUInteger,
            char_range: NSRange,
            color: &NSColor,
        );

        #[cfg(all(feature = "NSAttributedString", feature = "objc2-core-foundation"))]
        #[unsafe(method(drawUnderlineForGlyphRange:underlineType:baselineOffset:lineFragmentRect:lineFragmentGlyphRange:containerOrigin:))]
        #[unsafe(method_family = none)]
        pub unsafe fn drawUnderlineForGlyphRange_underlineType_baselineOffset_lineFragmentRect_lineFragmentGlyphRange_containerOrigin(
            &self,
            glyph_range: NSRange,
            underline_val: NSUnderlineStyle,
            baseline_offset: CGFloat,
            line_rect: NSRect,
            line_glyph_range: NSRange,
            container_origin: NSPoint,
        );

        #[cfg(feature = "NSAttributedString")]
        #[unsafe(method(underlineGlyphRange:underlineType:lineFragmentRect:lineFragmentGlyphRange:containerOrigin:))]
        #[unsafe(method_family = none)]
        pub unsafe fn underlineGlyphRange_underlineType_lineFragmentRect_lineFragmentGlyphRange_containerOrigin(
            &self,
            glyph_range: NSRange,
            underline_val: NSUnderlineStyle,
            line_rect: NSRect,
            line_glyph_range: NSRange,
            container_origin: NSPoint,
        );

        #[cfg(all(feature = "NSAttributedString", feature = "objc2-core-foundation"))]
        #[unsafe(method(drawStrikethroughForGlyphRange:strikethroughType:baselineOffset:lineFragmentRect:lineFragmentGlyphRange:containerOrigin:))]
        #[unsafe(method_family = none)]
        pub unsafe fn drawStrikethroughForGlyphRange_strikethroughType_baselineOffset_lineFragmentRect_lineFragmentGlyphRange_containerOrigin(
            &self,
            glyph_range: NSRange,
            strikethrough_val: NSUnderlineStyle,
            baseline_offset: CGFloat,
            line_rect: NSRect,
            line_glyph_range: NSRange,
            container_origin: NSPoint,
        );

        #[cfg(feature = "NSAttributedString")]
        #[unsafe(method(strikethroughGlyphRange:strikethroughType:lineFragmentRect:lineFragmentGlyphRange:containerOrigin:))]
        #[unsafe(method_family = none)]
        pub unsafe fn strikethroughGlyphRange_strikethroughType_lineFragmentRect_lineFragmentGlyphRange_containerOrigin(
            &self,
            glyph_range: NSRange,
            strikethrough_val: NSUnderlineStyle,
            line_rect: NSRect,
            line_glyph_range: NSRange,
            container_origin: NSPoint,
        );

        #[cfg(feature = "NSCell")]
        #[unsafe(method(showAttachmentCell:inRect:characterIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn showAttachmentCell_inRect_characterIndex(
            &self,
            cell: &NSCell,
            rect: NSRect,
            attachment_index: NSUInteger,
        );

        #[cfg(feature = "NSTextTable")]
        /// ************************ Block information *************************
        #[unsafe(method(setLayoutRect:forTextBlock:glyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLayoutRect_forTextBlock_glyphRange(
            &self,
            rect: NSRect,
            block: &NSTextBlock,
            glyph_range: NSRange,
        );

        #[cfg(feature = "NSTextTable")]
        #[unsafe(method(setBoundsRect:forTextBlock:glyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setBoundsRect_forTextBlock_glyphRange(
            &self,
            rect: NSRect,
            block: &NSTextBlock,
            glyph_range: NSRange,
        );

        #[cfg(feature = "NSTextTable")]
        #[unsafe(method(layoutRectForTextBlock:glyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn layoutRectForTextBlock_glyphRange(
            &self,
            block: &NSTextBlock,
            glyph_range: NSRange,
        ) -> NSRect;

        #[cfg(feature = "NSTextTable")]
        #[unsafe(method(boundsRectForTextBlock:glyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn boundsRectForTextBlock_glyphRange(
            &self,
            block: &NSTextBlock,
            glyph_range: NSRange,
        ) -> NSRect;

        #[cfg(feature = "NSTextTable")]
        #[unsafe(method(layoutRectForTextBlock:atIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn layoutRectForTextBlock_atIndex_effectiveRange(
            &self,
            block: &NSTextBlock,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
        ) -> NSRect;

        #[cfg(feature = "NSTextTable")]
        #[unsafe(method(boundsRectForTextBlock:atIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn boundsRectForTextBlock_atIndex_effectiveRange(
            &self,
            block: &NSTextBlock,
            glyph_index: NSUInteger,
            effective_glyph_range: NSRangePointer,
        ) -> NSRect;

        /// ********************** Temporary attribute support ***********************
        #[unsafe(method(temporaryAttributesAtCharacterIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn temporaryAttributesAtCharacterIndex_effectiveRange(
            &self,
            char_index: NSUInteger,
            effective_char_range: NSRangePointer,
        ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;

        #[unsafe(method(setTemporaryAttributes:forCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTemporaryAttributes_forCharacterRange(
            &self,
            attrs: &NSDictionary<NSAttributedStringKey, AnyObject>,
            char_range: NSRange,
        );

        #[unsafe(method(addTemporaryAttributes:forCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addTemporaryAttributes_forCharacterRange(
            &self,
            attrs: &NSDictionary<NSAttributedStringKey, AnyObject>,
            char_range: NSRange,
        );

        #[unsafe(method(removeTemporaryAttribute:forCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeTemporaryAttribute_forCharacterRange(
            &self,
            attr_name: &NSAttributedStringKey,
            char_range: NSRange,
        );

        #[unsafe(method(temporaryAttribute:atCharacterIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn temporaryAttribute_atCharacterIndex_effectiveRange(
            &self,
            attr_name: &NSAttributedStringKey,
            location: NSUInteger,
            range: NSRangePointer,
        ) -> Option<Retained<AnyObject>>;

        #[unsafe(method(temporaryAttribute:atCharacterIndex:longestEffectiveRange:inRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn temporaryAttribute_atCharacterIndex_longestEffectiveRange_inRange(
            &self,
            attr_name: &NSAttributedStringKey,
            location: NSUInteger,
            range: NSRangePointer,
            range_limit: NSRange,
        ) -> Option<Retained<AnyObject>>;

        #[unsafe(method(temporaryAttributesAtCharacterIndex:longestEffectiveRange:inRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn temporaryAttributesAtCharacterIndex_longestEffectiveRange_inRange(
            &self,
            location: NSUInteger,
            range: NSRangePointer,
            range_limit: NSRange,
        ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;

        #[unsafe(method(addTemporaryAttribute:value:forCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addTemporaryAttribute_value_forCharacterRange(
            &self,
            attr_name: &NSAttributedStringKey,
            value: &AnyObject,
            char_range: NSRange,
        );

        #[cfg(all(feature = "NSFont", feature = "objc2-core-foundation"))]
        /// ***************************** Font metrics *****************************
        #[unsafe(method(defaultLineHeightForFont:))]
        #[unsafe(method_family = none)]
        pub unsafe fn defaultLineHeightForFont(&self, the_font: &NSFont) -> CGFloat;

        #[cfg(all(feature = "NSFont", feature = "objc2-core-foundation"))]
        #[unsafe(method(defaultBaselineOffsetForFont:))]
        #[unsafe(method_family = none)]
        pub unsafe fn defaultBaselineOffsetForFont(&self, the_font: &NSFont) -> CGFloat;
    );
}

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

/// NSTextViewSupport.
impl NSLayoutManager {
    extern_methods!(
        #[cfg(all(
            feature = "NSParagraphStyle",
            feature = "NSResponder",
            feature = "NSRulerMarker",
            feature = "NSRulerView",
            feature = "NSText",
            feature = "NSTextView",
            feature = "NSView"
        ))]
        /// *************************** Ruler support ****************************
        #[unsafe(method(rulerMarkersForTextView:paragraphStyle:ruler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn rulerMarkersForTextView_paragraphStyle_ruler(
            &self,
            view: &NSTextView,
            style: &NSParagraphStyle,
            ruler: &NSRulerView,
        ) -> Retained<NSArray<NSRulerMarker>>;

        #[cfg(all(
            feature = "NSParagraphStyle",
            feature = "NSResponder",
            feature = "NSRulerView",
            feature = "NSText",
            feature = "NSTextView",
            feature = "NSView"
        ))]
        #[unsafe(method(rulerAccessoryViewForTextView:paragraphStyle:ruler:enabled:))]
        #[unsafe(method_family = none)]
        pub unsafe fn rulerAccessoryViewForTextView_paragraphStyle_ruler_enabled(
            &self,
            view: &NSTextView,
            style: &NSParagraphStyle,
            ruler: &NSRulerView,
            is_enabled: bool,
        ) -> Option<Retained<NSView>>;

        #[cfg(all(feature = "NSResponder", feature = "NSWindow"))]
        /// ********************** First responder support ***********************
        #[unsafe(method(layoutManagerOwnsFirstResponderInWindow:))]
        #[unsafe(method_family = none)]
        pub unsafe fn layoutManagerOwnsFirstResponderInWindow(&self, window: &NSWindow) -> bool;

        #[cfg(all(
            feature = "NSResponder",
            feature = "NSText",
            feature = "NSTextView",
            feature = "NSView"
        ))]
        #[unsafe(method(firstTextView))]
        #[unsafe(method_family = none)]
        pub unsafe fn firstTextView(&self, mtm: MainThreadMarker) -> Option<Retained<NSTextView>>;

        #[cfg(all(
            feature = "NSResponder",
            feature = "NSText",
            feature = "NSTextView",
            feature = "NSView"
        ))]
        #[unsafe(method(textViewForBeginningOfSelection))]
        #[unsafe(method_family = none)]
        pub unsafe fn textViewForBeginningOfSelection(
            &self,
            mtm: MainThreadMarker,
        ) -> Option<Retained<NSTextView>>;
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nslayoutmanagerdelegate?language=objc)
    pub unsafe trait NSLayoutManagerDelegate: NSObjectProtocol {
        #[cfg(all(feature = "NSFont", feature = "objc2-core-graphics"))]
        #[cfg(target_vendor = "apple")]
        /// ********************** Glyph generation ***********************
        #[optional]
        #[unsafe(method(layoutManager:shouldGenerateGlyphs:properties:characterIndexes:font:forGlyphRange:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_shouldGenerateGlyphs_properties_characterIndexes_font_forGlyphRange(
            &self,
            layout_manager: &NSLayoutManager,
            glyphs: NonNull<CGGlyph>,
            props: NonNull<NSGlyphProperty>,
            char_indexes: NonNull<NSUInteger>,
            a_font: &NSFont,
            glyph_range: NSRange,
        ) -> NSUInteger;

        #[cfg(feature = "objc2-core-foundation")]
        /// ********************** Line layout ***********************
        #[optional]
        #[unsafe(method(layoutManager:lineSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_lineSpacingAfterGlyphAtIndex_withProposedLineFragmentRect(
            &self,
            layout_manager: &NSLayoutManager,
            glyph_index: NSUInteger,
            rect: NSRect,
        ) -> CGFloat;

        #[cfg(feature = "objc2-core-foundation")]
        #[optional]
        #[unsafe(method(layoutManager:paragraphSpacingBeforeGlyphAtIndex:withProposedLineFragmentRect:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_paragraphSpacingBeforeGlyphAtIndex_withProposedLineFragmentRect(
            &self,
            layout_manager: &NSLayoutManager,
            glyph_index: NSUInteger,
            rect: NSRect,
        ) -> CGFloat;

        #[cfg(feature = "objc2-core-foundation")]
        #[optional]
        #[unsafe(method(layoutManager:paragraphSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_paragraphSpacingAfterGlyphAtIndex_withProposedLineFragmentRect(
            &self,
            layout_manager: &NSLayoutManager,
            glyph_index: NSUInteger,
            rect: NSRect,
        ) -> CGFloat;

        #[optional]
        #[unsafe(method(layoutManager:shouldUseAction:forControlCharacterAtIndex:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_shouldUseAction_forControlCharacterAtIndex(
            &self,
            layout_manager: &NSLayoutManager,
            action: NSControlCharacterAction,
            char_index: NSUInteger,
        ) -> NSControlCharacterAction;

        #[optional]
        #[unsafe(method(layoutManager:shouldBreakLineByWordBeforeCharacterAtIndex:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_shouldBreakLineByWordBeforeCharacterAtIndex(
            &self,
            layout_manager: &NSLayoutManager,
            char_index: NSUInteger,
        ) -> bool;

        #[optional]
        #[unsafe(method(layoutManager:shouldBreakLineByHyphenatingBeforeCharacterAtIndex:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_shouldBreakLineByHyphenatingBeforeCharacterAtIndex(
            &self,
            layout_manager: &NSLayoutManager,
            char_index: NSUInteger,
        ) -> bool;

        #[cfg(feature = "NSTextContainer")]
        #[optional]
        #[unsafe(method(layoutManager:boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment:glyphPosition:characterIndex:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_boundingBoxForControlGlyphAtIndex_forTextContainer_proposedLineFragment_glyphPosition_characterIndex(
            &self,
            layout_manager: &NSLayoutManager,
            glyph_index: NSUInteger,
            text_container: &NSTextContainer,
            proposed_rect: NSRect,
            glyph_position: NSPoint,
            char_index: NSUInteger,
        ) -> NSRect;

        #[cfg(all(feature = "NSTextContainer", feature = "objc2-core-foundation"))]
        #[optional]
        #[unsafe(method(layoutManager:shouldSetLineFragmentRect:lineFragmentUsedRect:baselineOffset:inTextContainer:forGlyphRange:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_shouldSetLineFragmentRect_lineFragmentUsedRect_baselineOffset_inTextContainer_forGlyphRange(
            &self,
            layout_manager: &NSLayoutManager,
            line_fragment_rect: NonNull<NSRect>,
            line_fragment_used_rect: NonNull<NSRect>,
            baseline_offset: NonNull<CGFloat>,
            text_container: &NSTextContainer,
            glyph_range: NSRange,
        ) -> bool;

        /// ********************** Layout processing ***********************
        #[optional]
        #[unsafe(method(layoutManagerDidInvalidateLayout:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManagerDidInvalidateLayout(&self, sender: &NSLayoutManager);

        #[cfg(feature = "NSTextContainer")]
        #[optional]
        #[unsafe(method(layoutManager:didCompleteLayoutForTextContainer:atEnd:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_didCompleteLayoutForTextContainer_atEnd(
            &self,
            layout_manager: &NSLayoutManager,
            text_container: Option<&NSTextContainer>,
            layout_finished_flag: bool,
        );

        #[cfg(feature = "NSTextContainer")]
        #[optional]
        #[unsafe(method(layoutManager:textContainer:didChangeGeometryFromSize:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_textContainer_didChangeGeometryFromSize(
            &self,
            layout_manager: &NSLayoutManager,
            text_container: &NSTextContainer,
            old_size: NSSize,
        );

        #[optional]
        #[unsafe(method(layoutManager:shouldUseTemporaryAttributes:forDrawingToScreen:atCharacterIndex:effectiveRange:))]
        #[unsafe(method_family = none)]
        unsafe fn layoutManager_shouldUseTemporaryAttributes_forDrawingToScreen_atCharacterIndex_effectiveRange(
            &self,
            layout_manager: &NSLayoutManager,
            attrs: &NSDictionary<NSAttributedStringKey, AnyObject>,
            to_screen: bool,
            char_index: NSUInteger,
            effective_char_range: NSRangePointer,
        ) -> Option<Retained<NSDictionary<NSAttributedStringKey, AnyObject>>>;
    }
);

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsglyphattributesoft?language=objc)
#[deprecated]
pub const NSGlyphAttributeSoft: c_uint = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsglyphattributeelastic?language=objc)
#[deprecated]
pub const NSGlyphAttributeElastic: c_uint = 1;
/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsglyphattributebidilevel?language=objc)
#[deprecated]
pub const NSGlyphAttributeBidiLevel: c_uint = 2;
/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsglyphattributeinscribe?language=objc)
#[deprecated]
pub const NSGlyphAttributeInscribe: c_uint = 5;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsglyphinscription?language=objc)
// NS_ENUM
#[deprecated = "Use NSGlyphProperty instead"]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSGlyphInscription(pub NSUInteger);
impl NSGlyphInscription {
    #[deprecated]
    #[doc(alias = "NSGlyphInscribeBase")]
    pub const InscribeBase: Self = Self(0);
    #[deprecated]
    #[doc(alias = "NSGlyphInscribeBelow")]
    pub const InscribeBelow: Self = Self(1);
    #[deprecated]
    #[doc(alias = "NSGlyphInscribeAbove")]
    pub const InscribeAbove: Self = Self(2);
    #[deprecated]
    #[doc(alias = "NSGlyphInscribeOverstrike")]
    pub const InscribeOverstrike: Self = Self(3);
    #[deprecated]
    #[doc(alias = "NSGlyphInscribeOverBelow")]
    pub const InscribeOverBelow: Self = Self(4);
}

unsafe impl Encode for NSGlyphInscription {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

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

/// NSLayoutManagerDeprecated.
impl NSLayoutManager {
    extern_methods!(
        #[cfg(feature = "NSFont")]
        #[unsafe(method(glyphAtIndex:isValidIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphAtIndex_isValidIndex(
            &self,
            glyph_index: NSUInteger,
            is_valid_index: *mut Bool,
        ) -> NSGlyph;

        #[cfg(feature = "NSFont")]
        #[unsafe(method(glyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphAtIndex(&self, glyph_index: NSUInteger) -> NSGlyph;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(rectArrayForCharacterRange:withinSelectedCharacterRange:inTextContainer:rectCount:))]
        #[unsafe(method_family = none)]
        pub unsafe fn rectArrayForCharacterRange_withinSelectedCharacterRange_inTextContainer_rectCount(
            &self,
            char_range: NSRange,
            sel_char_range: NSRange,
            container: &NSTextContainer,
            rect_count: NonNull<NSUInteger>,
        ) -> NSRectArray;

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(rectArrayForGlyphRange:withinSelectedGlyphRange:inTextContainer:rectCount:))]
        #[unsafe(method_family = none)]
        pub unsafe fn rectArrayForGlyphRange_withinSelectedGlyphRange_inTextContainer_rectCount(
            &self,
            glyph_range: NSRange,
            sel_glyph_range: NSRange,
            container: &NSTextContainer,
            rect_count: NonNull<NSUInteger>,
        ) -> NSRectArray;

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

        /// Setter for [`usesScreenFonts`][Self::usesScreenFonts].
        #[deprecated]
        #[unsafe(method(setUsesScreenFonts:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setUsesScreenFonts(&self, uses_screen_fonts: bool);

        #[cfg(feature = "NSFont")]
        #[deprecated]
        #[unsafe(method(substituteFontForFont:))]
        #[unsafe(method_family = none)]
        pub unsafe fn substituteFontForFont(&self, original_font: &NSFont) -> Retained<NSFont>;

        #[cfg(feature = "NSFont")]
        #[deprecated = "Use -setGlyphs:properties:characterIndexes:font:forGlyphRange instead"]
        #[unsafe(method(insertGlyphs:length:forStartingGlyphAtIndex:characterIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn insertGlyphs_length_forStartingGlyphAtIndex_characterIndex(
            &self,
            glyphs: NonNull<NSGlyph>,
            length: NSUInteger,
            glyph_index: NSUInteger,
            char_index: NSUInteger,
        );

        #[cfg(feature = "NSFont")]
        #[deprecated = "Use -setGlyphs:properties:characterIndexes:font:forGlyphRange instead"]
        #[unsafe(method(insertGlyph:atGlyphIndex:characterIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn insertGlyph_atGlyphIndex_characterIndex(
            &self,
            glyph: NSGlyph,
            glyph_index: NSUInteger,
            char_index: NSUInteger,
        );

        #[cfg(feature = "NSFont")]
        #[deprecated = "Use -setGlyphs:properties:characterIndexes:font:forGlyphRange instead"]
        #[unsafe(method(replaceGlyphAtIndex:withGlyph:))]
        #[unsafe(method_family = none)]
        pub unsafe fn replaceGlyphAtIndex_withGlyph(
            &self,
            glyph_index: NSUInteger,
            new_glyph: NSGlyph,
        );

        #[deprecated = "Use -setGlyphs:properties:characterIndexes:font:forGlyphRange instead"]
        #[unsafe(method(deleteGlyphsInRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn deleteGlyphsInRange(&self, glyph_range: NSRange);

        #[deprecated = "Use -setGlyphs:properties:characterIndexes:font:forGlyphRange instead"]
        #[unsafe(method(setCharacterIndex:forGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCharacterIndex_forGlyphAtIndex(
            &self,
            char_index: NSUInteger,
            glyph_index: NSUInteger,
        );

        #[deprecated = "Use -setGlyphs:properties:characterIndexes:font:forGlyphRange instead"]
        #[unsafe(method(setIntAttribute:value:forGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setIntAttribute_value_forGlyphAtIndex(
            &self,
            attribute_tag: NSInteger,
            val: NSInteger,
            glyph_index: NSUInteger,
        );

        #[deprecated = "Use -setGlyphs:properties:characterIndexes:font:forGlyphRange instead"]
        #[unsafe(method(invalidateGlyphsOnLayoutInvalidationForGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn invalidateGlyphsOnLayoutInvalidationForGlyphRange(
            &self,
            glyph_range: NSRange,
        );

        #[deprecated = "Use -getGlyphsInRange:glyphs:properties:characterIndexes:bidiLevels: instead"]
        #[unsafe(method(intAttribute:forGlyphAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn intAttribute_forGlyphAtIndex(
            &self,
            attribute_tag: NSInteger,
            glyph_index: NSUInteger,
        ) -> NSInteger;

        #[cfg(feature = "NSFont")]
        #[deprecated = "Use -getGlyphsInRange:glyphs:properties:characterIndexes:bidiLevels: instead"]
        #[unsafe(method(getGlyphsInRange:glyphs:characterIndexes:glyphInscriptions:elasticBits:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getGlyphsInRange_glyphs_characterIndexes_glyphInscriptions_elasticBits(
            &self,
            glyph_range: NSRange,
            glyph_buffer: *mut NSGlyph,
            char_index_buffer: *mut NSUInteger,
            inscribe_buffer: *mut NSGlyphInscription,
            elastic_buffer: *mut Bool,
        ) -> NSUInteger;

        #[cfg(feature = "NSFont")]
        #[deprecated = "Use -getGlyphsInRange:glyphs:properties:characterIndexes:bidiLevels: instead"]
        #[unsafe(method(getGlyphsInRange:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getGlyphsInRange_glyphs_characterIndexes_glyphInscriptions_elasticBits_bidiLevels(
            &self,
            glyph_range: NSRange,
            glyph_buffer: *mut NSGlyph,
            char_index_buffer: *mut NSUInteger,
            inscribe_buffer: *mut NSGlyphInscription,
            elastic_buffer: *mut Bool,
            bidi_level_buffer: *mut c_uchar,
        ) -> NSUInteger;

        #[cfg(feature = "NSFont")]
        #[deprecated = "Use -getGlyphsInRange:glyphs:properties:characterIndexes:bidiLevels: instead"]
        #[unsafe(method(getGlyphs:range:))]
        #[unsafe(method_family = none)]
        pub unsafe fn getGlyphs_range(
            &self,
            glyph_array: *mut NSGlyph,
            glyph_range: NSRange,
        ) -> NSUInteger;

        #[deprecated = "Use -invalidateLayoutForCharacterRange:actualCharacterRange: instead"]
        #[unsafe(method(invalidateLayoutForCharacterRange:isSoft:actualCharacterRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn invalidateLayoutForCharacterRange_isSoft_actualCharacterRange(
            &self,
            char_range: NSRange,
            flag: bool,
            actual_char_range: NSRangePointer,
        );

        #[cfg(feature = "NSTextStorage")]
        #[deprecated = "Use -processEditingForTextStorage:edited:range:changeInLength:invalidatedRange: instead"]
        #[unsafe(method(textStorage:edited:range:changeInLength:invalidatedRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn textStorage_edited_range_changeInLength_invalidatedRange(
            &self,
            str: &NSTextStorage,
            edited_mask: NSTextStorageEditedOptions,
            new_char_range: NSRange,
            delta: NSInteger,
            invalidated_char_range: NSRange,
        );

        #[deprecated = "Use -setLocation:forStartOfGlyphRange: instead"]
        #[unsafe(method(setLocations:startingGlyphIndexes:count:forGlyphRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLocations_startingGlyphIndexes_count_forGlyphRange(
            &self,
            locations: NSPointArray,
            glyph_indexes: NonNull<NSUInteger>,
            count: NSUInteger,
            glyph_range: NSRange,
        );

        #[cfg(all(feature = "NSColor", feature = "NSFont"))]
        #[deprecated = "Use -showCGGlyphs:positions:count:font:matrix:attributes:inContext: instead"]
        #[unsafe(method(showPackedGlyphs:length:glyphRange:atPoint:font:color:printingAdjustment:))]
        #[unsafe(method_family = none)]
        pub unsafe fn showPackedGlyphs_length_glyphRange_atPoint_font_color_printingAdjustment(
            &self,
            glyphs: NonNull<c_char>,
            glyph_len: NSUInteger,
            glyph_range: NSRange,
            point: NSPoint,
            font: &NSFont,
            color: &NSColor,
            printing_adjustment: NSSize,
        );

        #[cfg(all(
            feature = "NSFont",
            feature = "NSGraphicsContext",
            feature = "objc2-core-graphics"
        ))]
        #[cfg(target_vendor = "apple")]
        #[deprecated]
        #[unsafe(method(showCGGlyphs:positions:count:font:matrix:attributes:inContext:))]
        #[unsafe(method_family = none)]
        pub unsafe fn showCGGlyphs_positions_count_font_matrix_attributes_inContext(
            &self,
            glyphs: NonNull<CGGlyph>,
            positions: NonNull<NSPoint>,
            glyph_count: NSUInteger,
            font: &NSFont,
            text_matrix: &NSAffineTransform,
            attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
            graphics_context: &NSGraphicsContext,
        );

        #[deprecated = "Please use usesDefaultHyphenation or -[NSParagraphStyle hyphenationFactor] instead."]
        #[unsafe(method(hyphenationFactor))]
        #[unsafe(method_family = none)]
        pub unsafe fn hyphenationFactor(&self) -> c_float;

        /// Setter for [`hyphenationFactor`][Self::hyphenationFactor].
        #[deprecated = "Please use usesDefaultHyphenation or -[NSParagraphStyle hyphenationFactor] instead."]
        #[unsafe(method(setHyphenationFactor:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHyphenationFactor(&self, hyphenation_factor: c_float);
    );
}

/// NSGlyphGeneration.
impl NSLayoutManager {
    extern_methods!(
        #[cfg(feature = "NSGlyphGenerator")]
        #[unsafe(method(glyphGenerator))]
        #[unsafe(method_family = none)]
        pub unsafe fn glyphGenerator(&self) -> Retained<NSGlyphGenerator>;

        #[cfg(feature = "NSGlyphGenerator")]
        /// Setter for [`glyphGenerator`][Self::glyphGenerator].
        #[unsafe(method(setGlyphGenerator:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setGlyphGenerator(&self, glyph_generator: &NSGlyphGenerator);
    );
}

#[cfg(feature = "NSGlyphGenerator")]
unsafe impl NSGlyphStorage for NSLayoutManager {}
