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