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