//! 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::*;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfinderaction?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextFinderAction(pub NSInteger);
impl NSTextFinderAction {
    #[doc(alias = "NSTextFinderActionShowFindInterface")]
    pub const ShowFindInterface: Self = Self(1);
    #[doc(alias = "NSTextFinderActionNextMatch")]
    pub const NextMatch: Self = Self(2);
    #[doc(alias = "NSTextFinderActionPreviousMatch")]
    pub const PreviousMatch: Self = Self(3);
    #[doc(alias = "NSTextFinderActionReplaceAll")]
    pub const ReplaceAll: Self = Self(4);
    #[doc(alias = "NSTextFinderActionReplace")]
    pub const Replace: Self = Self(5);
    #[doc(alias = "NSTextFinderActionReplaceAndFind")]
    pub const ReplaceAndFind: Self = Self(6);
    #[doc(alias = "NSTextFinderActionSetSearchString")]
    pub const SetSearchString: Self = Self(7);
    #[doc(alias = "NSTextFinderActionReplaceAllInSelection")]
    pub const ReplaceAllInSelection: Self = Self(8);
    #[doc(alias = "NSTextFinderActionSelectAll")]
    pub const SelectAll: Self = Self(9);
    #[doc(alias = "NSTextFinderActionSelectAllInSelection")]
    pub const SelectAllInSelection: Self = Self(10);
    #[doc(alias = "NSTextFinderActionHideFindInterface")]
    pub const HideFindInterface: Self = Self(11);
    #[doc(alias = "NSTextFinderActionShowReplaceInterface")]
    pub const ShowReplaceInterface: Self = Self(12);
    #[doc(alias = "NSTextFinderActionHideReplaceInterface")]
    pub const HideReplaceInterface: Self = Self(13);
}

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypetextfinderoptionkey?language=objc)
// NS_TYPED_ENUM
pub type NSPasteboardTypeTextFinderOptionKey = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfindercaseinsensitivekey?language=objc)
    pub static NSTextFinderCaseInsensitiveKey: &'static NSPasteboardTypeTextFinderOptionKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfindermatchingtypekey?language=objc)
    pub static NSTextFinderMatchingTypeKey: &'static NSPasteboardTypeTextFinderOptionKey;
}

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfindermatchingtype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextFinderMatchingType(pub NSInteger);
impl NSTextFinderMatchingType {
    #[doc(alias = "NSTextFinderMatchingTypeContains")]
    pub const Contains: Self = Self(0);
    #[doc(alias = "NSTextFinderMatchingTypeStartsWith")]
    pub const StartsWith: Self = Self(1);
    #[doc(alias = "NSTextFinderMatchingTypeFullWord")]
    pub const FullWord: Self = Self(2);
    #[doc(alias = "NSTextFinderMatchingTypeEndsWith")]
    pub const EndsWith: Self = Self(3);
}

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

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

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

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

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

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

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

        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[unsafe(method(client))]
        #[unsafe(method_family = none)]
        pub unsafe fn client(&self) -> Option<Retained<ProtocolObject<dyn NSTextFinderClient>>>;

        /// Setter for [`client`][Self::client].
        ///
        /// # Safety
        ///
        /// This is unretained, you must ensure the object is kept alive while in use.
        #[unsafe(method(setClient:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setClient(&self, client: Option<&ProtocolObject<dyn NSTextFinderClient>>);

        #[unsafe(method(performAction:))]
        #[unsafe(method_family = none)]
        pub fn performAction(&self, op: NSTextFinderAction);

        #[unsafe(method(validateAction:))]
        #[unsafe(method_family = none)]
        pub fn validateAction(&self, op: NSTextFinderAction) -> bool;

        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[unsafe(method(findBarContainer))]
        #[unsafe(method_family = none)]
        pub unsafe fn findBarContainer(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSTextFinderBarContainer>>>;

        /// Setter for [`findBarContainer`][Self::findBarContainer].
        ///
        /// # Safety
        ///
        /// This is unretained, you must ensure the object is kept alive while in use.
        #[unsafe(method(setFindBarContainer:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFindBarContainer(
            &self,
            find_bar_container: Option<&ProtocolObject<dyn NSTextFinderBarContainer>>,
        );

        #[unsafe(method(cancelFindIndicator))]
        #[unsafe(method_family = none)]
        pub fn cancelFindIndicator(&self);

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

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

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

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

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

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

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

        #[unsafe(method(drawIncrementalMatchHighlightInRect:))]
        #[unsafe(method_family = none)]
        pub fn drawIncrementalMatchHighlightInRect(rect: NSRect);

        #[unsafe(method(noteClientStringWillChange))]
        #[unsafe(method_family = none)]
        pub fn noteClientStringWillChange(&self);
    );
}

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

impl DefaultRetained for NSTextFinder {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfinderclient?language=objc)
    pub unsafe trait NSTextFinderClient: NSObjectProtocol {
        #[optional]
        #[unsafe(method(isSelectable))]
        #[unsafe(method_family = none)]
        fn isSelectable(&self) -> bool;

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

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

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

        /// # Safety
        ///
        /// - `out_range` must be a valid pointer.
        /// - `out_flag` must be a valid pointer.
        #[optional]
        #[unsafe(method(stringAtIndex:effectiveRange:endsWithSearchBoundary:))]
        #[unsafe(method_family = none)]
        unsafe fn stringAtIndex_effectiveRange_endsWithSearchBoundary(
            &self,
            character_index: NSUInteger,
            out_range: NSRangePointer,
            out_flag: NonNull<Bool>,
        ) -> Retained<NSString>;

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

        #[optional]
        #[unsafe(method(firstSelectedRange))]
        #[unsafe(method_family = none)]
        fn firstSelectedRange(&self) -> NSRange;

        #[optional]
        #[unsafe(method(selectedRanges))]
        #[unsafe(method_family = none)]
        fn selectedRanges(&self) -> Retained<NSArray<NSValue>>;

        /// Setter for [`selectedRanges`][Self::selectedRanges].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[optional]
        #[unsafe(method(setSelectedRanges:))]
        #[unsafe(method_family = none)]
        fn setSelectedRanges(&self, selected_ranges: &NSArray<NSValue>);

        #[optional]
        #[unsafe(method(scrollRangeToVisible:))]
        #[unsafe(method_family = none)]
        fn scrollRangeToVisible(&self, range: NSRange);

        #[optional]
        #[unsafe(method(shouldReplaceCharactersInRanges:withStrings:))]
        #[unsafe(method_family = none)]
        fn shouldReplaceCharactersInRanges_withStrings(
            &self,
            ranges: &NSArray<NSValue>,
            strings: &NSArray<NSString>,
        ) -> bool;

        #[optional]
        #[unsafe(method(replaceCharactersInRange:withString:))]
        #[unsafe(method_family = none)]
        fn replaceCharactersInRange_withString(&self, range: NSRange, string: &NSString);

        #[optional]
        #[unsafe(method(didReplaceCharacters))]
        #[unsafe(method_family = none)]
        fn didReplaceCharacters(&self);

        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        /// # Safety
        ///
        /// `out_range` must be a valid pointer.
        #[optional]
        #[unsafe(method(contentViewAtIndex:effectiveCharacterRange:))]
        #[unsafe(method_family = none)]
        unsafe fn contentViewAtIndex_effectiveCharacterRange(
            &self,
            index: NSUInteger,
            out_range: NSRangePointer,
            mtm: MainThreadMarker,
        ) -> Retained<NSView>;

        #[optional]
        #[unsafe(method(rectsForCharacterRange:))]
        #[unsafe(method_family = none)]
        fn rectsForCharacterRange(&self, range: NSRange) -> Option<Retained<NSArray<NSValue>>>;

        #[optional]
        #[unsafe(method(visibleCharacterRanges))]
        #[unsafe(method_family = none)]
        fn visibleCharacterRanges(&self) -> Retained<NSArray<NSValue>>;

        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        #[optional]
        #[unsafe(method(drawCharactersInRange:forContentView:))]
        #[unsafe(method_family = none)]
        fn drawCharactersInRange_forContentView(&self, range: NSRange, view: &NSView);
    }
);

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfinderbarcontainer?language=objc)
    pub unsafe trait NSTextFinderBarContainer: NSObjectProtocol {
        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        #[unsafe(method(findBarView))]
        #[unsafe(method_family = none)]
        fn findBarView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;

        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
        /// Setter for [`findBarView`][Self::findBarView].
        #[unsafe(method(setFindBarView:))]
        #[unsafe(method_family = none)]
        fn setFindBarView(&self, find_bar_view: Option<&NSView>);

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

        /// Setter for [`isFindBarVisible`][Self::isFindBarVisible].
        #[unsafe(method(setFindBarVisible:))]
        #[unsafe(method_family = none)]
        fn setFindBarVisible(&self, find_bar_visible: bool);

        #[unsafe(method(findBarViewDidChangeHeight))]
        #[unsafe(method_family = none)]
        fn findBarViewDidChangeHeight(&self);

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