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
32extern_class!(
33 #[unsafe(super(NSView, NSResponder, NSObject))]
35 #[derive(Debug, PartialEq, Eq, Hash)]
36 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
37 pub struct NSText;
38);
39
40#[cfg(all(
41 feature = "NSAccessibilityProtocols",
42 feature = "NSResponder",
43 feature = "NSView"
44))]
45extern_conformance!(
46 unsafe impl NSAccessibility for NSText {}
47);
48
49#[cfg(all(
50 feature = "NSAccessibilityProtocols",
51 feature = "NSResponder",
52 feature = "NSView"
53))]
54extern_conformance!(
55 unsafe impl NSAccessibilityElementProtocol for NSText {}
56);
57
58#[cfg(all(feature = "NSAnimation", feature = "NSResponder", feature = "NSView"))]
59extern_conformance!(
60 unsafe impl NSAnimatablePropertyContainer for NSText {}
61);
62
63#[cfg(all(feature = "NSAppearance", feature = "NSResponder", feature = "NSView"))]
64extern_conformance!(
65 unsafe impl NSAppearanceCustomization for NSText {}
66);
67
68#[cfg(all(
69 feature = "NSResponder",
70 feature = "NSSpellProtocol",
71 feature = "NSView"
72))]
73extern_conformance!(
74 unsafe impl NSChangeSpelling for NSText {}
75);
76
77#[cfg(all(feature = "NSResponder", feature = "NSView"))]
78extern_conformance!(
79 unsafe impl NSCoding for NSText {}
80);
81
82#[cfg(all(feature = "NSDragging", feature = "NSResponder", feature = "NSView"))]
83extern_conformance!(
84 unsafe impl NSDraggingDestination for NSText {}
85);
86
87#[cfg(all(
88 feature = "NSResponder",
89 feature = "NSSpellProtocol",
90 feature = "NSView"
91))]
92extern_conformance!(
93 unsafe impl NSIgnoreMisspelledWords for NSText {}
94);
95
96#[cfg(all(feature = "NSResponder", feature = "NSView"))]
97extern_conformance!(
98 unsafe impl NSObjectProtocol for NSText {}
99);
100
101#[cfg(all(
102 feature = "NSResponder",
103 feature = "NSUserInterfaceItemIdentification",
104 feature = "NSView"
105))]
106extern_conformance!(
107 unsafe impl NSUserInterfaceItemIdentification for NSText {}
108);
109
110#[cfg(all(feature = "NSResponder", feature = "NSView"))]
111impl NSText {
112 extern_methods!(
113 #[unsafe(method(initWithFrame:))]
114 #[unsafe(method_family = init)]
115 pub unsafe fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
116
117 #[unsafe(method(initWithCoder:))]
118 #[unsafe(method_family = init)]
119 pub unsafe fn initWithCoder(
120 this: Allocated<Self>,
121 coder: &NSCoder,
122 ) -> Option<Retained<Self>>;
123
124 #[unsafe(method(string))]
125 #[unsafe(method_family = none)]
126 pub unsafe fn string(&self) -> Retained<NSString>;
127
128 #[unsafe(method(setString:))]
130 #[unsafe(method_family = none)]
131 pub unsafe fn setString(&self, string: &NSString);
132
133 #[unsafe(method(replaceCharactersInRange:withString:))]
134 #[unsafe(method_family = none)]
135 pub unsafe fn replaceCharactersInRange_withString(&self, range: NSRange, string: &NSString);
136
137 #[unsafe(method(replaceCharactersInRange:withRTF:))]
138 #[unsafe(method_family = none)]
139 pub unsafe fn replaceCharactersInRange_withRTF(&self, range: NSRange, rtf_data: &NSData);
140
141 #[unsafe(method(replaceCharactersInRange:withRTFD:))]
142 #[unsafe(method_family = none)]
143 pub unsafe fn replaceCharactersInRange_withRTFD(&self, range: NSRange, rtfd_data: &NSData);
144
145 #[unsafe(method(RTFFromRange:))]
146 #[unsafe(method_family = none)]
147 pub unsafe fn RTFFromRange(&self, range: NSRange) -> Option<Retained<NSData>>;
148
149 #[unsafe(method(RTFDFromRange:))]
150 #[unsafe(method_family = none)]
151 pub unsafe fn RTFDFromRange(&self, range: NSRange) -> Option<Retained<NSData>>;
152
153 #[unsafe(method(writeRTFDToFile:atomically:))]
154 #[unsafe(method_family = none)]
155 pub unsafe fn writeRTFDToFile_atomically(&self, path: &NSString, flag: bool) -> bool;
156
157 #[unsafe(method(readRTFDFromFile:))]
158 #[unsafe(method_family = none)]
159 pub unsafe fn readRTFDFromFile(&self, path: &NSString) -> bool;
160
161 #[unsafe(method(delegate))]
162 #[unsafe(method_family = none)]
163 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSTextDelegate>>>;
164
165 #[unsafe(method(setDelegate:))]
167 #[unsafe(method_family = none)]
168 pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSTextDelegate>>);
169
170 #[unsafe(method(isEditable))]
171 #[unsafe(method_family = none)]
172 pub unsafe fn isEditable(&self) -> bool;
173
174 #[unsafe(method(setEditable:))]
176 #[unsafe(method_family = none)]
177 pub unsafe fn setEditable(&self, editable: bool);
178
179 #[unsafe(method(isSelectable))]
180 #[unsafe(method_family = none)]
181 pub unsafe fn isSelectable(&self) -> bool;
182
183 #[unsafe(method(setSelectable:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn setSelectable(&self, selectable: bool);
187
188 #[unsafe(method(isRichText))]
189 #[unsafe(method_family = none)]
190 pub unsafe fn isRichText(&self) -> bool;
191
192 #[unsafe(method(setRichText:))]
194 #[unsafe(method_family = none)]
195 pub unsafe fn setRichText(&self, rich_text: bool);
196
197 #[unsafe(method(importsGraphics))]
198 #[unsafe(method_family = none)]
199 pub unsafe fn importsGraphics(&self) -> bool;
200
201 #[unsafe(method(setImportsGraphics:))]
203 #[unsafe(method_family = none)]
204 pub unsafe fn setImportsGraphics(&self, imports_graphics: bool);
205
206 #[unsafe(method(isFieldEditor))]
207 #[unsafe(method_family = none)]
208 pub unsafe fn isFieldEditor(&self) -> bool;
209
210 #[unsafe(method(setFieldEditor:))]
212 #[unsafe(method_family = none)]
213 pub unsafe fn setFieldEditor(&self, field_editor: bool);
214
215 #[unsafe(method(usesFontPanel))]
216 #[unsafe(method_family = none)]
217 pub unsafe fn usesFontPanel(&self) -> bool;
218
219 #[unsafe(method(setUsesFontPanel:))]
221 #[unsafe(method_family = none)]
222 pub unsafe fn setUsesFontPanel(&self, uses_font_panel: bool);
223
224 #[unsafe(method(drawsBackground))]
225 #[unsafe(method_family = none)]
226 pub unsafe fn drawsBackground(&self) -> bool;
227
228 #[unsafe(method(setDrawsBackground:))]
230 #[unsafe(method_family = none)]
231 pub unsafe fn setDrawsBackground(&self, draws_background: bool);
232
233 #[cfg(feature = "NSColor")]
234 #[unsafe(method(backgroundColor))]
235 #[unsafe(method_family = none)]
236 pub unsafe fn backgroundColor(&self) -> Option<Retained<NSColor>>;
237
238 #[cfg(feature = "NSColor")]
239 #[unsafe(method(setBackgroundColor:))]
241 #[unsafe(method_family = none)]
242 pub unsafe fn setBackgroundColor(&self, background_color: Option<&NSColor>);
243
244 #[unsafe(method(isRulerVisible))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn isRulerVisible(&self) -> bool;
247
248 #[unsafe(method(selectedRange))]
249 #[unsafe(method_family = none)]
250 pub unsafe fn selectedRange(&self) -> NSRange;
251
252 #[unsafe(method(setSelectedRange:))]
254 #[unsafe(method_family = none)]
255 pub unsafe fn setSelectedRange(&self, selected_range: NSRange);
256
257 #[unsafe(method(scrollRangeToVisible:))]
258 #[unsafe(method_family = none)]
259 pub unsafe fn scrollRangeToVisible(&self, range: NSRange);
260
261 #[cfg(feature = "NSFont")]
262 #[unsafe(method(font))]
263 #[unsafe(method_family = none)]
264 pub unsafe fn font(&self) -> Option<Retained<NSFont>>;
265
266 #[cfg(feature = "NSFont")]
267 #[unsafe(method(setFont:))]
269 #[unsafe(method_family = none)]
270 pub unsafe fn setFont(&self, font: Option<&NSFont>);
271
272 #[cfg(feature = "NSColor")]
273 #[unsafe(method(textColor))]
274 #[unsafe(method_family = none)]
275 pub unsafe fn textColor(&self) -> Option<Retained<NSColor>>;
276
277 #[cfg(feature = "NSColor")]
278 #[unsafe(method(setTextColor:))]
280 #[unsafe(method_family = none)]
281 pub unsafe fn setTextColor(&self, text_color: Option<&NSColor>);
282
283 #[unsafe(method(alignment))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn alignment(&self) -> NSTextAlignment;
286
287 #[unsafe(method(setAlignment:))]
289 #[unsafe(method_family = none)]
290 pub unsafe fn setAlignment(&self, alignment: NSTextAlignment);
291
292 #[unsafe(method(baseWritingDirection))]
293 #[unsafe(method_family = none)]
294 pub unsafe fn baseWritingDirection(&self) -> NSWritingDirection;
295
296 #[unsafe(method(setBaseWritingDirection:))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn setBaseWritingDirection(&self, base_writing_direction: NSWritingDirection);
300
301 #[cfg(feature = "NSColor")]
302 #[unsafe(method(setTextColor:range:))]
303 #[unsafe(method_family = none)]
304 pub unsafe fn setTextColor_range(&self, color: Option<&NSColor>, range: NSRange);
305
306 #[cfg(feature = "NSFont")]
307 #[unsafe(method(setFont:range:))]
308 #[unsafe(method_family = none)]
309 pub unsafe fn setFont_range(&self, font: &NSFont, range: NSRange);
310
311 #[unsafe(method(maxSize))]
312 #[unsafe(method_family = none)]
313 pub unsafe fn maxSize(&self) -> NSSize;
314
315 #[unsafe(method(setMaxSize:))]
317 #[unsafe(method_family = none)]
318 pub unsafe fn setMaxSize(&self, max_size: NSSize);
319
320 #[unsafe(method(minSize))]
321 #[unsafe(method_family = none)]
322 pub unsafe fn minSize(&self) -> NSSize;
323
324 #[unsafe(method(setMinSize:))]
326 #[unsafe(method_family = none)]
327 pub unsafe fn setMinSize(&self, min_size: NSSize);
328
329 #[unsafe(method(isHorizontallyResizable))]
330 #[unsafe(method_family = none)]
331 pub unsafe fn isHorizontallyResizable(&self) -> bool;
332
333 #[unsafe(method(setHorizontallyResizable:))]
335 #[unsafe(method_family = none)]
336 pub unsafe fn setHorizontallyResizable(&self, horizontally_resizable: bool);
337
338 #[unsafe(method(isVerticallyResizable))]
339 #[unsafe(method_family = none)]
340 pub unsafe fn isVerticallyResizable(&self) -> bool;
341
342 #[unsafe(method(setVerticallyResizable:))]
344 #[unsafe(method_family = none)]
345 pub unsafe fn setVerticallyResizable(&self, vertically_resizable: bool);
346
347 #[unsafe(method(sizeToFit))]
348 #[unsafe(method_family = none)]
349 pub unsafe fn sizeToFit(&self);
350
351 #[unsafe(method(copy:))]
352 #[unsafe(method_family = none)]
353 pub unsafe fn copy(&self, sender: Option<&AnyObject>);
354
355 #[unsafe(method(copyFont:))]
356 #[unsafe(method_family = none)]
357 pub unsafe fn copyFont(&self, sender: Option<&AnyObject>);
358
359 #[unsafe(method(copyRuler:))]
360 #[unsafe(method_family = none)]
361 pub unsafe fn copyRuler(&self, sender: Option<&AnyObject>);
362
363 #[unsafe(method(cut:))]
364 #[unsafe(method_family = none)]
365 pub unsafe fn cut(&self, sender: Option<&AnyObject>);
366
367 #[unsafe(method(delete:))]
368 #[unsafe(method_family = none)]
369 pub unsafe fn delete(&self, sender: Option<&AnyObject>);
370
371 #[unsafe(method(paste:))]
372 #[unsafe(method_family = none)]
373 pub unsafe fn paste(&self, sender: Option<&AnyObject>);
374
375 #[unsafe(method(pasteFont:))]
376 #[unsafe(method_family = none)]
377 pub unsafe fn pasteFont(&self, sender: Option<&AnyObject>);
378
379 #[unsafe(method(pasteRuler:))]
380 #[unsafe(method_family = none)]
381 pub unsafe fn pasteRuler(&self, sender: Option<&AnyObject>);
382
383 #[unsafe(method(selectAll:))]
384 #[unsafe(method_family = none)]
385 pub unsafe fn selectAll(&self, sender: Option<&AnyObject>);
386
387 #[unsafe(method(changeFont:))]
388 #[unsafe(method_family = none)]
389 pub unsafe fn changeFont(&self, sender: Option<&AnyObject>);
390
391 #[unsafe(method(alignLeft:))]
392 #[unsafe(method_family = none)]
393 pub unsafe fn alignLeft(&self, sender: Option<&AnyObject>);
394
395 #[unsafe(method(alignRight:))]
396 #[unsafe(method_family = none)]
397 pub unsafe fn alignRight(&self, sender: Option<&AnyObject>);
398
399 #[unsafe(method(alignCenter:))]
400 #[unsafe(method_family = none)]
401 pub unsafe fn alignCenter(&self, sender: Option<&AnyObject>);
402
403 #[unsafe(method(subscript:))]
404 #[unsafe(method_family = none)]
405 pub unsafe fn subscript(&self, sender: Option<&AnyObject>);
406
407 #[unsafe(method(superscript:))]
408 #[unsafe(method_family = none)]
409 pub unsafe fn superscript(&self, sender: Option<&AnyObject>);
410
411 #[unsafe(method(underline:))]
412 #[unsafe(method_family = none)]
413 pub unsafe fn underline(&self, sender: Option<&AnyObject>);
414
415 #[unsafe(method(unscript:))]
416 #[unsafe(method_family = none)]
417 pub unsafe fn unscript(&self, sender: Option<&AnyObject>);
418
419 #[unsafe(method(showGuessPanel:))]
420 #[unsafe(method_family = none)]
421 pub unsafe fn showGuessPanel(&self, sender: Option<&AnyObject>);
422
423 #[unsafe(method(checkSpelling:))]
424 #[unsafe(method_family = none)]
425 pub unsafe fn checkSpelling(&self, sender: Option<&AnyObject>);
426
427 #[unsafe(method(toggleRuler:))]
428 #[unsafe(method_family = none)]
429 pub unsafe fn toggleRuler(&self, sender: Option<&AnyObject>);
430 );
431}
432
433#[cfg(all(feature = "NSResponder", feature = "NSView"))]
435impl NSText {
436 extern_methods!(
437 #[unsafe(method(init))]
438 #[unsafe(method_family = init)]
439 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
440 );
441}
442
443#[cfg(all(feature = "NSResponder", feature = "NSView"))]
445impl NSText {
446 extern_methods!(
447 #[unsafe(method(new))]
448 #[unsafe(method_family = new)]
449 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
450 );
451}
452
453pub const NSEnterCharacter: c_uint = 0x0003;
455pub const NSBackspaceCharacter: c_uint = 0x0008;
457pub const NSTabCharacter: c_uint = 0x0009;
459pub const NSNewlineCharacter: c_uint = 0x000a;
461pub const NSFormFeedCharacter: c_uint = 0x000c;
463pub const NSCarriageReturnCharacter: c_uint = 0x000d;
465pub const NSBackTabCharacter: c_uint = 0x0019;
467pub const NSDeleteCharacter: c_uint = 0x007f;
469pub const NSLineSeparatorCharacter: c_uint = 0x2028;
471pub const NSParagraphSeparatorCharacter: c_uint = 0x2029;
473
474#[repr(transparent)]
477#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
478pub struct NSTextMovement(pub NSInteger);
479impl NSTextMovement {
480 #[doc(alias = "NSTextMovementReturn")]
481 pub const Return: Self = Self(0x10);
482 #[doc(alias = "NSTextMovementTab")]
483 pub const Tab: Self = Self(0x11);
484 #[doc(alias = "NSTextMovementBacktab")]
485 pub const Backtab: Self = Self(0x12);
486 #[doc(alias = "NSTextMovementLeft")]
487 pub const Left: Self = Self(0x13);
488 #[doc(alias = "NSTextMovementRight")]
489 pub const Right: Self = Self(0x14);
490 #[doc(alias = "NSTextMovementUp")]
491 pub const Up: Self = Self(0x15);
492 #[doc(alias = "NSTextMovementDown")]
493 pub const Down: Self = Self(0x16);
494 #[doc(alias = "NSTextMovementCancel")]
495 pub const Cancel: Self = Self(0x17);
496 #[doc(alias = "NSTextMovementOther")]
497 pub const Other: Self = Self(0);
498}
499
500unsafe impl Encode for NSTextMovement {
501 const ENCODING: Encoding = NSInteger::ENCODING;
502}
503
504unsafe impl RefEncode for NSTextMovement {
505 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
506}
507
508extern "C" {
509 pub static NSTextDidBeginEditingNotification: &'static NSNotificationName;
511}
512
513extern "C" {
514 pub static NSTextDidEndEditingNotification: &'static NSNotificationName;
516}
517
518extern "C" {
519 pub static NSTextDidChangeNotification: &'static NSNotificationName;
521}
522
523extern "C" {
524 pub static NSTextMovementUserInfoKey: &'static NSString;
526}
527
528pub const NSIllegalTextMovement: c_uint = 0;
530pub const NSReturnTextMovement: c_uint = 0x10;
532pub const NSTabTextMovement: c_uint = 0x11;
534pub const NSBacktabTextMovement: c_uint = 0x12;
536pub const NSLeftTextMovement: c_uint = 0x13;
538pub const NSRightTextMovement: c_uint = 0x14;
540pub const NSUpTextMovement: c_uint = 0x15;
542pub const NSDownTextMovement: c_uint = 0x16;
544pub const NSCancelTextMovement: c_uint = 0x17;
546pub const NSOtherTextMovement: c_uint = 0;
548
549extern_protocol!(
550 pub unsafe trait NSTextDelegate: NSObjectProtocol + MainThreadOnly {
552 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
553 #[optional]
554 #[unsafe(method(textShouldBeginEditing:))]
555 #[unsafe(method_family = none)]
556 unsafe fn textShouldBeginEditing(&self, text_object: &NSText) -> bool;
557
558 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
559 #[optional]
560 #[unsafe(method(textShouldEndEditing:))]
561 #[unsafe(method_family = none)]
562 unsafe fn textShouldEndEditing(&self, text_object: &NSText) -> bool;
563
564 #[optional]
565 #[unsafe(method(textDidBeginEditing:))]
566 #[unsafe(method_family = none)]
567 unsafe fn textDidBeginEditing(&self, notification: &NSNotification);
568
569 #[optional]
570 #[unsafe(method(textDidEndEditing:))]
571 #[unsafe(method_family = none)]
572 unsafe fn textDidEndEditing(&self, notification: &NSNotification);
573
574 #[optional]
575 #[unsafe(method(textDidChange:))]
576 #[unsafe(method_family = none)]
577 unsafe fn textDidChange(&self, notification: &NSNotification);
578 }
579);
580
581#[deprecated = "Use NSWritingDirectionEmbedding instead"]
583pub const NSTextWritingDirectionEmbedding: c_uint = 0 << 1;
584#[deprecated = "Use NSWritingDirectionOverride instead"]
586pub const NSTextWritingDirectionOverride: c_uint = 1 << 1;
587
588pub static NSLeftTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Left.0);
590
591pub static NSRightTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Right.0);
593
594pub static NSCenterTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Center.0);
596
597pub static NSJustifiedTextAlignment: NSTextAlignment =
599 NSTextAlignment(NSTextAlignment::Justified.0);
600
601pub static NSNaturalTextAlignment: NSTextAlignment = NSTextAlignment(NSTextAlignment::Natural.0);