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 unsafe fn tokens(&self) -> Retained<NSArray<UISearchToken>>;
236
237        /// Setter for [`tokens`][Self::tokens].
238        #[unsafe(method(setTokens:))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn setTokens(&self, tokens: &NSArray<UISearchToken>);
241
242        #[unsafe(method(insertToken:atIndex:))]
243        #[unsafe(method_family = none)]
244        pub unsafe fn insertToken_atIndex(&self, token: &UISearchToken, token_index: NSInteger);
245
246        #[unsafe(method(removeTokenAtIndex:))]
247        #[unsafe(method_family = none)]
248        pub unsafe fn removeTokenAtIndex(&self, token_index: NSInteger);
249
250        #[cfg(feature = "UITextInput")]
251        /// Returns the position of the provided token. To select a token, assign a UITextRange containing its position to the selectedTextRange property.
252        #[unsafe(method(positionOfTokenAtIndex:))]
253        #[unsafe(method_family = none)]
254        pub unsafe fn positionOfTokenAtIndex(
255            &self,
256            token_index: NSInteger,
257        ) -> Retained<UITextPosition>;
258
259        #[cfg(feature = "UITextInput")]
260        /// Returns the tokens which are contained within the provided range.
261        ///
262        /// 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.
263        #[unsafe(method(tokensInRange:))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn tokensInRange(
266            &self,
267            text_range: &UITextRange,
268        ) -> Retained<NSArray<UISearchToken>>;
269
270        #[cfg(feature = "UITextInput")]
271        /// The range that corresponds to the field’s text, exclusive of any tokens.
272        ///
273        ///
274        /// See: -[
275        /// <UITextInput
276        /// > positionWithinRange:atCharacterOffset:]
277        #[unsafe(method(textualRange))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn textualRange(&self) -> Retained<UITextRange>;
280
281        #[cfg(feature = "UITextInput")]
282        /// 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.
283        ///
284        /// This method is essentially a convenience wrapper around the more fundamental `text`, `tokens`, and `selectedTextRange` properties, providing the selection behavior the user will expect.
285        ///
286        ///
287        /// 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.
288        #[unsafe(method(replaceTextualPortionOfRange:withToken:atIndex:))]
289        #[unsafe(method_family = none)]
290        pub unsafe fn replaceTextualPortionOfRange_withToken_atIndex(
291            &self,
292            text_range: &UITextRange,
293            token: &UISearchToken,
294            token_index: NSUInteger,
295        );
296
297        #[cfg(feature = "UIColor")]
298        /// Set this to nil for tokens to use their default color.
299        #[unsafe(method(tokenBackgroundColor))]
300        #[unsafe(method_family = none)]
301        pub unsafe fn tokenBackgroundColor(&self) -> Option<Retained<UIColor>>;
302
303        #[cfg(feature = "UIColor")]
304        /// Setter for [`tokenBackgroundColor`][Self::tokenBackgroundColor].
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 unsafe fn allowsDeletingTokens(&self) -> bool;
315
316        /// Setter for [`allowsDeletingTokens`][Self::allowsDeletingTokens].
317        #[unsafe(method(setAllowsDeletingTokens:))]
318        #[unsafe(method_family = none)]
319        pub unsafe 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 unsafe fn allowsCopyingTokens(&self) -> bool;
327
328        /// Setter for [`allowsCopyingTokens`][Self::allowsCopyingTokens].
329        #[unsafe(method(setAllowsCopyingTokens:))]
330        #[unsafe(method_family = none)]
331        pub unsafe 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 unsafe fn searchSuggestions(
343            &self,
344        ) -> Option<Retained<NSArray<ProtocolObject<dyn UISearchSuggestion>>>>;
345
346        #[cfg(feature = "UISearchSuggestion")]
347        /// Setter for [`searchSuggestions`][Self::searchSuggestions].
348        #[unsafe(method(setSearchSuggestions:))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn setSearchSuggestions(
351            &self,
352            search_suggestions: Option<&NSArray<ProtocolObject<dyn UISearchSuggestion>>>,
353        );
354    );
355}
356
357/// Methods declared on superclass `UIControl`.
358#[cfg(all(
359    feature = "UIControl",
360    feature = "UIResponder",
361    feature = "UITextField",
362    feature = "UIView"
363))]
364impl UISearchTextField {
365    extern_methods!(
366        #[cfg(feature = "objc2-core-foundation")]
367        #[unsafe(method(initWithFrame:))]
368        #[unsafe(method_family = init)]
369        pub unsafe fn initWithFrame(this: Allocated<Self>, frame: CGRect) -> Retained<Self>;
370
371        #[unsafe(method(initWithCoder:))]
372        #[unsafe(method_family = init)]
373        pub unsafe fn initWithCoder(
374            this: Allocated<Self>,
375            coder: &NSCoder,
376        ) -> Option<Retained<Self>>;
377
378        #[cfg(all(
379            feature = "UIAction",
380            feature = "UIMenuElement",
381            feature = "objc2-core-foundation"
382        ))]
383        /// 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.
384        #[unsafe(method(initWithFrame:primaryAction:))]
385        #[unsafe(method_family = init)]
386        pub unsafe fn initWithFrame_primaryAction(
387            this: Allocated<Self>,
388            frame: CGRect,
389            primary_action: Option<&UIAction>,
390        ) -> Retained<Self>;
391    );
392}
393
394/// Methods declared on superclass `NSObject`.
395#[cfg(all(
396    feature = "UIControl",
397    feature = "UIResponder",
398    feature = "UITextField",
399    feature = "UIView"
400))]
401impl UISearchTextField {
402    extern_methods!(
403        #[unsafe(method(init))]
404        #[unsafe(method_family = init)]
405        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
406
407        #[unsafe(method(new))]
408        #[unsafe(method_family = new)]
409        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
410    );
411}
412
413extern_class!(
414    /// An individual token in a UISearchTextField.
415    ///
416    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtoken?language=objc)
417    #[unsafe(super(NSObject))]
418    #[thread_kind = MainThreadOnly]
419    #[derive(Debug, PartialEq, Eq, Hash)]
420    pub struct UISearchToken;
421);
422
423extern_conformance!(
424    unsafe impl NSObjectProtocol for UISearchToken {}
425);
426
427impl UISearchToken {
428    extern_methods!(
429        #[unsafe(method(init))]
430        #[unsafe(method_family = init)]
431        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
432
433        #[unsafe(method(new))]
434        #[unsafe(method_family = new)]
435        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
436
437        #[cfg(feature = "UIImage")]
438        #[unsafe(method(tokenWithIcon:text:))]
439        #[unsafe(method_family = none)]
440        pub unsafe fn tokenWithIcon_text(
441            icon: Option<&UIImage>,
442            text: &NSString,
443            mtm: MainThreadMarker,
444        ) -> Retained<UISearchToken>;
445
446        /// The object which this token represents.
447        ///
448        /// The application can assign any object it wants to this property. UISearchTextField does not attempt to interpret this object.
449        ///
450        ///
451        /// 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.
452        #[unsafe(method(representedObject))]
453        #[unsafe(method_family = none)]
454        pub unsafe fn representedObject(&self) -> Option<Retained<AnyObject>>;
455
456        /// Setter for [`representedObject`][Self::representedObject].
457        #[unsafe(method(setRepresentedObject:))]
458        #[unsafe(method_family = none)]
459        pub unsafe fn setRepresentedObject(&self, represented_object: Option<&AnyObject>);
460    );
461}
462
463extern_protocol!(
464    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfielddelegate?language=objc)
465    #[cfg(feature = "UITextField")]
466    pub unsafe trait UISearchTextFieldDelegate:
467        UITextFieldDelegate + MainThreadOnly
468    {
469        #[cfg(all(feature = "UIControl", feature = "UIResponder", feature = "UIView"))]
470        /// Implements cut and copy of tokens.
471        ///
472        /// 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.
473        ///
474        /// This method will only be called if either of the field’s allowsCopyingTokens or allowsDeletingTokens properties is true.
475        #[optional]
476        #[unsafe(method(searchTextField:itemProviderForCopyingToken:))]
477        #[unsafe(method_family = none)]
478        unsafe fn searchTextField_itemProviderForCopyingToken(
479            &self,
480            search_text_field: &UISearchTextField,
481            token: &UISearchToken,
482        ) -> Retained<NSItemProvider>;
483
484        #[cfg(all(
485            feature = "UIControl",
486            feature = "UIResponder",
487            feature = "UISearchSuggestion",
488            feature = "UIView"
489        ))]
490        /// searchSuggestions property will be set to nil after sending this message
491        #[optional]
492        #[unsafe(method(searchTextField:didSelectSuggestion:))]
493        #[unsafe(method_family = none)]
494        unsafe fn searchTextField_didSelectSuggestion(
495            &self,
496            search_text_field: &UISearchTextField,
497            suggestion: &ProtocolObject<dyn UISearchSuggestion>,
498        );
499    }
500);
501
502extern_protocol!(
503    /// A protocol that refines UITextPasteItem to support pasting of tokens.
504    ///
505    /// Paste items vended by UISearchTextField conform to this protocol.
506    ///
507    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uisearchtextfieldpasteitem?language=objc)
508    #[cfg(feature = "UITextPasteDelegate")]
509    pub unsafe trait UISearchTextFieldPasteItem: UITextPasteItem + MainThreadOnly {
510        /// Transforms this paste item into a token at the end of the search text field’s token array.
511        #[unsafe(method(setSearchTokenResult:))]
512        #[unsafe(method_family = none)]
513        unsafe fn setSearchTokenResult(&self, token: &UISearchToken);
514    }
515);