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))]
26unsafe impl NSAccessibility for NSTextField {}
27
28#[cfg(all(
29 feature = "NSAccessibilityProtocols",
30 feature = "NSControl",
31 feature = "NSResponder",
32 feature = "NSView"
33))]
34unsafe impl NSAccessibilityElementProtocol for NSTextField {}
35
36#[cfg(all(
37 feature = "NSAccessibilityProtocols",
38 feature = "NSControl",
39 feature = "NSResponder",
40 feature = "NSView"
41))]
42unsafe impl NSAccessibilityNavigableStaticText for NSTextField {}
43
44#[cfg(all(
45 feature = "NSAccessibilityProtocols",
46 feature = "NSControl",
47 feature = "NSResponder",
48 feature = "NSView"
49))]
50unsafe impl NSAccessibilityStaticText for NSTextField {}
51
52#[cfg(all(
53 feature = "NSAnimation",
54 feature = "NSControl",
55 feature = "NSResponder",
56 feature = "NSView"
57))]
58unsafe impl NSAnimatablePropertyContainer for NSTextField {}
59
60#[cfg(all(
61 feature = "NSAppearance",
62 feature = "NSControl",
63 feature = "NSResponder",
64 feature = "NSView"
65))]
66unsafe impl NSAppearanceCustomization for NSTextField {}
67
68#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
69unsafe impl NSCoding for NSTextField {}
70
71#[cfg(all(
72 feature = "NSControl",
73 feature = "NSDragging",
74 feature = "NSResponder",
75 feature = "NSView"
76))]
77unsafe impl NSDraggingDestination for NSTextField {}
78
79#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
80unsafe impl NSObjectProtocol for NSTextField {}
81
82#[cfg(all(
83 feature = "NSControl",
84 feature = "NSResponder",
85 feature = "NSTextContent",
86 feature = "NSView"
87))]
88unsafe impl NSTextContent for NSTextField {}
89
90#[cfg(all(
91 feature = "NSControl",
92 feature = "NSResponder",
93 feature = "NSUserInterfaceItemIdentification",
94 feature = "NSView"
95))]
96unsafe impl NSUserInterfaceItemIdentification for NSTextField {}
97
98#[cfg(all(
99 feature = "NSControl",
100 feature = "NSResponder",
101 feature = "NSUserInterfaceValidation",
102 feature = "NSView"
103))]
104unsafe impl NSUserInterfaceValidations for NSTextField {}
105
106#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
107impl NSTextField {
108 extern_methods!(
109 #[unsafe(method(placeholderString))]
110 #[unsafe(method_family = none)]
111 pub unsafe fn placeholderString(&self) -> Option<Retained<NSString>>;
112
113 #[unsafe(method(setPlaceholderString:))]
115 #[unsafe(method_family = none)]
116 pub unsafe fn setPlaceholderString(&self, placeholder_string: Option<&NSString>);
117
118 #[unsafe(method(placeholderAttributedString))]
119 #[unsafe(method_family = none)]
120 pub unsafe fn placeholderAttributedString(&self) -> Option<Retained<NSAttributedString>>;
121
122 #[unsafe(method(setPlaceholderAttributedString:))]
124 #[unsafe(method_family = none)]
125 pub unsafe fn setPlaceholderAttributedString(
126 &self,
127 placeholder_attributed_string: Option<&NSAttributedString>,
128 );
129
130 #[cfg(feature = "NSColor")]
131 #[unsafe(method(backgroundColor))]
132 #[unsafe(method_family = none)]
133 pub unsafe fn backgroundColor(&self) -> Option<Retained<NSColor>>;
134
135 #[cfg(feature = "NSColor")]
136 #[unsafe(method(setBackgroundColor:))]
138 #[unsafe(method_family = none)]
139 pub unsafe fn setBackgroundColor(&self, background_color: Option<&NSColor>);
140
141 #[unsafe(method(drawsBackground))]
142 #[unsafe(method_family = none)]
143 pub unsafe fn drawsBackground(&self) -> bool;
144
145 #[unsafe(method(setDrawsBackground:))]
147 #[unsafe(method_family = none)]
148 pub unsafe fn setDrawsBackground(&self, draws_background: bool);
149
150 #[cfg(feature = "NSColor")]
151 #[unsafe(method(textColor))]
152 #[unsafe(method_family = none)]
153 pub unsafe fn textColor(&self) -> Option<Retained<NSColor>>;
154
155 #[cfg(feature = "NSColor")]
156 #[unsafe(method(setTextColor:))]
158 #[unsafe(method_family = none)]
159 pub unsafe fn setTextColor(&self, text_color: Option<&NSColor>);
160
161 #[unsafe(method(isBordered))]
162 #[unsafe(method_family = none)]
163 pub unsafe fn isBordered(&self) -> bool;
164
165 #[unsafe(method(setBordered:))]
167 #[unsafe(method_family = none)]
168 pub unsafe fn setBordered(&self, bordered: bool);
169
170 #[unsafe(method(isBezeled))]
171 #[unsafe(method_family = none)]
172 pub unsafe fn isBezeled(&self) -> bool;
173
174 #[unsafe(method(setBezeled:))]
176 #[unsafe(method_family = none)]
177 pub unsafe fn setBezeled(&self, bezeled: bool);
178
179 #[unsafe(method(isEditable))]
180 #[unsafe(method_family = none)]
181 pub unsafe fn isEditable(&self) -> bool;
182
183 #[unsafe(method(setEditable:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn setEditable(&self, editable: bool);
187
188 #[unsafe(method(isSelectable))]
189 #[unsafe(method_family = none)]
190 pub unsafe fn isSelectable(&self) -> bool;
191
192 #[unsafe(method(setSelectable:))]
194 #[unsafe(method_family = none)]
195 pub unsafe fn setSelectable(&self, selectable: bool);
196
197 #[unsafe(method(selectText:))]
198 #[unsafe(method_family = none)]
199 pub unsafe fn selectText(&self, sender: Option<&AnyObject>);
200
201 #[unsafe(method(delegate))]
202 #[unsafe(method_family = none)]
203 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSTextFieldDelegate>>>;
204
205 #[unsafe(method(setDelegate:))]
208 #[unsafe(method_family = none)]
209 pub unsafe fn setDelegate(
210 &self,
211 delegate: Option<&ProtocolObject<dyn NSTextFieldDelegate>>,
212 );
213
214 #[cfg(feature = "NSText")]
215 #[unsafe(method(textShouldBeginEditing:))]
216 #[unsafe(method_family = none)]
217 pub unsafe fn textShouldBeginEditing(&self, text_object: &NSText) -> bool;
218
219 #[cfg(feature = "NSText")]
220 #[unsafe(method(textShouldEndEditing:))]
221 #[unsafe(method_family = none)]
222 pub unsafe fn textShouldEndEditing(&self, text_object: &NSText) -> bool;
223
224 #[unsafe(method(textDidBeginEditing:))]
225 #[unsafe(method_family = none)]
226 pub unsafe fn textDidBeginEditing(&self, notification: &NSNotification);
227
228 #[unsafe(method(textDidEndEditing:))]
229 #[unsafe(method_family = none)]
230 pub unsafe fn textDidEndEditing(&self, notification: &NSNotification);
231
232 #[unsafe(method(textDidChange:))]
233 #[unsafe(method_family = none)]
234 pub unsafe fn textDidChange(&self, notification: &NSNotification);
235
236 #[unsafe(method(acceptsFirstResponder))]
237 #[unsafe(method_family = none)]
238 pub unsafe fn acceptsFirstResponder(&self) -> bool;
239
240 #[cfg(feature = "NSTextFieldCell")]
241 #[unsafe(method(bezelStyle))]
242 #[unsafe(method_family = none)]
243 pub unsafe fn bezelStyle(&self) -> NSTextFieldBezelStyle;
244
245 #[cfg(feature = "NSTextFieldCell")]
246 #[unsafe(method(setBezelStyle:))]
248 #[unsafe(method_family = none)]
249 pub unsafe fn setBezelStyle(&self, bezel_style: NSTextFieldBezelStyle);
250
251 #[cfg(feature = "objc2-core-foundation")]
252 #[unsafe(method(preferredMaxLayoutWidth))]
253 #[unsafe(method_family = none)]
254 pub unsafe fn preferredMaxLayoutWidth(&self) -> CGFloat;
255
256 #[cfg(feature = "objc2-core-foundation")]
257 #[unsafe(method(setPreferredMaxLayoutWidth:))]
259 #[unsafe(method_family = none)]
260 pub unsafe fn setPreferredMaxLayoutWidth(&self, preferred_max_layout_width: CGFloat);
261
262 #[unsafe(method(maximumNumberOfLines))]
263 #[unsafe(method_family = none)]
264 pub unsafe fn maximumNumberOfLines(&self) -> NSInteger;
265
266 #[unsafe(method(setMaximumNumberOfLines:))]
268 #[unsafe(method_family = none)]
269 pub unsafe fn setMaximumNumberOfLines(&self, maximum_number_of_lines: NSInteger);
270
271 #[unsafe(method(allowsDefaultTighteningForTruncation))]
272 #[unsafe(method_family = none)]
273 pub unsafe fn allowsDefaultTighteningForTruncation(&self) -> bool;
274
275 #[unsafe(method(setAllowsDefaultTighteningForTruncation:))]
277 #[unsafe(method_family = none)]
278 pub unsafe fn setAllowsDefaultTighteningForTruncation(
279 &self,
280 allows_default_tightening_for_truncation: bool,
281 );
282
283 #[cfg(feature = "NSParagraphStyle")]
284 #[unsafe(method(lineBreakStrategy))]
285 #[unsafe(method_family = none)]
286 pub unsafe fn lineBreakStrategy(&self) -> NSLineBreakStrategy;
287
288 #[cfg(feature = "NSParagraphStyle")]
289 #[unsafe(method(setLineBreakStrategy:))]
291 #[unsafe(method_family = none)]
292 pub unsafe fn setLineBreakStrategy(&self, line_break_strategy: NSLineBreakStrategy);
293
294 #[unsafe(method(allowsWritingTools))]
295 #[unsafe(method_family = none)]
296 pub unsafe fn allowsWritingTools(&self) -> bool;
297
298 #[unsafe(method(setAllowsWritingTools:))]
300 #[unsafe(method_family = none)]
301 pub unsafe fn setAllowsWritingTools(&self, allows_writing_tools: bool);
302 );
303}
304
305#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
307impl NSTextField {
308 extern_methods!(
309 #[unsafe(method(initWithFrame:))]
310 #[unsafe(method_family = init)]
311 pub unsafe fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
312
313 #[unsafe(method(initWithCoder:))]
314 #[unsafe(method_family = init)]
315 pub unsafe fn initWithCoder(
316 this: Allocated<Self>,
317 coder: &NSCoder,
318 ) -> Option<Retained<Self>>;
319 );
320}
321
322#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
324impl NSTextField {
325 extern_methods!(
326 #[unsafe(method(init))]
327 #[unsafe(method_family = init)]
328 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
329 );
330}
331
332#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
334impl NSTextField {
335 extern_methods!(
336 #[unsafe(method(new))]
337 #[unsafe(method_family = new)]
338 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
339 );
340}
341
342#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
344impl NSTextField {
345 extern_methods!(
346 #[unsafe(method(isAutomaticTextCompletionEnabled))]
347 #[unsafe(method_family = none)]
348 pub unsafe fn isAutomaticTextCompletionEnabled(&self) -> bool;
349
350 #[unsafe(method(setAutomaticTextCompletionEnabled:))]
352 #[unsafe(method_family = none)]
353 pub unsafe fn setAutomaticTextCompletionEnabled(
354 &self,
355 automatic_text_completion_enabled: bool,
356 );
357
358 #[unsafe(method(allowsCharacterPickerTouchBarItem))]
359 #[unsafe(method_family = none)]
360 pub unsafe fn allowsCharacterPickerTouchBarItem(&self) -> bool;
361
362 #[unsafe(method(setAllowsCharacterPickerTouchBarItem:))]
364 #[unsafe(method_family = none)]
365 pub unsafe fn setAllowsCharacterPickerTouchBarItem(
366 &self,
367 allows_character_picker_touch_bar_item: bool,
368 );
369 );
370}
371
372#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
374impl NSTextField {
375 extern_methods!(
376 #[unsafe(method(labelWithString:))]
382 #[unsafe(method_family = none)]
383 pub unsafe fn labelWithString(
384 string_value: &NSString,
385 mtm: MainThreadMarker,
386 ) -> Retained<Self>;
387
388 #[unsafe(method(wrappingLabelWithString:))]
394 #[unsafe(method_family = none)]
395 pub unsafe fn wrappingLabelWithString(
396 string_value: &NSString,
397 mtm: MainThreadMarker,
398 ) -> Retained<Self>;
399
400 #[unsafe(method(labelWithAttributedString:))]
407 #[unsafe(method_family = none)]
408 pub unsafe fn labelWithAttributedString(
409 attributed_string_value: &NSAttributedString,
410 mtm: MainThreadMarker,
411 ) -> Retained<Self>;
412
413 #[unsafe(method(textFieldWithString:))]
419 #[unsafe(method_family = none)]
420 pub unsafe fn textFieldWithString(
421 string_value: &NSString,
422 mtm: MainThreadMarker,
423 ) -> Retained<Self>;
424 );
425}
426
427#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
429impl NSTextField {
430 extern_methods!(
431 #[unsafe(method(allowsEditingTextAttributes))]
432 #[unsafe(method_family = none)]
433 pub unsafe fn allowsEditingTextAttributes(&self) -> bool;
434
435 #[unsafe(method(setAllowsEditingTextAttributes:))]
437 #[unsafe(method_family = none)]
438 pub unsafe fn setAllowsEditingTextAttributes(&self, allows_editing_text_attributes: bool);
439
440 #[unsafe(method(importsGraphics))]
441 #[unsafe(method_family = none)]
442 pub unsafe fn importsGraphics(&self) -> bool;
443
444 #[unsafe(method(setImportsGraphics:))]
446 #[unsafe(method_family = none)]
447 pub unsafe fn setImportsGraphics(&self, imports_graphics: bool);
448 );
449}
450
451extern_protocol!(
452 #[cfg(feature = "NSControl")]
454 pub unsafe trait NSTextFieldDelegate:
455 NSControlTextEditingDelegate + MainThreadOnly
456 {
457 #[cfg(all(
458 feature = "NSResponder",
459 feature = "NSText",
460 feature = "NSTextView",
461 feature = "NSView"
462 ))]
463 #[optional]
466 #[unsafe(method(textField:textView:candidatesForSelectedRange:))]
467 #[unsafe(method_family = none)]
468 unsafe fn textField_textView_candidatesForSelectedRange(
469 &self,
470 text_field: &NSTextField,
471 text_view: &NSTextView,
472 selected_range: NSRange,
473 ) -> Option<Retained<NSArray>>;
474
475 #[cfg(all(
476 feature = "NSResponder",
477 feature = "NSText",
478 feature = "NSTextView",
479 feature = "NSView"
480 ))]
481 #[optional]
484 #[unsafe(method(textField:textView:candidates:forSelectedRange:))]
485 #[unsafe(method_family = none)]
486 unsafe fn textField_textView_candidates_forSelectedRange(
487 &self,
488 text_field: &NSTextField,
489 text_view: &NSTextView,
490 candidates: &NSArray<NSTextCheckingResult>,
491 selected_range: NSRange,
492 ) -> Retained<NSArray<NSTextCheckingResult>>;
493
494 #[cfg(all(
495 feature = "NSResponder",
496 feature = "NSText",
497 feature = "NSTextView",
498 feature = "NSView"
499 ))]
500 #[optional]
507 #[unsafe(method(textField:textView:shouldSelectCandidateAtIndex:))]
508 #[unsafe(method_family = none)]
509 unsafe fn textField_textView_shouldSelectCandidateAtIndex(
510 &self,
511 text_field: &NSTextField,
512 text_view: &NSTextView,
513 index: NSUInteger,
514 ) -> bool;
515 }
516);
517
518#[cfg(all(feature = "NSControl", feature = "NSResponder", feature = "NSView"))]
520impl NSTextField {
521 extern_methods!(
522 #[deprecated = "Use `-setTitle:` instead"]
523 #[unsafe(method(setTitleWithMnemonic:))]
524 #[unsafe(method_family = none)]
525 pub unsafe fn setTitleWithMnemonic(&self, string_with_ampersand: Option<&NSString>);
526 );
527}