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        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        ///
59        /// # Safety
60        ///
61        /// `document` should be of the correct type.
62        #[unsafe(method(foundRange:forSearchString:inDocument:))]
63        #[unsafe(method_family = none)]
64        unsafe fn foundRange_forSearchString_inDocument(
65            &self,
66            range: &UITextRange,
67            string: &NSString,
68            document: Option<&UITextSearchDocumentIdentifier>,
69        );
70
71        #[cfg(feature = "UITextInput")]
72        /// Call this method when a found
73        /// `range`is no longer in
74        /// `document`. This will cause the system find
75        /// panel to update it's current state, and if the range provided is the currently highlighted range, will advance
76        /// to the next found result.
77        ///
78        ///
79        /// Parameter `range`: The range that is now invalid.
80        ///
81        /// Parameter `document`: (Optional) If multiple documents are used, the document identifier for the range provided.
82        ///
83        /// # Safety
84        ///
85        /// `document` should be of the correct type.
86        #[unsafe(method(invalidateFoundRange:inDocument:))]
87        #[unsafe(method_family = none)]
88        unsafe fn invalidateFoundRange_inDocument(
89            &self,
90            range: &UITextRange,
91            document: Option<&UITextSearchDocumentIdentifier>,
92        );
93
94        /// Call this method to invalidate all currently shown ranges. This will cause the system find panel to update
95        /// it's current state, and may trigger a new search using `performTextSearchWithQueryString:` immediately after.
96        #[unsafe(method(invalidate))]
97        #[unsafe(method_family = none)]
98        fn invalidate(&self);
99
100        /// Call this method after all documents have been searched.
101        #[unsafe(method(finishedSearching))]
102        #[unsafe(method_family = none)]
103        fn finishedSearching(&self);
104    }
105);
106
107extern_protocol!(
108    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uitextsearching?language=objc)
109    pub unsafe trait UITextSearching: NSObjectProtocol + MainThreadOnly {
110        #[cfg(feature = "UITextInput")]
111        /// Overlap from UITextInput: Returns the currently selected text range, if applicable. Nil otherwise.
112        #[unsafe(method(selectedTextRange))]
113        #[unsafe(method_family = none)]
114        fn selectedTextRange(&self) -> Option<Retained<UITextRange>>;
115
116        #[cfg(feature = "UITextInput")]
117        /// Provide a comparison result comparing developer-provided
118        /// `fromRange`to
119        /// `toRange`. This is used by
120        /// the system find panel to know which
121        /// `UITextRange`to highlight next when the user taps the "next" or "previous"
122        /// result buttons.
123        ///
124        ///
125        /// Parameter `foundRange`: Developer-provided range to compare from.
126        ///
127        /// Parameter `toRange`: Developer-provided range to compare to.
128        ///
129        /// Parameter `document`: If multiple documents are used, a document identifier will be provided here. Ranges are only
130        /// compared between other ranges of the same document.
131        ///
132        /// # Safety
133        ///
134        /// `document` should be of the correct type.
135        #[unsafe(method(compareFoundRange:toRange:inDocument:))]
136        #[unsafe(method_family = none)]
137        unsafe fn compareFoundRange_toRange_inDocument(
138            &self,
139            found_range: &UITextRange,
140            to_range: &UITextRange,
141            document: Option<&UITextSearchDocumentIdentifier>,
142        ) -> NSComparisonResult;
143
144        #[cfg(feature = "UIFindSession")]
145        /// Perform a text search (across all available searchable documents) using
146        /// `string.`When results are found,
147        /// provide the results to
148        /// `aggregator.`
149        ///
150        /// Parameter `string`: The query string to search for
151        ///
152        /// Parameter `options`: Search options provided by the user.
153        ///
154        /// Parameter `aggregator`: When results are found, provide them to the aggregator. The aggregator is thread-safe,
155        /// so you may send it messages on other threads.
156        #[unsafe(method(performTextSearchWithQueryString:usingOptions:resultAggregator:))]
157        #[unsafe(method_family = none)]
158        fn performTextSearchWithQueryString_usingOptions_resultAggregator(
159            &self,
160            string: &NSString,
161            options: &UITextSearchOptions,
162            aggregator: &ProtocolObject<dyn UITextSearchAggregator>,
163        );
164
165        #[cfg(feature = "UITextInput")]
166        /// Given a found
167        /// `range`, decorate this text appropriately using the provided
168        /// `style`type.
169        ///
170        ///
171        /// Parameter `range`: The range of text to decorate.
172        ///
173        /// Parameter `document`: If multiple documents are used, the relevant document identifier is provided here.
174        /// Otherwise nil.
175        ///
176        /// Parameter `style`: A style hint for how to decorate the text. This is ultimately up to the developer, but developers are
177        /// encouraged to match the system's appearance (i.e., UITextView) as close as possible.
178        ///
179        /// # Safety
180        ///
181        /// `document` should be of the correct type.
182        #[unsafe(method(decorateFoundTextRange:inDocument:usingStyle:))]
183        #[unsafe(method_family = none)]
184        unsafe fn decorateFoundTextRange_inDocument_usingStyle(
185            &self,
186            range: &UITextRange,
187            document: Option<&UITextSearchDocumentIdentifier>,
188            style: UITextSearchFoundTextStyle,
189        );
190
191        /// Called when the current search session has changed or ended, with the expectation that all decorations
192        /// applied via
193        /// `decorateFoundTextRange:usingStyle:`are cleared.
194        #[unsafe(method(clearAllDecoratedFoundText))]
195        #[unsafe(method_family = none)]
196        fn clearAllDecoratedFoundText(&self);
197
198        /// Return YES if your searchable item also supports replacement. If this method is unimplemented, it is
199        /// assumed that text replacement is not supported.
200        #[optional]
201        #[unsafe(method(supportsTextReplacement))]
202        #[unsafe(method_family = none)]
203        fn supportsTextReplacement(&self) -> bool;
204
205        #[cfg(feature = "UITextInput")]
206        /// Optionally return NO to disallow the replacement of a particular result
207        /// `range`. This will disable the "replace"
208        /// button in the UI. If this method is unimplemented, it is assumed that all results are replaceable.
209        ///
210        ///
211        /// Parameter `range`: Range to replace.
212        ///
213        /// Parameter `document`: If multiple documents are used, the document from which range originates.
214        ///
215        /// Parameter `replacementText`: Text that the user intends to replace with.
216        ///
217        /// # Safety
218        ///
219        /// `document` should be of the correct type.
220        #[optional]
221        #[unsafe(method(shouldReplaceFoundTextInRange:inDocument:withText:))]
222        #[unsafe(method_family = none)]
223        unsafe fn shouldReplaceFoundTextInRange_inDocument_withText(
224            &self,
225            range: &UITextRange,
226            document: Option<&UITextSearchDocumentIdentifier>,
227            replacement_text: &NSString,
228        ) -> bool;
229
230        #[cfg(feature = "UITextInput")]
231        /// If you return YES for `-supportsTextReplacement`, this method will be called whenever the user intends to
232        /// replace a range of text.
233        ///
234        ///
235        /// Parameter `range`: The range of text requesting to be replaced.
236        ///
237        /// Parameter `document`: If multiple search documents are used, the relevant document identifier is provided
238        /// here. Otherwise nil.
239        ///
240        /// Parameter `replacementText`: The replacement string.
241        ///
242        /// # Safety
243        ///
244        /// `document` should be of the correct type.
245        #[optional]
246        #[unsafe(method(replaceFoundTextInRange:inDocument:withText:))]
247        #[unsafe(method_family = none)]
248        unsafe fn replaceFoundTextInRange_inDocument_withText(
249            &self,
250            range: &UITextRange,
251            document: Option<&UITextSearchDocumentIdentifier>,
252            replacement_text: &NSString,
253        );
254
255        #[cfg(feature = "UIFindSession")]
256        /// When replacing all occurrences at once, this method is called instead of the one above.
257        ///
258        ///
259        /// Parameter `queryString`: The search term to replace.
260        ///
261        /// Parameter `options`: Search options provided by the find panel UI.
262        ///
263        /// Parameter `replacementText`: The string to replace it with.
264        #[optional]
265        #[unsafe(method(replaceAllOccurrencesOfQueryString:usingOptions:withText:))]
266        #[unsafe(method_family = none)]
267        fn replaceAllOccurrencesOfQueryString_usingOptions_withText(
268            &self,
269            query_string: &NSString,
270            options: &UITextSearchOptions,
271            replacement_text: &NSString,
272        );
273
274        #[cfg(feature = "UITextInput")]
275        /// Called when the highlighted search result is about to change to
276        /// `range`.
277        ///
278        /// # Safety
279        ///
280        /// `document` should be of the correct type.
281        #[optional]
282        #[unsafe(method(willHighlightFoundTextRange:inDocument:))]
283        #[unsafe(method_family = none)]
284        unsafe fn willHighlightFoundTextRange_inDocument(
285            &self,
286            range: &UITextRange,
287            document: Option<&UITextSearchDocumentIdentifier>,
288        );
289
290        #[cfg(feature = "UITextInput")]
291        /// If scrolling is supported, implement this to know when the document should be scrolled to a particular
292        /// search result.
293        ///
294        ///
295        /// Parameter `range`: The text range to scroll to.
296        ///
297        /// Parameter `document`: (Optional) If multiple documents are used, the document identifier to scroll to.
298        ///
299        /// # Safety
300        ///
301        /// `document` should be of the correct type.
302        #[optional]
303        #[unsafe(method(scrollRangeToVisible:inDocument:))]
304        #[unsafe(method_family = none)]
305        unsafe fn scrollRangeToVisible_inDocument(
306            &self,
307            range: &UITextRange,
308            document: Option<&UITextSearchDocumentIdentifier>,
309        );
310
311        /// Returns the current search document, if applicable. Nil otherwise.
312        #[optional]
313        #[unsafe(method(selectedTextSearchDocument))]
314        #[unsafe(method_family = none)]
315        fn selectedTextSearchDocument(&self) -> Option<Retained<UITextSearchDocumentIdentifier>>;
316
317        /// Returns the visible ordering from `fromDocument` to `toDocument`. If your document identifiers
318        /// are index paths, for example, this would yield the same result as `-[NSIndexPath compare:]`.
319        ///
320        /// # Safety
321        ///
322        /// - `from_document` should be of the correct type.
323        /// - `to_document` should be of the correct type.
324        #[optional]
325        #[unsafe(method(compareOrderFromDocument:toDocument:))]
326        #[unsafe(method_family = none)]
327        unsafe fn compareOrderFromDocument_toDocument(
328            &self,
329            from_document: &UITextSearchDocumentIdentifier,
330            to_document: &UITextSearchDocumentIdentifier,
331        ) -> NSComparisonResult;
332    }
333);