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