1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct NSWritingDirection(pub NSInteger);
15impl NSWritingDirection {
16 #[doc(alias = "NSWritingDirectionNatural")]
17 pub const Natural: Self = Self(-1);
18 #[doc(alias = "NSWritingDirectionLeftToRight")]
19 pub const LeftToRight: Self = Self(0);
20 #[doc(alias = "NSWritingDirectionRightToLeft")]
21 pub const RightToLeft: Self = Self(1);
22}
23
24unsafe impl Encode for NSWritingDirection {
25 const ENCODING: Encoding = NSInteger::ENCODING;
26}
27
28unsafe impl RefEncode for NSWritingDirection {
29 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
30}
31
32#[repr(transparent)]
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
36pub struct NSTextAlignment(pub NSInteger);
37impl NSTextAlignment {
38 #[doc(alias = "NSTextAlignmentLeft")]
39 pub const Left: Self = Self(0);
40 #[doc(alias = "NSTextAlignmentJustified")]
41 pub const Justified: Self = Self(3);
42 #[doc(alias = "NSTextAlignmentNatural")]
48 pub const Natural: Self = Self(4);
49}
50
51unsafe impl Encode for NSTextAlignment {
52 const ENCODING: Encoding = NSInteger::ENCODING;
53}
54
55unsafe impl RefEncode for NSTextAlignment {
56 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
57}
58
59extern_class!(
60 #[unsafe(super(NSView, NSResponder, NSObject))]
62 #[derive(Debug, PartialEq, Eq, Hash)]
63 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
64 pub struct NSText;
65);
66
67#[cfg(all(
68 feature = "NSAccessibilityProtocols",
69 feature = "NSResponder",
70 feature = "NSView"
71))]
72extern_conformance!(
73 unsafe impl NSAccessibility for NSText {}
74);
75
76#[cfg(all(
77 feature = "NSAccessibilityProtocols",
78 feature = "NSResponder",
79 feature = "NSView"
80))]
81extern_conformance!(
82 unsafe impl NSAccessibilityElementProtocol for NSText {}
83);
84
85#[cfg(all(feature = "NSAnimation", feature = "NSResponder", feature = "NSView"))]
86extern_conformance!(
87 unsafe impl NSAnimatablePropertyContainer for NSText {}
88);
89
90#[cfg(all(feature = "NSAppearance", feature = "NSResponder", feature = "NSView"))]
91extern_conformance!(
92 unsafe impl NSAppearanceCustomization for NSText {}
93);
94
95#[cfg(all(
96 feature = "NSResponder",
97 feature = "NSSpellProtocol",
98 feature = "NSView"
99))]
100extern_conformance!(
101 unsafe impl NSChangeSpelling for NSText {}
102);
103
104#[cfg(all(feature = "NSResponder", feature = "NSView"))]
105extern_conformance!(
106 unsafe impl NSCoding for NSText {}
107);
108
109#[cfg(all(feature = "NSDragging", feature = "NSResponder", feature = "NSView"))]
110extern_conformance!(
111 unsafe impl NSDraggingDestination for NSText {}
112);
113
114#[cfg(all(
115 feature = "NSResponder",
116 feature = "NSSpellProtocol",
117 feature = "NSView"
118))]
119extern_conformance!(
120 unsafe impl NSIgnoreMisspelledWords for NSText {}
121);
122
123#[cfg(all(feature = "NSResponder", feature = "NSView"))]
124extern_conformance!(
125 unsafe impl NSObjectProtocol for NSText {}
126);
127
128#[cfg(all(
129 feature = "NSResponder",
130 feature = "NSUserInterfaceItemIdentification",
131 feature = "NSView"
132))]
133extern_conformance!(
134 unsafe impl NSUserInterfaceItemIdentification for NSText {}
135);
136
137#[cfg(all(feature = "NSResponder", feature = "NSView"))]
138impl NSText {
139 extern_methods!(
140 #[unsafe(method(initWithFrame:))]
141 #[unsafe(method_family = init)]
142 pub fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
143
144 #[unsafe(method(initWithCoder:))]
148 #[unsafe(method_family = init)]
149 pub unsafe fn initWithCoder(
150 this: Allocated<Self>,
151 coder: &NSCoder,
152 ) -> Option<Retained<Self>>;
153
154 #[unsafe(method(string))]
155 #[unsafe(method_family = none)]
156 pub fn string(&self) -> Retained<NSString>;
157
158 #[unsafe(method(setString:))]
162 #[unsafe(method_family = none)]
163 pub fn setString(&self, string: &NSString);
164
165 #[unsafe(method(replaceCharactersInRange:withString:))]
166 #[unsafe(method_family = none)]
167 pub fn replaceCharactersInRange_withString(&self, range: NSRange, string: &NSString);
168
169 #[unsafe(method(replaceCharactersInRange:withRTF:))]
170 #[unsafe(method_family = none)]
171 pub fn replaceCharactersInRange_withRTF(&self, range: NSRange, rtf_data: &NSData);
172
173 #[unsafe(method(replaceCharactersInRange:withRTFD:))]
174 #[unsafe(method_family = none)]
175 pub fn replaceCharactersInRange_withRTFD(&self, range: NSRange, rtfd_data: &NSData);
176
177 #[unsafe(method(RTFFromRange:))]
178 #[unsafe(method_family = none)]
179 pub fn RTFFromRange(&self, range: NSRange) -> Option<Retained<NSData>>;
180
181 #[unsafe(method(RTFDFromRange:))]
182 #[unsafe(method_family = none)]
183 pub fn RTFDFromRange(&self, range: NSRange) -> Option<Retained<NSData>>;
184
185 #[unsafe(method(writeRTFDToFile:atomically:))]
186 #[unsafe(method_family = none)]
187 pub fn writeRTFDToFile_atomically(&self, path: &NSString, flag: bool) -> bool;
188
189 #[unsafe(method(readRTFDFromFile:))]
190 #[unsafe(method_family = none)]
191 pub fn readRTFDFromFile(&self, path: &NSString) -> bool;
192
193 #[unsafe(method(delegate))]
197 #[unsafe(method_family = none)]
198 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSTextDelegate>>>;
199
200 #[unsafe(method(setDelegate:))]
206 #[unsafe(method_family = none)]
207 pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSTextDelegate>>);
208
209 #[unsafe(method(isEditable))]
210 #[unsafe(method_family = none)]
211 pub fn isEditable(&self) -> bool;
212
213 #[unsafe(method(setEditable:))]
215 #[unsafe(method_family = none)]
216 pub fn setEditable(&self, editable: bool);
217
218 #[unsafe(method(isSelectable))]
219 #[unsafe(method_family = none)]
220 pub fn isSelectable(&self) -> bool;
221
222 #[unsafe(method(setSelectable:))]
224 #[unsafe(method_family = none)]
225 pub fn setSelectable(&self, selectable: bool);
226
227 #[unsafe(method(isRichText))]
228 #[unsafe(method_family = none)]
229 pub fn isRichText(&self) -> bool;
230
231 #[unsafe(method(setRichText:))]
233 #[unsafe(method_family = none)]
234 pub fn setRichText(&self, rich_text: bool);
235
236 #[unsafe(method(importsGraphics))]
237 #[unsafe(method_family = none)]
238 pub fn importsGraphics(&self) -> bool;
239
240 #[unsafe(method(setImportsGraphics:))]
242 #[unsafe(method_family = none)]
243 pub fn setImportsGraphics(&self, imports_graphics: bool);
244
245 #[unsafe(method(isFieldEditor))]
246 #[unsafe(method_family = none)]
247 pub fn isFieldEditor(&self) -> bool;
248
249 #[unsafe(method(setFieldEditor:))]
251 #[unsafe(method_family = none)]
252 pub fn setFieldEditor(&self, field_editor: bool);
253
254 #[unsafe(method(usesFontPanel))]
255 #[unsafe(method_family = none)]
256 pub fn usesFontPanel(&self) -> bool;
257
258 #[unsafe(method(setUsesFontPanel:))]
260 #[unsafe(method_family = none)]
261 pub fn setUsesFontPanel(&self, uses_font_panel: bool);
262
263 #[unsafe(method(drawsBackground))]
264 #[unsafe(method_family = none)]
265 pub fn drawsBackground(&self) -> bool;
266
267 #[unsafe(method(setDrawsBackground:))]
269 #[unsafe(method_family = none)]
270 pub fn setDrawsBackground(&self, draws_background: bool);
271
272 #[cfg(feature = "NSColor")]
273 #[unsafe(method(backgroundColor))]
274 #[unsafe(method_family = none)]
275 pub fn backgroundColor(&self) -> Option<Retained<NSColor>>;
276
277 #[cfg(feature = "NSColor")]
278 #[unsafe(method(setBackgroundColor:))]
282 #[unsafe(method_family = none)]
283 pub fn setBackgroundColor(&self, background_color: Option<&NSColor>);
284
285 #[unsafe(method(isRulerVisible))]
286 #[unsafe(method_family = none)]
287 pub fn isRulerVisible(&self) -> bool;
288
289 #[unsafe(method(selectedRange))]
290 #[unsafe(method_family = none)]
291 pub fn selectedRange(&self) -> NSRange;
292
293 #[unsafe(method(setSelectedRange:))]
295 #[unsafe(method_family = none)]
296 pub fn setSelectedRange(&self, selected_range: NSRange);
297
298 #[unsafe(method(scrollRangeToVisible:))]
299 #[unsafe(method_family = none)]
300 pub fn scrollRangeToVisible(&self, range: NSRange);
301
302 #[cfg(feature = "NSFont")]
303 #[unsafe(method(font))]
304 #[unsafe(method_family = none)]
305 pub fn font(&self) -> Option<Retained<NSFont>>;
306
307 #[cfg(feature = "NSFont")]
308 #[unsafe(method(setFont:))]
310 #[unsafe(method_family = none)]
311 pub fn setFont(&self, font: Option<&NSFont>);
312
313 #[cfg(feature = "NSColor")]
314 #[unsafe(method(textColor))]
315 #[unsafe(method_family = none)]
316 pub fn textColor(&self) -> Option<Retained<NSColor>>;
317
318 #[cfg(feature = "NSColor")]
319 #[unsafe(method(setTextColor:))]
323 #[unsafe(method_family = none)]
324 pub fn setTextColor(&self, text_color: Option<&NSColor>);
325
326 #[unsafe(method(alignment))]
327 #[unsafe(method_family = none)]
328 pub fn alignment(&self) -> NSTextAlignment;
329
330 #[unsafe(method(setAlignment:))]
332 #[unsafe(method_family = none)]
333 pub fn setAlignment(&self, alignment: NSTextAlignment);
334
335 #[unsafe(method(baseWritingDirection))]
336 #[unsafe(method_family = none)]
337 pub fn baseWritingDirection(&self) -> NSWritingDirection;
338
339 #[unsafe(method(setBaseWritingDirection:))]
341 #[unsafe(method_family = none)]
342 pub fn setBaseWritingDirection(&self, base_writing_direction: NSWritingDirection);
343
344 #[cfg(feature = "NSColor")]
345 #[unsafe(method(setTextColor:range:))]
346 #[unsafe(method_family = none)]
347 pub fn setTextColor_range(&self, color: Option<&NSColor>, range: NSRange);
348
349 #[cfg(feature = "NSFont")]
350 #[unsafe(method(setFont:range:))]
351 #[unsafe(method_family = none)]
352 pub fn setFont_range(&self, font: &NSFont, range: NSRange);
353
354 #[unsafe(method(maxSize))]
355 #[unsafe(method_family = none)]
356 pub fn maxSize(&self) -> NSSize;
357
358 #[unsafe(method(setMaxSize:))]
360 #[unsafe(method_family = none)]
361 pub fn setMaxSize(&self, max_size: NSSize);
362
363 #[unsafe(method(minSize))]
364 #[unsafe(method_family = none)]
365 pub fn minSize(&self) -> NSSize;
366
367 #[unsafe(method(setMinSize:))]
369 #[unsafe(method_family = none)]
370 pub fn setMinSize(&self, min_size: NSSize);
371
372 #[unsafe(method(isHorizontallyResizable))]
373 #[unsafe(method_family = none)]
374 pub fn isHorizontallyResizable(&self) -> bool;
375
376 #[unsafe(method(setHorizontallyResizable:))]
378 #[unsafe(method_family = none)]
379 pub fn setHorizontallyResizable(&self, horizontally_resizable: bool);
380
381 #[unsafe(method(isVerticallyResizable))]
382 #[unsafe(method_family = none)]
383 pub fn isVerticallyResizable(&self) -> bool;
384
385 #[unsafe(method(setVerticallyResizable:))]
387 #[unsafe(method_family = none)]
388 pub fn setVerticallyResizable(&self, vertically_resizable: bool);
389
390 #[unsafe(method(sizeToFit))]
391 #[unsafe(method_family = none)]
392 pub fn sizeToFit(&self);
393
394 #[unsafe(method(copy:))]
398 #[unsafe(method_family = none)]
399 pub unsafe fn copy(&self, sender: Option<&AnyObject>);
400
401 #[unsafe(method(copyFont:))]
405 #[unsafe(method_family = none)]
406 pub unsafe fn copyFont(&self, sender: Option<&AnyObject>);
407
408 #[unsafe(method(copyRuler:))]
412 #[unsafe(method_family = none)]
413 pub unsafe fn copyRuler(&self, sender: Option<&AnyObject>);
414
415 #[unsafe(method(cut:))]
419 #[unsafe(method_family = none)]
420 pub unsafe fn cut(&self, sender: Option<&AnyObject>);
421
422 #[unsafe(method(delete:))]
426 #[unsafe(method_family = none)]
427 pub unsafe fn delete(&self, sender: Option<&AnyObject>);
428
429 #[unsafe(method(paste:))]
433 #[unsafe(method_family = none)]
434 pub unsafe fn paste(&self, sender: Option<&AnyObject>);
435
436 #[unsafe(method(pasteFont:))]
440 #[unsafe(method_family = none)]
441 pub unsafe fn pasteFont(&self, sender: Option<&AnyObject>);
442
443 #[unsafe(method(pasteRuler:))]
447 #[unsafe(method_family = none)]
448 pub unsafe fn pasteRuler(&self, sender: Option<&AnyObject>);
449
450 #[unsafe(method(selectAll:))]
454 #[unsafe(method_family = none)]
455 pub unsafe fn selectAll(&self, sender: Option<&AnyObject>);
456
457 #[unsafe(method(changeFont:))]
461 #[unsafe(method_family = none)]
462 pub unsafe fn changeFont(&self, sender: Option<&AnyObject>);
463
464 #[unsafe(method(alignLeft:))]
468 #[unsafe(method_family = none)]
469 pub unsafe fn alignLeft(&self, sender: Option<&AnyObject>);
470
471 #[unsafe(method(alignRight:))]
475 #[unsafe(method_family = none)]
476 pub unsafe fn alignRight(&self, sender: Option<&AnyObject>);
477
478 #[unsafe(method(alignCenter:))]
482 #[unsafe(method_family = none)]
483 pub unsafe fn alignCenter(&self, sender: Option<&AnyObject>);
484
485 #[unsafe(method(subscript:))]
489 #[unsafe(method_family = none)]
490 pub unsafe fn subscript(&self, sender: Option<&AnyObject>);
491
492 #[unsafe(method(superscript:))]
496 #[unsafe(method_family = none)]
497 pub unsafe fn superscript(&self, sender: Option<&AnyObject>);
498
499 #[unsafe(method(underline:))]
503 #[unsafe(method_family = none)]
504 pub unsafe fn underline(&self, sender: Option<&AnyObject>);
505
506 #[unsafe(method(unscript:))]
510 #[unsafe(method_family = none)]
511 pub unsafe fn unscript(&self, sender: Option<&AnyObject>);
512
513 #[unsafe(method(showGuessPanel:))]
517 #[unsafe(method_family = none)]
518 pub unsafe fn showGuessPanel(&self, sender: Option<&AnyObject>);
519
520 #[unsafe(method(checkSpelling:))]
524 #[unsafe(method_family = none)]
525 pub unsafe fn checkSpelling(&self, sender: Option<&AnyObject>);
526
527 #[unsafe(method(toggleRuler:))]
531 #[unsafe(method_family = none)]
532 pub unsafe fn toggleRuler(&self, sender: Option<&AnyObject>);
533 );
534}
535
536#[cfg(all(feature = "NSResponder", feature = "NSView"))]
538impl NSText {
539 extern_methods!(
540 #[unsafe(method(init))]
541 #[unsafe(method_family = init)]
542 pub fn init(this: Allocated<Self>) -> Retained<Self>;
543 );
544}
545
546#[cfg(all(feature = "NSResponder", feature = "NSView"))]
548impl NSText {
549 extern_methods!(
550 #[unsafe(method(new))]
551 #[unsafe(method_family = new)]
552 pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
553 );
554}
555
556pub const NSEnterCharacter: c_uint = 0x0003;
558pub const NSBackspaceCharacter: c_uint = 0x0008;
560pub const NSTabCharacter: c_uint = 0x0009;
562pub const NSNewlineCharacter: c_uint = 0x000a;
564pub const NSFormFeedCharacter: c_uint = 0x000c;
566pub const NSCarriageReturnCharacter: c_uint = 0x000d;
568pub const NSBackTabCharacter: c_uint = 0x0019;
570pub const NSDeleteCharacter: c_uint = 0x007f;
572pub const NSLineSeparatorCharacter: c_uint = 0x2028;
574pub const NSParagraphSeparatorCharacter: c_uint = 0x2029;
576
577#[repr(transparent)]
580#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
581pub struct NSTextMovement(pub NSInteger);
582impl NSTextMovement {
583 #[doc(alias = "NSTextMovementReturn")]
584 pub const Return: Self = Self(0x10);
585 #[doc(alias = "NSTextMovementTab")]
586 pub const Tab: Self = Self(0x11);
587 #[doc(alias = "NSTextMovementBacktab")]
588 pub const Backtab: Self = Self(0x12);
589 #[doc(alias = "NSTextMovementLeft")]
590 pub const Left: Self = Self(0x13);
591 #[doc(alias = "NSTextMovementRight")]
592 pub const Right: Self = Self(0x14);
593 #[doc(alias = "NSTextMovementUp")]
594 pub const Up: Self = Self(0x15);
595 #[doc(alias = "NSTextMovementDown")]
596 pub const Down: Self = Self(0x16);
597 #[doc(alias = "NSTextMovementCancel")]
598 pub const Cancel: Self = Self(0x17);
599 #[doc(alias = "NSTextMovementOther")]
600 pub const Other: Self = Self(0);
601}
602
603unsafe impl Encode for NSTextMovement {
604 const ENCODING: Encoding = NSInteger::ENCODING;
605}
606
607unsafe impl RefEncode for NSTextMovement {
608 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
609}
610
611extern "C" {
612 pub static NSTextDidBeginEditingNotification: &'static NSNotificationName;
614}
615
616extern "C" {
617 pub static NSTextDidEndEditingNotification: &'static NSNotificationName;
619}
620
621extern "C" {
622 pub static NSTextDidChangeNotification: &'static NSNotificationName;
624}
625
626extern "C" {
627 pub static NSTextMovementUserInfoKey: &'static NSString;
629}
630
631pub const NSIllegalTextMovement: c_uint = 0;
633pub const NSReturnTextMovement: c_uint = 0x10;
635pub const NSTabTextMovement: c_uint = 0x11;
637pub const NSBacktabTextMovement: c_uint = 0x12;
639pub const NSLeftTextMovement: c_uint = 0x13;
641pub const NSRightTextMovement: c_uint = 0x14;
643pub const NSUpTextMovement: c_uint = 0x15;
645pub const NSDownTextMovement: c_uint = 0x16;
647pub const NSCancelTextMovement: c_uint = 0x17;
649pub const NSOtherTextMovement: c_uint = 0;
651
652extern_protocol!(
653 pub unsafe trait NSTextDelegate: NSObjectProtocol + MainThreadOnly {
655 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
656 #[optional]
657 #[unsafe(method(textShouldBeginEditing:))]
658 #[unsafe(method_family = none)]
659 fn textShouldBeginEditing(&self, text_object: &NSText) -> bool;
660
661 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
662 #[optional]
663 #[unsafe(method(textShouldEndEditing:))]
664 #[unsafe(method_family = none)]
665 fn textShouldEndEditing(&self, text_object: &NSText) -> bool;
666
667 #[optional]
668 #[unsafe(method(textDidBeginEditing:))]
669 #[unsafe(method_family = none)]
670 fn textDidBeginEditing(&self, notification: &NSNotification);
671
672 #[optional]
673 #[unsafe(method(textDidEndEditing:))]
674 #[unsafe(method_family = none)]
675 fn textDidEndEditing(&self, notification: &NSNotification);
676
677 #[optional]
678 #[unsafe(method(textDidChange:))]
679 #[unsafe(method_family = none)]
680 fn textDidChange(&self, notification: &NSNotification);
681 }
682);
683
684#[deprecated = "Use NSWritingDirectionEmbedding instead"]
686pub const NSTextWritingDirectionEmbedding: c_uint = 0 << 1;
687#[deprecated = "Use NSWritingDirectionOverride instead"]
689pub const NSTextWritingDirectionOverride: c_uint = 1 << 1;
690
691#[deprecated]
693pub static NSLeftTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Left.0);
694
695#[deprecated]
697pub static NSRightTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Right.0);
698
699#[deprecated]
701pub static NSCenterTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Center.0);
702
703#[deprecated]
705pub static NSJustifiedTextAlignment: NSTextAlignment =
706 NSTextAlignment(NSTextAlignment::Justified.0);
707
708#[deprecated]
710pub static NSNaturalTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Natural.0);