objc2_ui_kit/generated/
UISearchTextField.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::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9#[cfg(feature = "objc2-quartz-core")]
10#[cfg(not(target_os = "watchos"))]
11use objc2_quartz_core::*;
12
13use crate::*;
14
15extern_class!(
16    /// UISearchTextField is the subclass of UITextField used in UISearchBar, and can also be used elsewhere (e.g. as the titleView of a UINavigationItem).
17    ///
18    /// 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.
19    ///
20    ///
21    /// 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.
22    ///
23    /// 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.
24    ///
25    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfield?language=objc)
26    #[unsafe(super(UITextField, UIControl, UIView, UIResponder, NSObject))]
27    #[thread_kind = MainThreadOnly]
28    #[derive(Debug, PartialEq, Eq, Hash)]
29    #[cfg(all(
30        feature = "UIControl",
31        feature = "UIResponder",
32        feature = "UITextField",
33        feature = "UIView"
34    ))]
35    pub struct UISearchTextField;
36);
37
38#[cfg(all(
39    feature = "UIControl",
40    feature = "UIResponder",
41    feature = "UITextField",
42    feature = "UIView",
43    feature = "objc2-quartz-core"
44))]
45#[cfg(not(target_os = "watchos"))]
46extern_conformance!(
47    unsafe impl CALayerDelegate for UISearchTextField {}
48);
49
50#[cfg(all(
51    feature = "UIControl",
52    feature = "UIResponder",
53    feature = "UITextField",
54    feature = "UIView"
55))]
56extern_conformance!(
57    unsafe impl NSCoding for UISearchTextField {}
58);
59
60#[cfg(all(
61    feature = "UIControl",
62    feature = "UIResponder",
63    feature = "UITextField",
64    feature = "UIView"
65))]
66extern_conformance!(
67    unsafe impl NSObjectProtocol for UISearchTextField {}
68);
69
70#[cfg(all(
71    feature = "UIAppearance",
72    feature = "UIControl",
73    feature = "UIResponder",
74    feature = "UITextField",
75    feature = "UIView"
76))]
77extern_conformance!(
78    unsafe impl UIAppearance for UISearchTextField {}
79);
80
81#[cfg(all(
82    feature = "UIAppearance",
83    feature = "UIControl",
84    feature = "UIResponder",
85    feature = "UITextField",
86    feature = "UIView"
87))]
88extern_conformance!(
89    unsafe impl UIAppearanceContainer for UISearchTextField {}
90);
91
92#[cfg(all(
93    feature = "UIContentSizeCategoryAdjusting",
94    feature = "UIControl",
95    feature = "UIResponder",
96    feature = "UITextField",
97    feature = "UIView"
98))]
99extern_conformance!(
100    unsafe impl UIContentSizeCategoryAdjusting for UISearchTextField {}
101);
102
103#[cfg(all(
104    feature = "UIControl",
105    feature = "UIResponder",
106    feature = "UITextField",
107    feature = "UIView"
108))]
109extern_conformance!(
110    unsafe impl UICoordinateSpace for UISearchTextField {}
111);
112
113#[cfg(all(
114    feature = "UIControl",
115    feature = "UIDynamicBehavior",
116    feature = "UIResponder",
117    feature = "UITextField",
118    feature = "UIView"
119))]
120extern_conformance!(
121    unsafe impl UIDynamicItem for UISearchTextField {}
122);
123
124#[cfg(all(
125    feature = "UIControl",
126    feature = "UIFocus",
127    feature = "UIResponder",
128    feature = "UITextField",
129    feature = "UIView"
130))]
131extern_conformance!(
132    unsafe impl UIFocusEnvironment for UISearchTextField {}
133);
134
135#[cfg(all(
136    feature = "UIControl",
137    feature = "UIFocus",
138    feature = "UIResponder",
139    feature = "UITextField",
140    feature = "UIView"
141))]
142extern_conformance!(
143    unsafe impl UIFocusItem for UISearchTextField {}
144);
145
146#[cfg(all(
147    feature = "UIControl",
148    feature = "UIFocus",
149    feature = "UIResponder",
150    feature = "UITextField",
151    feature = "UIView"
152))]
153extern_conformance!(
154    unsafe impl UIFocusItemContainer for UISearchTextField {}
155);
156
157#[cfg(all(
158    feature = "UIControl",
159    feature = "UIResponder",
160    feature = "UITextField",
161    feature = "UITextInput",
162    feature = "UITextInputTraits",
163    feature = "UIView"
164))]
165extern_conformance!(
166    unsafe impl UIKeyInput for UISearchTextField {}
167);
168
169#[cfg(all(
170    feature = "UIControl",
171    feature = "UILetterformAwareAdjusting",
172    feature = "UIResponder",
173    feature = "UITextField",
174    feature = "UIView"
175))]
176extern_conformance!(
177    unsafe impl UILetterformAwareAdjusting for UISearchTextField {}
178);
179
180#[cfg(all(
181    feature = "UIControl",
182    feature = "UIResponder",
183    feature = "UITextField",
184    feature = "UIView"
185))]
186extern_conformance!(
187    unsafe impl UIResponderStandardEditActions for UISearchTextField {}
188);
189
190#[cfg(all(
191    feature = "UIControl",
192    feature = "UIResponder",
193    feature = "UITextField",
194    feature = "UITextInput",
195    feature = "UITextInputTraits",
196    feature = "UIView"
197))]
198extern_conformance!(
199    unsafe impl UITextInput for UISearchTextField {}
200);
201
202#[cfg(all(
203    feature = "UIControl",
204    feature = "UIResponder",
205    feature = "UITextField",
206    feature = "UITextInputTraits",
207    feature = "UIView"
208))]
209extern_conformance!(
210    unsafe impl UITextInputTraits for UISearchTextField {}
211);
212
213#[cfg(all(
214    feature = "UIControl",
215    feature = "UIResponder",
216    feature = "UITextField",
217    feature = "UITraitCollection",
218    feature = "UIView"
219))]
220extern_conformance!(
221    unsafe impl UITraitEnvironment for UISearchTextField {}
222);
223
224#[cfg(all(
225    feature = "UIControl",
226    feature = "UIResponder",
227    feature = "UITextField",
228    feature = "UIView"
229))]
230impl UISearchTextField {
231    extern_methods!(
232        /// Simple access to the collection of tokens.
233        #[unsafe(method(tokens))]
234        #[unsafe(method_family = none)]
235        pub fn tokens(&self) -> Retained<NSArray<UISearchToken>>;
236
237        /// Setter for [`tokens`][Self::tokens].
238        ///
239        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
240        #[unsafe(method(setTokens:))]
241        #[unsafe(method_family = none)]
242        pub fn setTokens(&self, tokens: &NSArray<UISearchToken>);
243
244        #[unsafe(method(insertToken:atIndex:))]
245        #[unsafe(method_family = none)]
246        pub fn insertToken_atIndex(&self, token: &UISearchToken, token_index: NSInteger);
247
248        #[unsafe(method(removeTokenAtIndex:))]
249        #[unsafe(method_family = none)]
250        pub fn removeTokenAtIndex(&self, token_index: NSInteger);
251
252        #[cfg(feature = "UITextInput")]
253        /// Returns the position of the provided token. To select a token, assign a UITextRange containing its position to the selectedTextRange property.
254        #[unsafe(method(positionOfTokenAtIndex:))]
255        #[unsafe(method_family = none)]
256        pub fn positionOfTokenAtIndex(&self, token_index: NSInteger) -> Retained<UITextPosition>;
257
258        #[cfg(feature = "UITextInput")]
259        /// Returns the tokens which are contained within the provided range.
260        ///
261        /// 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.
262        #[unsafe(method(tokensInRange:))]
263        #[unsafe(method_family = none)]
264        pub fn tokensInRange(&self, text_range: &UITextRange) -> Retained<NSArray<UISearchToken>>;
265
266        #[cfg(feature = "UITextInput")]
267        /// The range that corresponds to the field’s text, exclusive of any tokens.
268        ///
269        ///
270        /// See: -[
271        /// <UITextInput
272        /// > positionWithinRange:atCharacterOffset:]
273        #[unsafe(method(textualRange))]
274        #[unsafe(method_family = none)]
275        pub fn textualRange(&self) -> Retained<UITextRange>;
276
277        #[cfg(feature = "UITextInput")]
278        /// 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.
279        ///
280        /// This method is essentially a convenience wrapper around the more fundamental `text`, `tokens`, and `selectedTextRange` properties, providing the selection behavior the user will expect.
281        ///
282        ///
283        /// 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.
284        #[unsafe(method(replaceTextualPortionOfRange:withToken:atIndex:))]
285        #[unsafe(method_family = none)]
286        pub fn replaceTextualPortionOfRange_withToken_atIndex(
287            &self,
288            text_range: &UITextRange,
289            token: &UISearchToken,
290            token_index: NSUInteger,
291        );
292
293        #[cfg(feature = "UIColor")]
294        /// Set this to nil for tokens to use their default color.
295        #[unsafe(method(tokenBackgroundColor))]
296        #[unsafe(method_family = none)]
297        pub fn tokenBackgroundColor(&self) -> Option<Retained<UIColor>>;
298
299        #[cfg(feature = "UIColor")]
300        /// Setter for [`tokenBackgroundColor`][Self::tokenBackgroundColor].
301        ///
302        /// # Safety
303        ///
304        /// `token_background_color` might not allow `None`.
305        #[unsafe(method(setTokenBackgroundColor:))]
306        #[unsafe(method_family = none)]
307        pub unsafe fn setTokenBackgroundColor(&self, token_background_color: Option<&UIColor>);
308
309        /// Whether the user can remove tokens through standard actions such as Delete and Cut.
310        ///
311        /// 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.
312        #[unsafe(method(allowsDeletingTokens))]
313        #[unsafe(method_family = none)]
314        pub fn allowsDeletingTokens(&self) -> bool;
315
316        /// Setter for [`allowsDeletingTokens`][Self::allowsDeletingTokens].
317        #[unsafe(method(setAllowsDeletingTokens:))]
318        #[unsafe(method_family = none)]
319        pub fn setAllowsDeletingTokens(&self, allows_deleting_tokens: bool);
320
321        /// Whether the user can copy tokens to the pasteboard or drag them out of the text field.
322        ///
323        /// 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.
324        #[unsafe(method(allowsCopyingTokens))]
325        #[unsafe(method_family = none)]
326        pub fn allowsCopyingTokens(&self) -> bool;
327
328        /// Setter for [`allowsCopyingTokens`][Self::allowsCopyingTokens].
329        #[unsafe(method(setAllowsCopyingTokens:))]
330        #[unsafe(method_family = none)]
331        pub fn setAllowsCopyingTokens(&self, allows_copying_tokens: bool);
332
333        #[cfg(feature = "UISearchSuggestion")]
334        /// An array of suggestions that will be presented as a menu beneath the search field when nonempty.
335        /// Set to nil or
336        /// @
337        /// [] to dismiss the menu.
338        /// The menu will also dismiss and the property will be set to nil when a suggestion is selected.
339        /// The delegate is expected to execute any necessary updating when a suggestion is selected.
340        #[unsafe(method(searchSuggestions))]
341        #[unsafe(method_family = none)]
342        pub fn searchSuggestions(
343            &self,
344        ) -> Option<Retained<NSArray<ProtocolObject<dyn UISearchSuggestion>>>>;
345
346        #[cfg(feature = "UISearchSuggestion")]
347        /// Setter for [`searchSuggestions`][Self::searchSuggestions].
348        ///
349        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
350        #[unsafe(method(setSearchSuggestions:))]
351        #[unsafe(method_family = none)]
352        pub fn setSearchSuggestions(
353            &self,
354            search_suggestions: Option<&NSArray<ProtocolObject<dyn UISearchSuggestion>>>,
355        );
356    );
357}
358
359/// Methods declared on superclass `UIControl`.
360#[cfg(all(
361    feature = "UIControl",
362    feature = "UIResponder",
363    feature = "UITextField",
364    feature = "UIView"
365))]
366impl UISearchTextField {
367    extern_methods!(
368        #[cfg(feature = "objc2-core-foundation")]
369        #[unsafe(method(initWithFrame:))]
370        #[unsafe(method_family = init)]
371        pub fn initWithFrame(this: Allocated<Self>, frame: CGRect) -> Retained<Self>;
372
373        /// # Safety
374        ///
375        /// `coder` possibly has further requirements.
376        #[unsafe(method(initWithCoder:))]
377        #[unsafe(method_family = init)]
378        pub unsafe fn initWithCoder(
379            this: Allocated<Self>,
380            coder: &NSCoder,
381        ) -> Option<Retained<Self>>;
382
383        #[cfg(all(
384            feature = "UIAction",
385            feature = "UIMenuElement",
386            feature = "objc2-core-foundation"
387        ))]
388        /// 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.
389        #[unsafe(method(initWithFrame:primaryAction:))]
390        #[unsafe(method_family = init)]
391        pub fn initWithFrame_primaryAction(
392            this: Allocated<Self>,
393            frame: CGRect,
394            primary_action: Option<&UIAction>,
395        ) -> Retained<Self>;
396    );
397}
398
399/// Methods declared on superclass `UIView`.
400#[cfg(all(
401    feature = "UIControl",
402    feature = "UIResponder",
403    feature = "UITextField",
404    feature = "UIView"
405))]
406impl UISearchTextField {
407    extern_methods!(
408        #[unsafe(method(init))]
409        #[unsafe(method_family = init)]
410        pub fn init(this: Allocated<Self>) -> Retained<Self>;
411    );
412}
413
414/// Methods declared on superclass `NSObject`.
415#[cfg(all(
416    feature = "UIControl",
417    feature = "UIResponder",
418    feature = "UITextField",
419    feature = "UIView"
420))]
421impl UISearchTextField {
422    extern_methods!(
423        #[unsafe(method(new))]
424        #[unsafe(method_family = new)]
425        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
426    );
427}
428
429extern_class!(
430    /// An individual token in a UISearchTextField.
431    ///
432    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtoken?language=objc)
433    #[unsafe(super(NSObject))]
434    #[thread_kind = MainThreadOnly]
435    #[derive(Debug, PartialEq, Eq, Hash)]
436    pub struct UISearchToken;
437);
438
439extern_conformance!(
440    unsafe impl NSObjectProtocol for UISearchToken {}
441);
442
443impl UISearchToken {
444    extern_methods!(
445        #[unsafe(method(init))]
446        #[unsafe(method_family = init)]
447        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
448
449        #[unsafe(method(new))]
450        #[unsafe(method_family = new)]
451        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
452
453        #[cfg(feature = "UIImage")]
454        #[unsafe(method(tokenWithIcon:text:))]
455        #[unsafe(method_family = none)]
456        pub fn tokenWithIcon_text(
457            icon: Option<&UIImage>,
458            text: &NSString,
459            mtm: MainThreadMarker,
460        ) -> Retained<UISearchToken>;
461
462        /// The object which this token represents.
463        ///
464        /// The application can assign any object it wants to this property. UISearchTextField does not attempt to interpret this object.
465        ///
466        ///
467        /// 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.
468        #[unsafe(method(representedObject))]
469        #[unsafe(method_family = none)]
470        pub fn representedObject(&self) -> Option<Retained<AnyObject>>;
471
472        /// Setter for [`representedObject`][Self::representedObject].
473        ///
474        /// # Safety
475        ///
476        /// `represented_object` should be of the correct type.
477        #[unsafe(method(setRepresentedObject:))]
478        #[unsafe(method_family = none)]
479        pub unsafe fn setRepresentedObject(&self, represented_object: Option<&AnyObject>);
480    );
481}
482
483extern_protocol!(
484    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfielddelegate?language=objc)
485    #[cfg(feature = "UITextField")]
486    pub unsafe trait UISearchTextFieldDelegate:
487        UITextFieldDelegate + MainThreadOnly
488    {
489        #[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
490        /// Implements cut and copy of tokens.
491        ///
492        /// 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.
493        ///
494        /// This method will only be called if either of the field’s allowsCopyingTokens or allowsDeletingTokens properties is true.
495        #[optional]
496        #[unsafe(method(searchTextField:itemProviderForCopyingToken:))]
497        #[unsafe(method_family = none)]
498        fn searchTextField_itemProviderForCopyingToken(
499            &self,
500            search_text_field: &UISearchTextField,
501            token: &UISearchToken,
502        ) -> Retained<NSItemProvider>;
503
504        #[cfg(all(
505            feature = "UIControl",
506            feature = "UIResponder",
507            feature = "UISearchSuggestion",
508            feature = "UIView"
509        ))]
510        /// searchSuggestions property will be set to nil after sending this message
511        #[optional]
512        #[unsafe(method(searchTextField:didSelectSuggestion:))]
513        #[unsafe(method_family = none)]
514        fn searchTextField_didSelectSuggestion(
515            &self,
516            search_text_field: &UISearchTextField,
517            suggestion: &ProtocolObject<dyn UISearchSuggestion>,
518        );
519    }
520);
521
522extern_protocol!(
523    /// A protocol that refines UITextPasteItem to support pasting of tokens.
524    ///
525    /// Paste items vended by UISearchTextField conform to this protocol.
526    ///
527    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfieldpasteitem?language=objc)
528    #[cfg(feature = "UITextPasteDelegate")]
529    pub unsafe trait UISearchTextFieldPasteItem: UITextPasteItem + MainThreadOnly {
530        /// Transforms this paste item into a token at the end of the search text field’s token array.
531        #[unsafe(method(setSearchTokenResult:))]
532        #[unsafe(method_family = none)]
533        fn setSearchTokenResult(&self, token: &UISearchToken);
534    }
535);