objc2_app_kit/generated/
NSTextField.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
10use crate::*;
11
12extern_class!(
13    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfield?language=objc)
14    #[unsafe(super(NSControl, NSView, NSResponder, NSObject))]
15    #[derive(Debug, PartialEq, Eq, Hash)]
16    #[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
17    pub struct NSTextField;
18);
19
20#[cfg(all(
21    feature = "NSAccessibilityProtocols",
22    feature = "NSControl",
23    feature = "NSResponder",
24    feature = "NSView"
25))]
26extern_conformance!(
27    unsafe impl NSAccessibility for NSTextField {}
28);
29
30#[cfg(all(
31    feature = "NSAccessibilityProtocols",
32    feature = "NSControl",
33    feature = "NSResponder",
34    feature = "NSView"
35))]
36extern_conformance!(
37    unsafe impl NSAccessibilityElementProtocol for NSTextField {}
38);
39
40#[cfg(all(
41    feature = "NSAccessibilityProtocols",
42    feature = "NSControl",
43    feature = "NSResponder",
44    feature = "NSView"
45))]
46extern_conformance!(
47    unsafe impl NSAccessibilityNavigableStaticText for NSTextField {}
48);
49
50#[cfg(all(
51    feature = "NSAccessibilityProtocols",
52    feature = "NSControl",
53    feature = "NSResponder",
54    feature = "NSView"
55))]
56extern_conformance!(
57    unsafe impl NSAccessibilityStaticText for NSTextField {}
58);
59
60#[cfg(all(
61    feature = "NSAnimation",
62    feature = "NSControl",
63    feature = "NSResponder",
64    feature = "NSView"
65))]
66extern_conformance!(
67    unsafe impl NSAnimatablePropertyContainer for NSTextField {}
68);
69
70#[cfg(all(
71    feature = "NSAppearance",
72    feature = "NSControl",
73    feature = "NSResponder",
74    feature = "NSView"
75))]
76extern_conformance!(
77    unsafe impl NSAppearanceCustomization for NSTextField {}
78);
79
80#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
81extern_conformance!(
82    unsafe impl NSCoding for NSTextField {}
83);
84
85#[cfg(all(
86    feature = "NSControl",
87    feature = "NSDragging",
88    feature = "NSResponder",
89    feature = "NSView"
90))]
91extern_conformance!(
92    unsafe impl NSDraggingDestination for NSTextField {}
93);
94
95#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
96extern_conformance!(
97    unsafe impl NSObjectProtocol for NSTextField {}
98);
99
100#[cfg(all(
101    feature = "NSControl",
102    feature = "NSResponder",
103    feature = "NSTextContent",
104    feature = "NSView"
105))]
106extern_conformance!(
107    unsafe impl NSTextContent for NSTextField {}
108);
109
110#[cfg(all(
111    feature = "NSControl",
112    feature = "NSResponder",
113    feature = "NSUserInterfaceItemIdentification",
114    feature = "NSView"
115))]
116extern_conformance!(
117    unsafe impl NSUserInterfaceItemIdentification for NSTextField {}
118);
119
120#[cfg(all(
121    feature = "NSControl",
122    feature = "NSResponder",
123    feature = "NSUserInterfaceValidation",
124    feature = "NSView"
125))]
126extern_conformance!(
127    unsafe impl NSUserInterfaceValidations for NSTextField {}
128);
129
130#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
131impl NSTextField {
132    extern_methods!(
133        #[unsafe(method(placeholderString))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn placeholderString(&self) -> Option<Retained<NSString>>;
136
137        /// Setter for [`placeholderString`][Self::placeholderString].
138        #[unsafe(method(setPlaceholderString:))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn setPlaceholderString(&self, placeholder_string: Option<&NSString>);
141
142        #[unsafe(method(placeholderAttributedString))]
143        #[unsafe(method_family = none)]
144        pub unsafe fn placeholderAttributedString(&self) -> Option<Retained<NSAttributedString>>;
145
146        /// Setter for [`placeholderAttributedString`][Self::placeholderAttributedString].
147        #[unsafe(method(setPlaceholderAttributedString:))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn setPlaceholderAttributedString(
150            &self,
151            placeholder_attributed_string: Option<&NSAttributedString>,
152        );
153
154        #[cfg(feature = "NSColor")]
155        #[unsafe(method(backgroundColor))]
156        #[unsafe(method_family = none)]
157        pub unsafe fn backgroundColor(&self) -> Option<Retained<NSColor>>;
158
159        #[cfg(feature = "NSColor")]
160        /// Setter for [`backgroundColor`][Self::backgroundColor].
161        #[unsafe(method(setBackgroundColor:))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn setBackgroundColor(&self, background_color: Option<&NSColor>);
164
165        #[unsafe(method(drawsBackground))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn drawsBackground(&self) -> bool;
168
169        /// Setter for [`drawsBackground`][Self::drawsBackground].
170        #[unsafe(method(setDrawsBackground:))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn setDrawsBackground(&self, draws_background: bool);
173
174        #[cfg(feature = "NSColor")]
175        #[unsafe(method(textColor))]
176        #[unsafe(method_family = none)]
177        pub unsafe fn textColor(&self) -> Option<Retained<NSColor>>;
178
179        #[cfg(feature = "NSColor")]
180        /// Setter for [`textColor`][Self::textColor].
181        #[unsafe(method(setTextColor:))]
182        #[unsafe(method_family = none)]
183        pub unsafe fn setTextColor(&self, text_color: Option<&NSColor>);
184
185        #[unsafe(method(isBordered))]
186        #[unsafe(method_family = none)]
187        pub unsafe fn isBordered(&self) -> bool;
188
189        /// Setter for [`isBordered`][Self::isBordered].
190        #[unsafe(method(setBordered:))]
191        #[unsafe(method_family = none)]
192        pub unsafe fn setBordered(&self, bordered: bool);
193
194        #[unsafe(method(isBezeled))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn isBezeled(&self) -> bool;
197
198        /// Setter for [`isBezeled`][Self::isBezeled].
199        #[unsafe(method(setBezeled:))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn setBezeled(&self, bezeled: bool);
202
203        #[unsafe(method(isEditable))]
204        #[unsafe(method_family = none)]
205        pub unsafe fn isEditable(&self) -> bool;
206
207        /// Setter for [`isEditable`][Self::isEditable].
208        #[unsafe(method(setEditable:))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn setEditable(&self, editable: bool);
211
212        #[unsafe(method(isSelectable))]
213        #[unsafe(method_family = none)]
214        pub unsafe fn isSelectable(&self) -> bool;
215
216        /// Setter for [`isSelectable`][Self::isSelectable].
217        #[unsafe(method(setSelectable:))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn setSelectable(&self, selectable: bool);
220
221        #[unsafe(method(selectText:))]
222        #[unsafe(method_family = none)]
223        pub unsafe fn selectText(&self, sender: Option<&AnyObject>);
224
225        #[unsafe(method(delegate))]
226        #[unsafe(method_family = none)]
227        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSTextFieldDelegate>>>;
228
229        /// This is a [weak property][objc2::topics::weak_property].
230        /// Setter for [`delegate`][Self::delegate].
231        #[unsafe(method(setDelegate:))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn setDelegate(
234            &self,
235            delegate: Option<&ProtocolObject<dyn NSTextFieldDelegate>>,
236        );
237
238        #[cfg(feature = "NSText")]
239        #[unsafe(method(textShouldBeginEditing:))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn textShouldBeginEditing(&self, text_object: &NSText) -> bool;
242
243        #[cfg(feature = "NSText")]
244        #[unsafe(method(textShouldEndEditing:))]
245        #[unsafe(method_family = none)]
246        pub unsafe fn textShouldEndEditing(&self, text_object: &NSText) -> bool;
247
248        #[unsafe(method(textDidBeginEditing:))]
249        #[unsafe(method_family = none)]
250        pub unsafe fn textDidBeginEditing(&self, notification: &NSNotification);
251
252        #[unsafe(method(textDidEndEditing:))]
253        #[unsafe(method_family = none)]
254        pub unsafe fn textDidEndEditing(&self, notification: &NSNotification);
255
256        #[unsafe(method(textDidChange:))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn textDidChange(&self, notification: &NSNotification);
259
260        #[unsafe(method(acceptsFirstResponder))]
261        #[unsafe(method_family = none)]
262        pub unsafe fn acceptsFirstResponder(&self) -> bool;
263
264        #[cfg(feature = "NSTextFieldCell")]
265        #[unsafe(method(bezelStyle))]
266        #[unsafe(method_family = none)]
267        pub unsafe fn bezelStyle(&self) -> NSTextFieldBezelStyle;
268
269        #[cfg(feature = "NSTextFieldCell")]
270        /// Setter for [`bezelStyle`][Self::bezelStyle].
271        #[unsafe(method(setBezelStyle:))]
272        #[unsafe(method_family = none)]
273        pub unsafe fn setBezelStyle(&self, bezel_style: NSTextFieldBezelStyle);
274
275        #[cfg(feature = "objc2-core-foundation")]
276        #[unsafe(method(preferredMaxLayoutWidth))]
277        #[unsafe(method_family = none)]
278        pub unsafe fn preferredMaxLayoutWidth(&self) -> CGFloat;
279
280        #[cfg(feature = "objc2-core-foundation")]
281        /// Setter for [`preferredMaxLayoutWidth`][Self::preferredMaxLayoutWidth].
282        #[unsafe(method(setPreferredMaxLayoutWidth:))]
283        #[unsafe(method_family = none)]
284        pub unsafe fn setPreferredMaxLayoutWidth(&self, preferred_max_layout_width: CGFloat);
285
286        #[unsafe(method(maximumNumberOfLines))]
287        #[unsafe(method_family = none)]
288        pub unsafe fn maximumNumberOfLines(&self) -> NSInteger;
289
290        /// Setter for [`maximumNumberOfLines`][Self::maximumNumberOfLines].
291        #[unsafe(method(setMaximumNumberOfLines:))]
292        #[unsafe(method_family = none)]
293        pub unsafe fn setMaximumNumberOfLines(&self, maximum_number_of_lines: NSInteger);
294
295        #[unsafe(method(allowsDefaultTighteningForTruncation))]
296        #[unsafe(method_family = none)]
297        pub unsafe fn allowsDefaultTighteningForTruncation(&self) -> bool;
298
299        /// Setter for [`allowsDefaultTighteningForTruncation`][Self::allowsDefaultTighteningForTruncation].
300        #[unsafe(method(setAllowsDefaultTighteningForTruncation:))]
301        #[unsafe(method_family = none)]
302        pub unsafe fn setAllowsDefaultTighteningForTruncation(
303            &self,
304            allows_default_tightening_for_truncation: bool,
305        );
306
307        #[cfg(feature = "NSParagraphStyle")]
308        #[unsafe(method(lineBreakStrategy))]
309        #[unsafe(method_family = none)]
310        pub unsafe fn lineBreakStrategy(&self) -> NSLineBreakStrategy;
311
312        #[cfg(feature = "NSParagraphStyle")]
313        /// Setter for [`lineBreakStrategy`][Self::lineBreakStrategy].
314        #[unsafe(method(setLineBreakStrategy:))]
315        #[unsafe(method_family = none)]
316        pub unsafe fn setLineBreakStrategy(&self, line_break_strategy: NSLineBreakStrategy);
317
318        #[unsafe(method(allowsWritingTools))]
319        #[unsafe(method_family = none)]
320        pub unsafe fn allowsWritingTools(&self) -> bool;
321
322        /// Setter for [`allowsWritingTools`][Self::allowsWritingTools].
323        #[unsafe(method(setAllowsWritingTools:))]
324        #[unsafe(method_family = none)]
325        pub unsafe fn setAllowsWritingTools(&self, allows_writing_tools: bool);
326
327        #[unsafe(method(allowsWritingToolsAffordance))]
328        #[unsafe(method_family = none)]
329        pub unsafe fn allowsWritingToolsAffordance(&self) -> bool;
330
331        /// Setter for [`allowsWritingToolsAffordance`][Self::allowsWritingToolsAffordance].
332        #[unsafe(method(setAllowsWritingToolsAffordance:))]
333        #[unsafe(method_family = none)]
334        pub unsafe fn setAllowsWritingToolsAffordance(&self, allows_writing_tools_affordance: bool);
335    );
336}
337
338/// Methods declared on superclass `NSControl`.
339#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
340impl NSTextField {
341    extern_methods!(
342        #[unsafe(method(initWithFrame:))]
343        #[unsafe(method_family = init)]
344        pub unsafe fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
345
346        #[unsafe(method(initWithCoder:))]
347        #[unsafe(method_family = init)]
348        pub unsafe fn initWithCoder(
349            this: Allocated<Self>,
350            coder: &NSCoder,
351        ) -> Option<Retained<Self>>;
352    );
353}
354
355/// Methods declared on superclass `NSResponder`.
356#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
357impl NSTextField {
358    extern_methods!(
359        #[unsafe(method(init))]
360        #[unsafe(method_family = init)]
361        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
362    );
363}
364
365/// Methods declared on superclass `NSObject`.
366#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
367impl NSTextField {
368    extern_methods!(
369        #[unsafe(method(new))]
370        #[unsafe(method_family = new)]
371        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
372    );
373}
374
375/// NSTouchBar.
376#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
377impl NSTextField {
378    extern_methods!(
379        #[unsafe(method(isAutomaticTextCompletionEnabled))]
380        #[unsafe(method_family = none)]
381        pub unsafe fn isAutomaticTextCompletionEnabled(&self) -> bool;
382
383        /// Setter for [`isAutomaticTextCompletionEnabled`][Self::isAutomaticTextCompletionEnabled].
384        #[unsafe(method(setAutomaticTextCompletionEnabled:))]
385        #[unsafe(method_family = none)]
386        pub unsafe fn setAutomaticTextCompletionEnabled(
387            &self,
388            automatic_text_completion_enabled: bool,
389        );
390
391        #[unsafe(method(allowsCharacterPickerTouchBarItem))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn allowsCharacterPickerTouchBarItem(&self) -> bool;
394
395        /// Setter for [`allowsCharacterPickerTouchBarItem`][Self::allowsCharacterPickerTouchBarItem].
396        #[unsafe(method(setAllowsCharacterPickerTouchBarItem:))]
397        #[unsafe(method_family = none)]
398        pub unsafe fn setAllowsCharacterPickerTouchBarItem(
399            &self,
400            allows_character_picker_touch_bar_item: bool,
401        );
402    );
403}
404
405/// NSTextFieldConvenience.
406#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
407impl NSTextField {
408    extern_methods!(
409        /// Creates a non-wrapping, non-editable, non-selectable text field that displays text in the default system font.
410        ///
411        /// Parameter `stringValue`: The title text to display in the field.
412        ///
413        /// Returns: An initialized text field object.
414        #[unsafe(method(labelWithString:))]
415        #[unsafe(method_family = none)]
416        pub unsafe fn labelWithString(
417            string_value: &NSString,
418            mtm: MainThreadMarker,
419        ) -> Retained<Self>;
420
421        /// Creates a wrapping, non-editable, selectable text field that displays text in the default system font.
422        ///
423        /// Parameter `stringValue`: The title text to display in the field.
424        ///
425        /// Returns: An initialized text field object.
426        #[unsafe(method(wrappingLabelWithString:))]
427        #[unsafe(method_family = none)]
428        pub unsafe fn wrappingLabelWithString(
429            string_value: &NSString,
430            mtm: MainThreadMarker,
431        ) -> Retained<Self>;
432
433        /// Creates a non-editable, non-selectable text field that displays attributed text.
434        /// The line break mode of this field is determined by the attributed string's NSParagraphStyle attribute.
435        ///
436        /// Parameter `attributedStringValue`: The attributed string to display in the field.
437        ///
438        /// Returns: An initialized text field object.
439        #[unsafe(method(labelWithAttributedString:))]
440        #[unsafe(method_family = none)]
441        pub unsafe fn labelWithAttributedString(
442            attributed_string_value: &NSAttributedString,
443            mtm: MainThreadMarker,
444        ) -> Retained<Self>;
445
446        /// Creates a non-wrapping editable text field.
447        ///
448        /// Parameter `stringValue`: The initial contents of the text field, or empty string for an initially empty text field.
449        ///
450        /// Returns: An initialized text field object.
451        #[unsafe(method(textFieldWithString:))]
452        #[unsafe(method_family = none)]
453        pub unsafe fn textFieldWithString(
454            string_value: &NSString,
455            mtm: MainThreadMarker,
456        ) -> Retained<Self>;
457    );
458}
459
460/// NSTextFieldAttributedStringMethods.
461#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
462impl NSTextField {
463    extern_methods!(
464        #[unsafe(method(allowsEditingTextAttributes))]
465        #[unsafe(method_family = none)]
466        pub unsafe fn allowsEditingTextAttributes(&self) -> bool;
467
468        /// Setter for [`allowsEditingTextAttributes`][Self::allowsEditingTextAttributes].
469        #[unsafe(method(setAllowsEditingTextAttributes:))]
470        #[unsafe(method_family = none)]
471        pub unsafe fn setAllowsEditingTextAttributes(&self, allows_editing_text_attributes: bool);
472
473        #[unsafe(method(importsGraphics))]
474        #[unsafe(method_family = none)]
475        pub unsafe fn importsGraphics(&self) -> bool;
476
477        /// Setter for [`importsGraphics`][Self::importsGraphics].
478        #[unsafe(method(setImportsGraphics:))]
479        #[unsafe(method_family = none)]
480        pub unsafe fn setImportsGraphics(&self, imports_graphics: bool);
481    );
482}
483
484extern_protocol!(
485    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextfielddelegate?language=objc)
486    #[cfg(feature = "NSControl")]
487    pub unsafe trait NSTextFieldDelegate:
488        NSControlTextEditingDelegate + MainThreadOnly
489    {
490        #[cfg(all(
491            feature = "NSResponder",
492            feature = "NSText",
493            feature = "NSTextView",
494            feature = "NSView"
495        ))]
496        /// Provides a customized list of candidates to the text view’s `candidateListTouchBarItem`. Invoked from `-updateCandidates`. `NSTextView` uses the candidates returned from this method and suppress its built-in candidate generation. Returning `nil` from this delegate method allows `NSTextView` to query candidates from `NSSpellChecker`.
497        /// - Returns: An array of objects that represent the elements of a selection.
498        #[optional]
499        #[unsafe(method(textField:textView:candidatesForSelectedRange:))]
500        #[unsafe(method_family = none)]
501        unsafe fn textField_textView_candidatesForSelectedRange(
502            &self,
503            text_field: &NSTextField,
504            text_view: &NSTextView,
505            selected_range: NSRange,
506        ) -> Option<Retained<NSArray>>;
507
508        #[cfg(all(
509            feature = "NSResponder",
510            feature = "NSText",
511            feature = "NSTextView",
512            feature = "NSView"
513        ))]
514        /// Allows customizing the candidate list queried from `NSSpellChecker`.
515        /// - Returns: An array of text objects to include in a text selection.
516        #[optional]
517        #[unsafe(method(textField:textView:candidates:forSelectedRange:))]
518        #[unsafe(method_family = none)]
519        unsafe fn textField_textView_candidates_forSelectedRange(
520            &self,
521            text_field: &NSTextField,
522            text_view: &NSTextView,
523            candidates: &NSArray<NSTextCheckingResult>,
524            selected_range: NSRange,
525        ) -> Retained<NSArray<NSTextCheckingResult>>;
526
527        #[cfg(all(
528            feature = "NSResponder",
529            feature = "NSText",
530            feature = "NSTextView",
531            feature = "NSView"
532        ))]
533        /// Notifies the delegate that the user selected the candidate at index in `-[NSCandidateListTouchBarItem candidates]` for the text view’s `candidateListTouchBarItem`. Returns a Boolean value that indicates whether to select the text object at the index.
534        /// - Parameters:
535        /// - textField: The text field that sent the message.
536        /// - textView: The text view that sent the message.
537        /// - index: The index that represents the start of the candidate text to evaluate, or `NSNotFound` if no candidate is to be selected.
538        /// - Returns: `YES` if the framework selects the text. `YES` allows `textView` to insert the candidate into the text storage if it’s `NSString`, `NSAttributedString`, or `NSTextCheckingResult`.
539        #[optional]
540        #[unsafe(method(textField:textView:shouldSelectCandidateAtIndex:))]
541        #[unsafe(method_family = none)]
542        unsafe fn textField_textView_shouldSelectCandidateAtIndex(
543            &self,
544            text_field: &NSTextField,
545            text_view: &NSTextView,
546            index: NSUInteger,
547        ) -> bool;
548    }
549);
550
551/// NSDeprecated.
552#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
553impl NSTextField {
554    extern_methods!(
555        #[deprecated = "Use `-setTitle:` instead"]
556        #[unsafe(method(setTitleWithMnemonic:))]
557        #[unsafe(method_family = none)]
558        pub unsafe fn setTitleWithMnemonic(&self, string_with_ampersand: Option<&NSString>);
559    );
560}