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 unsafe fn placeholderString(&self) -> Option<Retained<NSString>>;
136
137 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[unsafe(method(setAllowsWritingToolsAffordance:))]
333 #[unsafe(method_family = none)]
334 pub unsafe fn setAllowsWritingToolsAffordance(&self, allows_writing_tools_affordance: bool);
335 );
336}
337
338#[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#[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#[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#[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 #[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 #[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#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
407impl NSTextField {
408 extern_methods!(
409 #[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 #[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 #[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 #[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#[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 #[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 #[unsafe(method(setImportsGraphics:))]
479 #[unsafe(method_family = none)]
480 pub unsafe fn setImportsGraphics(&self, imports_graphics: bool);
481 );
482}
483
484extern_protocol!(
485 #[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 #[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 #[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 #[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#[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}