1use 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 #[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 fn placeholderString(&self) -> Option<Retained<NSString>>;
136
137 #[unsafe(method(setPlaceholderString:))]
141 #[unsafe(method_family = none)]
142 pub fn setPlaceholderString(&self, placeholder_string: Option<&NSString>);
143
144 #[unsafe(method(placeholderAttributedString))]
145 #[unsafe(method_family = none)]
146 pub fn placeholderAttributedString(&self) -> Option<Retained<NSAttributedString>>;
147
148 #[unsafe(method(setPlaceholderAttributedString:))]
152 #[unsafe(method_family = none)]
153 pub fn setPlaceholderAttributedString(
154 &self,
155 placeholder_attributed_string: Option<&NSAttributedString>,
156 );
157
158 #[cfg(feature = "NSColor")]
159 #[unsafe(method(backgroundColor))]
160 #[unsafe(method_family = none)]
161 pub fn backgroundColor(&self) -> Option<Retained<NSColor>>;
162
163 #[cfg(feature = "NSColor")]
164 #[unsafe(method(setBackgroundColor:))]
168 #[unsafe(method_family = none)]
169 pub fn setBackgroundColor(&self, background_color: Option<&NSColor>);
170
171 #[unsafe(method(drawsBackground))]
172 #[unsafe(method_family = none)]
173 pub fn drawsBackground(&self) -> bool;
174
175 #[unsafe(method(setDrawsBackground:))]
177 #[unsafe(method_family = none)]
178 pub fn setDrawsBackground(&self, draws_background: bool);
179
180 #[cfg(feature = "NSColor")]
181 #[unsafe(method(textColor))]
182 #[unsafe(method_family = none)]
183 pub fn textColor(&self) -> Option<Retained<NSColor>>;
184
185 #[cfg(feature = "NSColor")]
186 #[unsafe(method(setTextColor:))]
190 #[unsafe(method_family = none)]
191 pub fn setTextColor(&self, text_color: Option<&NSColor>);
192
193 #[unsafe(method(isBordered))]
194 #[unsafe(method_family = none)]
195 pub fn isBordered(&self) -> bool;
196
197 #[unsafe(method(setBordered:))]
199 #[unsafe(method_family = none)]
200 pub fn setBordered(&self, bordered: bool);
201
202 #[unsafe(method(isBezeled))]
203 #[unsafe(method_family = none)]
204 pub fn isBezeled(&self) -> bool;
205
206 #[unsafe(method(setBezeled:))]
208 #[unsafe(method_family = none)]
209 pub fn setBezeled(&self, bezeled: bool);
210
211 #[unsafe(method(isEditable))]
212 #[unsafe(method_family = none)]
213 pub fn isEditable(&self) -> bool;
214
215 #[unsafe(method(setEditable:))]
217 #[unsafe(method_family = none)]
218 pub fn setEditable(&self, editable: bool);
219
220 #[unsafe(method(isSelectable))]
221 #[unsafe(method_family = none)]
222 pub fn isSelectable(&self) -> bool;
223
224 #[unsafe(method(setSelectable:))]
226 #[unsafe(method_family = none)]
227 pub fn setSelectable(&self, selectable: bool);
228
229 #[unsafe(method(selectText:))]
233 #[unsafe(method_family = none)]
234 pub unsafe fn selectText(&self, sender: Option<&AnyObject>);
235
236 #[unsafe(method(delegate))]
237 #[unsafe(method_family = none)]
238 pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSTextFieldDelegate>>>;
239
240 #[unsafe(method(setDelegate:))]
244 #[unsafe(method_family = none)]
245 pub unsafe fn setDelegate(
246 &self,
247 delegate: Option<&ProtocolObject<dyn NSTextFieldDelegate>>,
248 );
249
250 #[cfg(feature = "NSText")]
251 #[unsafe(method(textShouldBeginEditing:))]
252 #[unsafe(method_family = none)]
253 pub fn textShouldBeginEditing(&self, text_object: &NSText) -> bool;
254
255 #[cfg(feature = "NSText")]
256 #[unsafe(method(textShouldEndEditing:))]
257 #[unsafe(method_family = none)]
258 pub fn textShouldEndEditing(&self, text_object: &NSText) -> bool;
259
260 #[unsafe(method(textDidBeginEditing:))]
261 #[unsafe(method_family = none)]
262 pub fn textDidBeginEditing(&self, notification: &NSNotification);
263
264 #[unsafe(method(textDidEndEditing:))]
265 #[unsafe(method_family = none)]
266 pub fn textDidEndEditing(&self, notification: &NSNotification);
267
268 #[unsafe(method(textDidChange:))]
269 #[unsafe(method_family = none)]
270 pub fn textDidChange(&self, notification: &NSNotification);
271
272 #[unsafe(method(acceptsFirstResponder))]
273 #[unsafe(method_family = none)]
274 pub fn acceptsFirstResponder(&self) -> bool;
275
276 #[cfg(feature = "NSTextFieldCell")]
277 #[unsafe(method(bezelStyle))]
278 #[unsafe(method_family = none)]
279 pub fn bezelStyle(&self) -> NSTextFieldBezelStyle;
280
281 #[cfg(feature = "NSTextFieldCell")]
282 #[unsafe(method(setBezelStyle:))]
284 #[unsafe(method_family = none)]
285 pub fn setBezelStyle(&self, bezel_style: NSTextFieldBezelStyle);
286
287 #[cfg(feature = "objc2-core-foundation")]
288 #[unsafe(method(preferredMaxLayoutWidth))]
289 #[unsafe(method_family = none)]
290 pub fn preferredMaxLayoutWidth(&self) -> CGFloat;
291
292 #[cfg(feature = "objc2-core-foundation")]
293 #[unsafe(method(setPreferredMaxLayoutWidth:))]
295 #[unsafe(method_family = none)]
296 pub fn setPreferredMaxLayoutWidth(&self, preferred_max_layout_width: CGFloat);
297
298 #[unsafe(method(maximumNumberOfLines))]
299 #[unsafe(method_family = none)]
300 pub fn maximumNumberOfLines(&self) -> NSInteger;
301
302 #[unsafe(method(setMaximumNumberOfLines:))]
304 #[unsafe(method_family = none)]
305 pub fn setMaximumNumberOfLines(&self, maximum_number_of_lines: NSInteger);
306
307 #[unsafe(method(allowsDefaultTighteningForTruncation))]
308 #[unsafe(method_family = none)]
309 pub fn allowsDefaultTighteningForTruncation(&self) -> bool;
310
311 #[unsafe(method(setAllowsDefaultTighteningForTruncation:))]
313 #[unsafe(method_family = none)]
314 pub fn setAllowsDefaultTighteningForTruncation(
315 &self,
316 allows_default_tightening_for_truncation: bool,
317 );
318
319 #[cfg(feature = "NSParagraphStyle")]
320 #[unsafe(method(lineBreakStrategy))]
321 #[unsafe(method_family = none)]
322 pub fn lineBreakStrategy(&self) -> NSLineBreakStrategy;
323
324 #[cfg(feature = "NSParagraphStyle")]
325 #[unsafe(method(setLineBreakStrategy:))]
327 #[unsafe(method_family = none)]
328 pub fn setLineBreakStrategy(&self, line_break_strategy: NSLineBreakStrategy);
329
330 #[unsafe(method(allowsWritingTools))]
331 #[unsafe(method_family = none)]
332 pub fn allowsWritingTools(&self) -> bool;
333
334 #[unsafe(method(setAllowsWritingTools:))]
336 #[unsafe(method_family = none)]
337 pub fn setAllowsWritingTools(&self, allows_writing_tools: bool);
338
339 #[unsafe(method(allowsWritingToolsAffordance))]
340 #[unsafe(method_family = none)]
341 pub fn allowsWritingToolsAffordance(&self) -> bool;
342
343 #[unsafe(method(setAllowsWritingToolsAffordance:))]
345 #[unsafe(method_family = none)]
346 pub fn setAllowsWritingToolsAffordance(&self, allows_writing_tools_affordance: bool);
347
348 #[unsafe(method(placeholderStrings))]
349 #[unsafe(method_family = none)]
350 pub fn placeholderStrings(&self) -> Retained<NSArray<NSString>>;
351
352 #[unsafe(method(setPlaceholderStrings:))]
356 #[unsafe(method_family = none)]
357 pub fn setPlaceholderStrings(&self, placeholder_strings: &NSArray<NSString>);
358
359 #[unsafe(method(placeholderAttributedStrings))]
360 #[unsafe(method_family = none)]
361 pub fn placeholderAttributedStrings(&self) -> Retained<NSArray<NSAttributedString>>;
362
363 #[unsafe(method(setPlaceholderAttributedStrings:))]
367 #[unsafe(method_family = none)]
368 pub fn setPlaceholderAttributedStrings(
369 &self,
370 placeholder_attributed_strings: &NSArray<NSAttributedString>,
371 );
372
373 #[unsafe(method(resolvesNaturalAlignmentWithBaseWritingDirection))]
378 #[unsafe(method_family = none)]
379 pub fn resolvesNaturalAlignmentWithBaseWritingDirection(&self) -> bool;
380
381 #[unsafe(method(setResolvesNaturalAlignmentWithBaseWritingDirection:))]
383 #[unsafe(method_family = none)]
384 pub fn setResolvesNaturalAlignmentWithBaseWritingDirection(
385 &self,
386 resolves_natural_alignment_with_base_writing_direction: bool,
387 );
388 );
389}
390
391#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
393impl NSTextField {
394 extern_methods!(
395 #[unsafe(method(initWithFrame:))]
396 #[unsafe(method_family = init)]
397 pub fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
398
399 #[unsafe(method(initWithCoder:))]
403 #[unsafe(method_family = init)]
404 pub unsafe fn initWithCoder(
405 this: Allocated<Self>,
406 coder: &NSCoder,
407 ) -> Option<Retained<Self>>;
408 );
409}
410
411#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
413impl NSTextField {
414 extern_methods!(
415 #[unsafe(method(init))]
416 #[unsafe(method_family = init)]
417 pub fn init(this: Allocated<Self>) -> Retained<Self>;
418 );
419}
420
421#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
423impl NSTextField {
424 extern_methods!(
425 #[unsafe(method(new))]
426 #[unsafe(method_family = new)]
427 pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
428 );
429}
430
431#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
433impl NSTextField {
434 extern_methods!(
435 #[unsafe(method(isAutomaticTextCompletionEnabled))]
436 #[unsafe(method_family = none)]
437 pub fn isAutomaticTextCompletionEnabled(&self) -> bool;
438
439 #[unsafe(method(setAutomaticTextCompletionEnabled:))]
441 #[unsafe(method_family = none)]
442 pub fn setAutomaticTextCompletionEnabled(&self, automatic_text_completion_enabled: bool);
443
444 #[unsafe(method(allowsCharacterPickerTouchBarItem))]
445 #[unsafe(method_family = none)]
446 pub fn allowsCharacterPickerTouchBarItem(&self) -> bool;
447
448 #[unsafe(method(setAllowsCharacterPickerTouchBarItem:))]
450 #[unsafe(method_family = none)]
451 pub fn setAllowsCharacterPickerTouchBarItem(
452 &self,
453 allows_character_picker_touch_bar_item: bool,
454 );
455 );
456}
457
458#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
460impl NSTextField {
461 extern_methods!(
462 #[unsafe(method(labelWithString:))]
468 #[unsafe(method_family = none)]
469 pub fn labelWithString(string_value: &NSString, mtm: MainThreadMarker) -> Retained<Self>;
470
471 #[unsafe(method(wrappingLabelWithString:))]
477 #[unsafe(method_family = none)]
478 pub fn wrappingLabelWithString(
479 string_value: &NSString,
480 mtm: MainThreadMarker,
481 ) -> Retained<Self>;
482
483 #[unsafe(method(labelWithAttributedString:))]
490 #[unsafe(method_family = none)]
491 pub fn labelWithAttributedString(
492 attributed_string_value: &NSAttributedString,
493 mtm: MainThreadMarker,
494 ) -> Retained<Self>;
495
496 #[unsafe(method(textFieldWithString:))]
502 #[unsafe(method_family = none)]
503 pub fn textFieldWithString(
504 string_value: &NSString,
505 mtm: MainThreadMarker,
506 ) -> Retained<Self>;
507 );
508}
509
510#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
512impl NSTextField {
513 extern_methods!(
514 #[unsafe(method(allowsEditingTextAttributes))]
515 #[unsafe(method_family = none)]
516 pub fn allowsEditingTextAttributes(&self) -> bool;
517
518 #[unsafe(method(setAllowsEditingTextAttributes:))]
520 #[unsafe(method_family = none)]
521 pub fn setAllowsEditingTextAttributes(&self, allows_editing_text_attributes: bool);
522
523 #[unsafe(method(importsGraphics))]
524 #[unsafe(method_family = none)]
525 pub fn importsGraphics(&self) -> bool;
526
527 #[unsafe(method(setImportsGraphics:))]
529 #[unsafe(method_family = none)]
530 pub fn setImportsGraphics(&self, imports_graphics: bool);
531 );
532}
533
534extern_protocol!(
535 #[cfg(feature = "NSControl")]
537 pub unsafe trait NSTextFieldDelegate:
538 NSControlTextEditingDelegate + MainThreadOnly
539 {
540 #[cfg(all(
541 feature = "NSResponder",
542 feature = "NSText",
543 feature = "NSTextView",
544 feature = "NSView"
545 ))]
546 #[optional]
549 #[unsafe(method(textField:textView:candidatesForSelectedRange:))]
550 #[unsafe(method_family = none)]
551 fn textField_textView_candidatesForSelectedRange(
552 &self,
553 text_field: &NSTextField,
554 text_view: &NSTextView,
555 selected_range: NSRange,
556 ) -> Option<Retained<NSArray>>;
557
558 #[cfg(all(
559 feature = "NSResponder",
560 feature = "NSText",
561 feature = "NSTextView",
562 feature = "NSView"
563 ))]
564 #[optional]
567 #[unsafe(method(textField:textView:candidates:forSelectedRange:))]
568 #[unsafe(method_family = none)]
569 fn textField_textView_candidates_forSelectedRange(
570 &self,
571 text_field: &NSTextField,
572 text_view: &NSTextView,
573 candidates: &NSArray<NSTextCheckingResult>,
574 selected_range: NSRange,
575 ) -> Retained<NSArray<NSTextCheckingResult>>;
576
577 #[cfg(all(
578 feature = "NSResponder",
579 feature = "NSText",
580 feature = "NSTextView",
581 feature = "NSView"
582 ))]
583 #[optional]
590 #[unsafe(method(textField:textView:shouldSelectCandidateAtIndex:))]
591 #[unsafe(method_family = none)]
592 fn textField_textView_shouldSelectCandidateAtIndex(
593 &self,
594 text_field: &NSTextField,
595 text_view: &NSTextView,
596 index: NSUInteger,
597 ) -> bool;
598 }
599);
600
601#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
603impl NSTextField {
604 extern_methods!(
605 #[deprecated = "Use `-setTitle:` instead"]
609 #[unsafe(method(setTitleWithMnemonic:))]
610 #[unsafe(method_family = none)]
611 pub unsafe fn setTitleWithMnemonic(&self, string_with_ampersand: Option<&NSString>);
612 );
613}