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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
//! 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::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-quartz-core")]
#[cfg(not(target_os = "watchos"))]
use objc2_quartz_core::*;
use crate::*;
extern_class!(
/// UISearchTextField is the subclass of UITextField used in UISearchBar, and can also be used elsewhere (e.g. as the titleView of a UINavigationItem).
///
/// In addition to its text, a UISearchField can contain tokens. Tokens are discrete representations of non-textual content. Your app might use tokens to represent filters that are being applied in conjunction with the search field’s text. Tokens are always created by the application, and always occur contiguously before the search field’s text.
///
///
/// Note: Because the system drives selection and keyboard behaviors through the UITextInput protocol, and UISearchTextField supports selecting tokens, UISearchTextField assigns UITextPositions to tokens as well as text. If the current selection includes any tokens, their positions are part of the range returned by `UISearchTextField.selectedTextRange`. Use the `textualRange` property to obtain the range of the text field that excludes any tokens.
///
/// Tokens can be programmatically selected by including their position in a range assigned to the `selectedTextRange` property. UISearchTextField does not support placing an insertion point before a token; attempting to do so will select the token instead.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfield?language=objc)
#[unsafe(super(UITextField, UIControl, UIView, UIResponder, NSObject))]
#[thread_kind = MainThreadOnly]
#[derive(Debug, PartialEq, Eq, Hash)]
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
pub struct UISearchTextField;
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView",
feature = "objc2-quartz-core"
))]
#[cfg(not(target_os = "watchos"))]
extern_conformance!(
unsafe impl CALayerDelegate for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl NSCoding for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl NSObjectProtocol for UISearchTextField {}
);
#[cfg(all(
feature = "UIAppearance",
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIAppearance for UISearchTextField {}
);
#[cfg(all(
feature = "UIAppearance",
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIAppearanceContainer for UISearchTextField {}
);
#[cfg(all(
feature = "UIContentSizeCategoryAdjusting",
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIContentSizeCategoryAdjusting for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UICoordinateSpace for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIDynamicBehavior",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIDynamicItem for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIFocus",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIFocusEnvironment for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIFocus",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIFocusItem for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIFocus",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIFocusItemContainer for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UITextInput",
feature = "UITextInputTraits",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIKeyInput for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UILetterformAwareAdjusting",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UILetterformAwareAdjusting for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UIResponderStandardEditActions for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UITextInput",
feature = "UITextInputTraits",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UITextInput for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UITextInputTraits",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UITextInputTraits for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UITraitCollection",
feature = "UIView"
))]
extern_conformance!(
unsafe impl UITraitEnvironment for UISearchTextField {}
);
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
impl UISearchTextField {
extern_methods!(
/// Simple access to the collection of tokens.
#[unsafe(method(tokens))]
#[unsafe(method_family = none)]
pub fn tokens(&self) -> Retained<NSArray<UISearchToken>>;
/// Setter for [`tokens`][Self::tokens].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setTokens:))]
#[unsafe(method_family = none)]
pub fn setTokens(&self, tokens: &NSArray<UISearchToken>);
#[unsafe(method(insertToken:atIndex:))]
#[unsafe(method_family = none)]
pub fn insertToken_atIndex(&self, token: &UISearchToken, token_index: NSInteger);
#[unsafe(method(removeTokenAtIndex:))]
#[unsafe(method_family = none)]
pub fn removeTokenAtIndex(&self, token_index: NSInteger);
#[cfg(feature = "UITextInput")]
/// Returns the position of the provided token. To select a token, assign a UITextRange containing its position to the selectedTextRange property.
#[unsafe(method(positionOfTokenAtIndex:))]
#[unsafe(method_family = none)]
pub fn positionOfTokenAtIndex(&self, token_index: NSInteger) -> Retained<UITextPosition>;
#[cfg(feature = "UITextInput")]
/// Returns the tokens which are contained within the provided range.
///
/// You can use this method to determine which tokens are included in the user’s current selection. The range may span more than one token or a mixture of tokens and text.
#[unsafe(method(tokensInRange:))]
#[unsafe(method_family = none)]
pub fn tokensInRange(&self, text_range: &UITextRange) -> Retained<NSArray<UISearchToken>>;
#[cfg(feature = "UITextInput")]
/// The range that corresponds to the field’s text, exclusive of any tokens.
///
///
/// See: -[
/// <UITextInput
/// > positionWithinRange:atCharacterOffset:]
#[unsafe(method(textualRange))]
#[unsafe(method_family = none)]
pub fn textualRange(&self) -> Retained<UITextRange>;
#[cfg(feature = "UITextInput")]
/// Removes any text contained in the specified range, inserts the provided token at the specified index, and selects the newly-inserted token. Does not replace any tokens within the provided range. If the range intersects the marked text range, the marked text is committed.
///
/// This method is essentially a convenience wrapper around the more fundamental `text`, `tokens`, and `selectedTextRange` properties, providing the selection behavior the user will expect.
///
///
/// Note: Because this method does not remove any tokens in the provided range, the caller can pass the field’s selectedTextRange to convert the selected portion of the text into a token without first having to trim the range.
#[unsafe(method(replaceTextualPortionOfRange:withToken:atIndex:))]
#[unsafe(method_family = none)]
pub fn replaceTextualPortionOfRange_withToken_atIndex(
&self,
text_range: &UITextRange,
token: &UISearchToken,
token_index: NSUInteger,
);
#[cfg(feature = "UIColor")]
/// Set this to nil for tokens to use their default color.
#[unsafe(method(tokenBackgroundColor))]
#[unsafe(method_family = none)]
pub fn tokenBackgroundColor(&self) -> Option<Retained<UIColor>>;
#[cfg(feature = "UIColor")]
/// Setter for [`tokenBackgroundColor`][Self::tokenBackgroundColor].
///
/// # Safety
///
/// `token_background_color` might not allow `None`.
#[unsafe(method(setTokenBackgroundColor:))]
#[unsafe(method_family = none)]
pub unsafe fn setTokenBackgroundColor(&self, token_background_color: Option<&UIColor>);
/// Whether the user can remove tokens through standard actions such as Delete and Cut.
///
/// The application can always remove tokens programmatically. If this property is true, the application must be prepared not only for tokens to be removed, but also to be re-added through Undo. Defaults to true.
#[unsafe(method(allowsDeletingTokens))]
#[unsafe(method_family = none)]
pub fn allowsDeletingTokens(&self) -> bool;
/// Setter for [`allowsDeletingTokens`][Self::allowsDeletingTokens].
#[unsafe(method(setAllowsDeletingTokens:))]
#[unsafe(method_family = none)]
pub fn setAllowsDeletingTokens(&self, allows_deleting_tokens: bool);
/// Whether the user can copy tokens to the pasteboard or drag them out of the text field.
///
/// To support copying tokens, this property must be true and the delegate must provide an item provider for the tokens to be copied. UISearchTextField always enables the Copy command if any plain text is selected, even if the selection also includes tokens and this property is false. Defaults to true.
#[unsafe(method(allowsCopyingTokens))]
#[unsafe(method_family = none)]
pub fn allowsCopyingTokens(&self) -> bool;
/// Setter for [`allowsCopyingTokens`][Self::allowsCopyingTokens].
#[unsafe(method(setAllowsCopyingTokens:))]
#[unsafe(method_family = none)]
pub fn setAllowsCopyingTokens(&self, allows_copying_tokens: bool);
#[cfg(feature = "UISearchSuggestion")]
/// An array of suggestions that will be presented as a menu beneath the search field when nonempty.
/// Set to nil or
/// @
/// [] to dismiss the menu.
/// The menu will also dismiss and the property will be set to nil when a suggestion is selected.
/// The delegate is expected to execute any necessary updating when a suggestion is selected.
#[unsafe(method(searchSuggestions))]
#[unsafe(method_family = none)]
pub fn searchSuggestions(
&self,
) -> Option<Retained<NSArray<ProtocolObject<dyn UISearchSuggestion>>>>;
#[cfg(feature = "UISearchSuggestion")]
/// Setter for [`searchSuggestions`][Self::searchSuggestions].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setSearchSuggestions:))]
#[unsafe(method_family = none)]
pub fn setSearchSuggestions(
&self,
search_suggestions: Option<&NSArray<ProtocolObject<dyn UISearchSuggestion>>>,
);
);
}
/// Methods declared on superclass `UIControl`.
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
impl UISearchTextField {
extern_methods!(
#[cfg(feature = "objc2-core-foundation")]
#[unsafe(method(initWithFrame:))]
#[unsafe(method_family = init)]
pub fn initWithFrame(this: Allocated<Self>, frame: CGRect) -> Retained<Self>;
/// # Safety
///
/// `coder` possibly has further requirements.
#[unsafe(method(initWithCoder:))]
#[unsafe(method_family = init)]
pub unsafe fn initWithCoder(
this: Allocated<Self>,
coder: &NSCoder,
) -> Option<Retained<Self>>;
#[cfg(all(
feature = "UIAction",
feature = "UIMenuElement",
feature = "objc2-core-foundation"
))]
/// Initializes the control and adds primaryAction for the UIControlEventPrimaryActionTriggered control event. Subclasses of UIControl may alter or add behaviors around the usage of primaryAction, see subclass documentation of this initializer for additional information.
#[unsafe(method(initWithFrame:primaryAction:))]
#[unsafe(method_family = init)]
pub fn initWithFrame_primaryAction(
this: Allocated<Self>,
frame: CGRect,
primary_action: Option<&UIAction>,
) -> Retained<Self>;
);
}
/// Methods declared on superclass `UIView`.
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
impl UISearchTextField {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
);
}
/// Methods declared on superclass `NSObject`.
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UITextField",
feature = "UIView"
))]
impl UISearchTextField {
extern_methods!(
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
);
}
extern_class!(
/// An individual token in a UISearchTextField.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtoken?language=objc)
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct UISearchToken;
);
extern_conformance!(
unsafe impl NSObjectProtocol for UISearchToken {}
);
impl UISearchToken {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
#[cfg(feature = "UIImage")]
#[unsafe(method(tokenWithIcon:text:))]
#[unsafe(method_family = none)]
pub fn tokenWithIcon_text(
icon: Option<&UIImage>,
text: &NSString,
mtm: MainThreadMarker,
) -> Retained<UISearchToken>;
/// The object which this token represents.
///
/// The application can assign any object it wants to this property. UISearchTextField does not attempt to interpret this object.
///
///
/// Note: Because UISearchToken strongly references its representedObject, consider assigning a lightweight representation (such as NSManagedObjectID) instead of a complete model object to this property. The lifetime of a UISearchToken may be considerably longer than expected, especially if the token has been copied to a pasteboard.
#[unsafe(method(representedObject))]
#[unsafe(method_family = none)]
pub fn representedObject(&self) -> Option<Retained<AnyObject>>;
/// Setter for [`representedObject`][Self::representedObject].
///
/// # Safety
///
/// `represented_object` should be of the correct type.
#[unsafe(method(setRepresentedObject:))]
#[unsafe(method_family = none)]
pub unsafe fn setRepresentedObject(&self, represented_object: Option<&AnyObject>);
);
}
extern_protocol!(
/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfielddelegate?language=objc)
#[cfg(feature = "UITextField")]
pub unsafe trait UISearchTextFieldDelegate:
UITextFieldDelegate + MainThreadOnly
{
#[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
/// Implements cut and copy of tokens.
///
/// To support drag and drop and the Cut and Copy commands, your delegate must implement this method and return an NSItemProvider for the requested token. The field’s textPasteDelegate is responsible for implementing pasting of tokens. Your delegate can provide a plain text representation for pasting in other contexts, but should register a custom type identifier so it can recognize and reconstruct the token when pasted into the same field.
///
/// This method will only be called if either of the field’s allowsCopyingTokens or allowsDeletingTokens properties is true.
#[optional]
#[unsafe(method(searchTextField:itemProviderForCopyingToken:))]
#[unsafe(method_family = none)]
fn searchTextField_itemProviderForCopyingToken(
&self,
search_text_field: &UISearchTextField,
token: &UISearchToken,
) -> Retained<NSItemProvider>;
#[cfg(all(
feature = "UIControl",
feature = "UIResponder",
feature = "UISearchSuggestion",
feature = "UIView"
))]
/// searchSuggestions property will be set to nil after sending this message
#[optional]
#[unsafe(method(searchTextField:didSelectSuggestion:))]
#[unsafe(method_family = none)]
fn searchTextField_didSelectSuggestion(
&self,
search_text_field: &UISearchTextField,
suggestion: &ProtocolObject<dyn UISearchSuggestion>,
);
}
);
extern_protocol!(
/// A protocol that refines UITextPasteItem to support pasting of tokens.
///
/// Paste items vended by UISearchTextField conform to this protocol.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfieldpasteitem?language=objc)
#[cfg(feature = "UITextPasteDelegate")]
pub unsafe trait UISearchTextFieldPasteItem: UITextPasteItem + MainThreadOnly {
/// Transforms this paste item into a token at the end of the search text field’s token array.
#[unsafe(method(setSearchTokenResult:))]
#[unsafe(method_family = none)]
fn setSearchTokenResult(&self, token: &UISearchToken);
}
);