objc2_ui_kit/generated/
UITextSearching.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uitextsearchdocumentidentifier?language=objc)
11pub type UITextSearchDocumentIdentifier = AnyObject;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uitextsearchfoundtextstyle?language=objc)
14// NS_ENUM
15#[repr(transparent)]
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
17pub struct UITextSearchFoundTextStyle(pub NSInteger);
18impl UITextSearchFoundTextStyle {
19    /// No style.
20    #[doc(alias = "UITextSearchFoundTextStyleNormal")]
21    pub const Normal: Self = Self(0);
22    /// "Found" style. Used to indicate matches that have been found, but not currently highlighted.
23    #[doc(alias = "UITextSearchFoundTextStyleFound")]
24    pub const Found: Self = Self(1);
25    /// Highlighted style, used to indicate a match that is found and currently highlighted.
26    #[doc(alias = "UITextSearchFoundTextStyleHighlighted")]
27    pub const Highlighted: Self = Self(2);
28}
29
30unsafe impl Encode for UITextSearchFoundTextStyle {
31    const ENCODING: Encoding = NSInteger::ENCODING;
32}
33
34unsafe impl RefEncode for UITextSearchFoundTextStyle {
35    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38extern_protocol!(
39    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uitextsearchaggregator?language=objc)
40    pub unsafe trait UITextSearchAggregator: NSObjectProtocol + MainThreadOnly {
41        #[cfg(feature = "UITextInput")]
42        /// Returns all currently reported found ranges via
43        /// `foundRange:forSearchString:.`
44        #[unsafe(method(allFoundRanges))]
45        #[unsafe(method_family = none)]
46        unsafe fn allFoundRanges(&self) -> Retained<NSOrderedSet<UITextRange>>;
47
48        #[cfg(feature = "UITextInput")]
49        /// Call this method when a range of text is found in your document.
50        ///
51        ///
52        /// Parameter `range`: The range of text that was found.
53        ///
54        /// Parameter `string`: The query string that was used to locate this range of text.
55        ///
56        /// Parameter `document`: (Optional) A developer-defined document identifier, later provided when this range
57        /// needs to be styled.
58        #[unsafe(method(foundRange:forSearchString:inDocument:))]
59        #[unsafe(method_family = none)]
60        unsafe fn foundRange_forSearchString_inDocument(
61            &self,
62            range: &UITextRange,
63            string: &NSString,
64            document: Option<&UITextSearchDocumentIdentifier>,
65        );
66
67        #[cfg(feature = "UITextInput")]
68        /// Call this method when a found
69        /// `range`is no longer in
70        /// `document`. This will cause the system find
71        /// panel to update it's current state, and if the range provided is the currently highlighted range, will advance
72        /// to the next found result.
73        ///
74        ///
75        /// Parameter `range`: The range that is now invalid.
76        ///
77        /// Parameter `document`: (Optional) If multiple documents are used, the document identifier for the range provided.
78        #[unsafe(method(invalidateFoundRange:inDocument:))]
79        #[unsafe(method_family = none)]
80        unsafe fn invalidateFoundRange_inDocument(
81            &self,
82            range: &UITextRange,
83            document: Option<&UITextSearchDocumentIdentifier>,
84        );
85
86        /// Call this method to invalidate all currently shown ranges. This will cause the system find panel to update
87        /// it's current state, and may trigger a new search using `performTextSearchWithQueryString:` immediately after.
88        #[unsafe(method(invalidate))]
89        #[unsafe(method_family = none)]
90        unsafe fn invalidate(&self);
91
92        /// Call this method after all documents have been searched.
93        #[unsafe(method(finishedSearching))]
94        #[unsafe(method_family = none)]
95        unsafe fn finishedSearching(&self);
96    }
97);
98
99extern_protocol!(
100    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uitextsearching?language=objc)
101    pub unsafe trait UITextSearching: NSObjectProtocol + MainThreadOnly {
102        #[cfg(feature = "UITextInput")]
103        /// Overlap from UITextInput: Returns the currently selected text range, if applicable. Nil otherwise.
104        #[unsafe(method(selectedTextRange))]
105        #[unsafe(method_family = none)]
106        unsafe fn selectedTextRange(&self) -> Option<Retained<UITextRange>>;
107
108        #[cfg(feature = "UITextInput")]
109        /// Provide a comparison result comparing developer-provided
110        /// `fromRange`to
111        /// `toRange`. This is used by
112        /// the system find panel to know which
113        /// `UITextRange`to highlight next when the user taps the "next" or "previous"
114        /// result buttons.
115        ///
116        ///
117        /// Parameter `foundRange`: Developer-provided range to compare from.
118        ///
119        /// Parameter `toRange`: Developer-provided range to compare to.
120        ///
121        /// Parameter `document`: If multiple documents are used, a document identifier will be provided here. Ranges are only
122        /// compared between other ranges of the same document.
123        #[unsafe(method(compareFoundRange:toRange:inDocument:))]
124        #[unsafe(method_family = none)]
125        unsafe fn compareFoundRange_toRange_inDocument(
126            &self,
127            found_range: &UITextRange,
128            to_range: &UITextRange,
129            document: Option<&UITextSearchDocumentIdentifier>,
130        ) -> NSComparisonResult;
131
132        #[cfg(feature = "UIFindSession")]
133        /// Perform a text search (across all available searchable documents) using
134        /// `string.`When results are found,
135        /// provide the results to
136        /// `aggregator.`
137        ///
138        /// Parameter `string`: The query string to search for
139        ///
140        /// Parameter `options`: Search options provided by the user.
141        ///
142        /// Parameter `aggregator`: When results are found, provide them to the aggregator. The aggregator is thread-safe,
143        /// so you may send it messages on other threads.
144        #[unsafe(method(performTextSearchWithQueryString:usingOptions:resultAggregator:))]
145        #[unsafe(method_family = none)]
146        unsafe fn performTextSearchWithQueryString_usingOptions_resultAggregator(
147            &self,
148            string: &NSString,
149            options: &UITextSearchOptions,
150            aggregator: &ProtocolObject<dyn UITextSearchAggregator>,
151        );
152
153        #[cfg(feature = "UITextInput")]
154        /// Given a found
155        /// `range`, decorate this text appropriately using the provided
156        /// `style`type.
157        ///
158        ///
159        /// Parameter `range`: The range of text to decorate.
160        ///
161        /// Parameter `document`: If multiple documents are used, the relevant document identifier is provided here.
162        /// Otherwise nil.
163        ///
164        /// Parameter `style`: A style hint for how to decorate the text. This is ultimately up to the developer, but developers are
165        /// encouraged to match the system's appearance (i.e., UITextView) as close as possible.
166        #[unsafe(method(decorateFoundTextRange:inDocument:usingStyle:))]
167        #[unsafe(method_family = none)]
168        unsafe fn decorateFoundTextRange_inDocument_usingStyle(
169            &self,
170            range: &UITextRange,
171            document: Option<&UITextSearchDocumentIdentifier>,
172            style: UITextSearchFoundTextStyle,
173        );
174
175        /// Called when the current search session has changed or ended, with the expectation that all decorations
176        /// applied via
177        /// `decorateFoundTextRange:usingStyle:`are cleared.
178        #[unsafe(method(clearAllDecoratedFoundText))]
179        #[unsafe(method_family = none)]
180        unsafe fn clearAllDecoratedFoundText(&self);
181
182        /// Return YES if your searchable item also supports replacement. If this method is unimplemented, it is
183        /// assumed that text replacement is not supported.
184        #[optional]
185        #[unsafe(method(supportsTextReplacement))]
186        #[unsafe(method_family = none)]
187        unsafe fn supportsTextReplacement(&self) -> bool;
188
189        #[cfg(feature = "UITextInput")]
190        /// Optionally return NO to disallow the replacement of a particular result
191        /// `range`. This will disable the "replace"
192        /// button in the UI. If this method is unimplemented, it is assumed that all results are replaceable.
193        ///
194        ///
195        /// Parameter `range`: Range to replace.
196        ///
197        /// Parameter `document`: If multiple documents are used, the document from which range originates.
198        ///
199        /// Parameter `replacementText`: Text that the user intends to replace with.
200        #[optional]
201        #[unsafe(method(shouldReplaceFoundTextInRange:inDocument:withText:))]
202        #[unsafe(method_family = none)]
203        unsafe fn shouldReplaceFoundTextInRange_inDocument_withText(
204            &self,
205            range: &UITextRange,
206            document: Option<&UITextSearchDocumentIdentifier>,
207            replacement_text: &NSString,
208        ) -> bool;
209
210        #[cfg(feature = "UITextInput")]
211        /// If you return YES for `-supportsTextReplacement`, this method will be called whenever the user intends to
212        /// replace a range of text.
213        ///
214        ///
215        /// Parameter `range`: The range of text requesting to be replaced.
216        ///
217        /// Parameter `document`: If multiple search documents are used, the relevant document identifier is provided
218        /// here. Otherwise nil.
219        ///
220        /// Parameter `replacementText`: The replacement string.
221        #[optional]
222        #[unsafe(method(replaceFoundTextInRange:inDocument:withText:))]
223        #[unsafe(method_family = none)]
224        unsafe fn replaceFoundTextInRange_inDocument_withText(
225            &self,
226            range: &UITextRange,
227            document: Option<&UITextSearchDocumentIdentifier>,
228            replacement_text: &NSString,
229        );
230
231        #[cfg(feature = "UIFindSession")]
232        /// When replacing all occurrences at once, this method is called instead of the one above.
233        ///
234        ///
235        /// Parameter `queryString`: The search term to replace.
236        ///
237        /// Parameter `options`: Search options provided by the find panel UI.
238        ///
239        /// Parameter `replacementText`: The string to replace it with.
240        #[optional]
241        #[unsafe(method(replaceAllOccurrencesOfQueryString:usingOptions:withText:))]
242        #[unsafe(method_family = none)]
243        unsafe fn replaceAllOccurrencesOfQueryString_usingOptions_withText(
244            &self,
245            query_string: &NSString,
246            options: &UITextSearchOptions,
247            replacement_text: &NSString,
248        );
249
250        #[cfg(feature = "UITextInput")]
251        /// Called when the highlighted search result is about to change to
252        /// `range`.
253        #[optional]
254        #[unsafe(method(willHighlightFoundTextRange:inDocument:))]
255        #[unsafe(method_family = none)]
256        unsafe fn willHighlightFoundTextRange_inDocument(
257            &self,
258            range: &UITextRange,
259            document: Option<&UITextSearchDocumentIdentifier>,
260        );
261
262        #[cfg(feature = "UITextInput")]
263        /// If scrolling is supported, implement this to know when the document should be scrolled to a particular
264        /// search result.
265        ///
266        ///
267        /// Parameter `range`: The text range to scroll to.
268        ///
269        /// Parameter `document`: (Optional) If multiple documents are used, the document identifier to scroll to.
270        #[optional]
271        #[unsafe(method(scrollRangeToVisible:inDocument:))]
272        #[unsafe(method_family = none)]
273        unsafe fn scrollRangeToVisible_inDocument(
274            &self,
275            range: &UITextRange,
276            document: Option<&UITextSearchDocumentIdentifier>,
277        );
278
279        /// Returns the current search document, if applicable. Nil otherwise.
280        #[optional]
281        #[unsafe(method(selectedTextSearchDocument))]
282        #[unsafe(method_family = none)]
283        unsafe fn selectedTextSearchDocument(
284            &self,
285        ) -> Option<Retained<UITextSearchDocumentIdentifier>>;
286
287        /// Returns the visible ordering from `fromDocument` to `toDocument`. If your document identifiers
288        /// are index paths, for example, this would yield the same result as `-[NSIndexPath compare:]`.
289        #[optional]
290        #[unsafe(method(compareOrderFromDocument:toDocument:))]
291        #[unsafe(method_family = none)]
292        unsafe fn compareOrderFromDocument_toDocument(
293            &self,
294            from_document: &UITextSearchDocumentIdentifier,
295            to_document: &UITextSearchDocumentIdentifier,
296        ) -> NSComparisonResult;
297    }
298);