1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10pub type NSTextCheckingOptionKey = NSString;
13
14extern "C" {
15 pub static NSTextCheckingOrthographyKey: &'static NSTextCheckingOptionKey;
17}
18
19extern "C" {
20 pub static NSTextCheckingQuotesKey: &'static NSTextCheckingOptionKey;
22}
23
24extern "C" {
25 pub static NSTextCheckingReplacementsKey: &'static NSTextCheckingOptionKey;
27}
28
29extern "C" {
30 pub static NSTextCheckingReferenceDateKey: &'static NSTextCheckingOptionKey;
32}
33
34extern "C" {
35 pub static NSTextCheckingReferenceTimeZoneKey: &'static NSTextCheckingOptionKey;
37}
38
39extern "C" {
40 pub static NSTextCheckingDocumentURLKey: &'static NSTextCheckingOptionKey;
42}
43
44extern "C" {
45 pub static NSTextCheckingDocumentTitleKey: &'static NSTextCheckingOptionKey;
47}
48
49extern "C" {
50 pub static NSTextCheckingDocumentAuthorKey: &'static NSTextCheckingOptionKey;
52}
53
54extern "C" {
55 pub static NSTextCheckingRegularExpressionsKey: &'static NSTextCheckingOptionKey;
57}
58
59extern "C" {
60 pub static NSTextCheckingSelectedRangeKey: &'static NSTextCheckingOptionKey;
62}
63
64extern "C" {
65 pub static NSTextCheckingGenerateInlinePredictionsKey: &'static NSTextCheckingOptionKey;
67}
68
69#[repr(transparent)]
72#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
73pub struct NSCorrectionResponse(pub NSInteger);
74impl NSCorrectionResponse {
75 #[doc(alias = "NSCorrectionResponseNone")]
76 pub const None: Self = Self(0);
77 #[doc(alias = "NSCorrectionResponseAccepted")]
78 pub const Accepted: Self = Self(1);
79 #[doc(alias = "NSCorrectionResponseRejected")]
80 pub const Rejected: Self = Self(2);
81 #[doc(alias = "NSCorrectionResponseIgnored")]
82 pub const Ignored: Self = Self(3);
83 #[doc(alias = "NSCorrectionResponseEdited")]
84 pub const Edited: Self = Self(4);
85 #[doc(alias = "NSCorrectionResponseReverted")]
86 pub const Reverted: Self = Self(5);
87}
88
89unsafe impl Encode for NSCorrectionResponse {
90 const ENCODING: Encoding = NSInteger::ENCODING;
91}
92
93unsafe impl RefEncode for NSCorrectionResponse {
94 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
95}
96
97#[repr(transparent)]
100#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
101pub struct NSCorrectionIndicatorType(pub NSInteger);
102impl NSCorrectionIndicatorType {
103 #[doc(alias = "NSCorrectionIndicatorTypeDefault")]
104 pub const Default: Self = Self(0);
105 #[doc(alias = "NSCorrectionIndicatorTypeReversion")]
106 pub const Reversion: Self = Self(1);
107 #[doc(alias = "NSCorrectionIndicatorTypeGuesses")]
108 pub const Guesses: Self = Self(2);
109}
110
111unsafe impl Encode for NSCorrectionIndicatorType {
112 const ENCODING: Encoding = NSInteger::ENCODING;
113}
114
115unsafe impl RefEncode for NSCorrectionIndicatorType {
116 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
117}
118
119extern_class!(
120 #[unsafe(super(NSObject))]
122 #[derive(Debug, PartialEq, Eq, Hash)]
123 pub struct NSSpellChecker;
124);
125
126extern_conformance!(
127 unsafe impl NSObjectProtocol for NSSpellChecker {}
128);
129
130impl NSSpellChecker {
131 extern_methods!(
132 #[unsafe(method(sharedSpellChecker))]
133 #[unsafe(method_family = none)]
134 pub fn sharedSpellChecker() -> Retained<NSSpellChecker>;
135
136 #[unsafe(method(sharedSpellCheckerExists))]
137 #[unsafe(method_family = none)]
138 pub fn sharedSpellCheckerExists() -> bool;
139
140 #[unsafe(method(uniqueSpellDocumentTag))]
141 #[unsafe(method_family = none)]
142 pub fn uniqueSpellDocumentTag() -> NSInteger;
143
144 #[unsafe(method(checkSpellingOfString:startingAt:language:wrap:inSpellDocumentWithTag:wordCount:))]
148 #[unsafe(method_family = none)]
149 pub unsafe fn checkSpellingOfString_startingAt_language_wrap_inSpellDocumentWithTag_wordCount(
150 &self,
151 string_to_check: &NSString,
152 starting_offset: NSInteger,
153 language: Option<&NSString>,
154 wrap_flag: bool,
155 tag: NSInteger,
156 word_count: *mut NSInteger,
157 ) -> NSRange;
158
159 #[unsafe(method(checkSpellingOfString:startingAt:))]
160 #[unsafe(method_family = none)]
161 pub fn checkSpellingOfString_startingAt(
162 &self,
163 string_to_check: &NSString,
164 starting_offset: NSInteger,
165 ) -> NSRange;
166
167 #[unsafe(method(countWordsInString:language:))]
168 #[unsafe(method_family = none)]
169 pub fn countWordsInString_language(
170 &self,
171 string_to_count: &NSString,
172 language: Option<&NSString>,
173 ) -> NSInteger;
174
175 #[unsafe(method(checkGrammarOfString:startingAt:language:wrap:inSpellDocumentWithTag:details:))]
179 #[unsafe(method_family = none)]
180 pub unsafe fn checkGrammarOfString_startingAt_language_wrap_inSpellDocumentWithTag_details(
181 &self,
182 string_to_check: &NSString,
183 starting_offset: NSInteger,
184 language: Option<&NSString>,
185 wrap_flag: bool,
186 tag: NSInteger,
187 details: Option<&mut Option<Retained<NSArray<NSDictionary<NSString, AnyObject>>>>>,
188 ) -> NSRange;
189
190 #[unsafe(method(checkString:range:types:options:inSpellDocumentWithTag:orthography:wordCount:))]
195 #[unsafe(method_family = none)]
196 pub unsafe fn checkString_range_types_options_inSpellDocumentWithTag_orthography_wordCount(
197 &self,
198 string_to_check: &NSString,
199 range: NSRange,
200 checking_types: NSTextCheckingTypes,
201 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
202 tag: NSInteger,
203 orthography: Option<&mut Option<Retained<NSOrthography>>>,
204 word_count: *mut NSInteger,
205 ) -> Retained<NSArray<NSTextCheckingResult>>;
206
207 #[cfg(feature = "block2")]
208 #[unsafe(method(requestCheckingOfString:range:types:options:inSpellDocumentWithTag:completionHandler:))]
212 #[unsafe(method_family = none)]
213 pub unsafe fn requestCheckingOfString_range_types_options_inSpellDocumentWithTag_completionHandler(
214 &self,
215 string_to_check: &NSString,
216 range: NSRange,
217 checking_types: NSTextCheckingTypes,
218 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
219 tag: NSInteger,
220 completion_handler: Option<
221 &block2::DynBlock<
222 dyn Fn(
223 NSInteger,
224 NonNull<NSArray<NSTextCheckingResult>>,
225 NonNull<NSOrthography>,
226 NSInteger,
227 ),
228 >,
229 >,
230 ) -> NSInteger;
231
232 #[cfg(feature = "block2")]
233 #[unsafe(method(requestCandidatesForSelectedRange:inString:types:options:inSpellDocumentWithTag:completionHandler:))]
237 #[unsafe(method_family = none)]
238 pub unsafe fn requestCandidatesForSelectedRange_inString_types_options_inSpellDocumentWithTag_completionHandler(
239 &self,
240 selected_range: NSRange,
241 string_to_check: &NSString,
242 checking_types: NSTextCheckingTypes,
243 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
244 tag: NSInteger,
245 completion_handler: Option<
246 &block2::DynBlock<dyn Fn(NSInteger, NonNull<NSArray<NSTextCheckingResult>>)>,
247 >,
248 ) -> NSInteger;
249
250 #[cfg(all(feature = "NSMenu", feature = "NSResponder", feature = "NSView"))]
251 #[unsafe(method(menuForResult:string:options:atLocation:inView:))]
255 #[unsafe(method_family = none)]
256 pub unsafe fn menuForResult_string_options_atLocation_inView(
257 &self,
258 result: &NSTextCheckingResult,
259 checked_string: &NSString,
260 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
261 location: NSPoint,
262 view: &NSView,
263 ) -> Option<Retained<NSMenu>>;
264
265 #[unsafe(method(userQuotesArrayForLanguage:))]
266 #[unsafe(method_family = none)]
267 pub fn userQuotesArrayForLanguage(
268 &self,
269 language: &NSString,
270 ) -> Retained<NSArray<NSString>>;
271
272 #[unsafe(method(userReplacementsDictionary))]
273 #[unsafe(method_family = none)]
274 pub fn userReplacementsDictionary(&self) -> Retained<NSDictionary<NSString, NSString>>;
275
276 #[unsafe(method(updateSpellingPanelWithMisspelledWord:))]
277 #[unsafe(method_family = none)]
278 pub fn updateSpellingPanelWithMisspelledWord(&self, word: &NSString);
279
280 #[unsafe(method(updateSpellingPanelWithGrammarString:detail:))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn updateSpellingPanelWithGrammarString_detail(
286 &self,
287 string: &NSString,
288 detail: &NSDictionary<NSString, AnyObject>,
289 );
290
291 #[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
292 #[unsafe(method(spellingPanel))]
293 #[unsafe(method_family = none)]
294 pub fn spellingPanel(&self, mtm: MainThreadMarker) -> Retained<NSPanel>;
295
296 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
297 #[unsafe(method(accessoryView))]
298 #[unsafe(method_family = none)]
299 pub fn accessoryView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
300
301 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
302 #[unsafe(method(setAccessoryView:))]
304 #[unsafe(method_family = none)]
305 pub fn setAccessoryView(&self, accessory_view: Option<&NSView>);
306
307 #[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
308 #[unsafe(method(substitutionsPanel))]
309 #[unsafe(method_family = none)]
310 pub fn substitutionsPanel(&self, mtm: MainThreadMarker) -> Retained<NSPanel>;
311
312 #[cfg(all(feature = "NSResponder", feature = "NSViewController"))]
313 #[unsafe(method(substitutionsPanelAccessoryViewController))]
314 #[unsafe(method_family = none)]
315 pub fn substitutionsPanelAccessoryViewController(
316 &self,
317 mtm: MainThreadMarker,
318 ) -> Option<Retained<NSViewController>>;
319
320 #[cfg(all(feature = "NSResponder", feature = "NSViewController"))]
321 #[unsafe(method(setSubstitutionsPanelAccessoryViewController:))]
323 #[unsafe(method_family = none)]
324 pub fn setSubstitutionsPanelAccessoryViewController(
325 &self,
326 substitutions_panel_accessory_view_controller: Option<&NSViewController>,
327 );
328
329 #[unsafe(method(updatePanels))]
330 #[unsafe(method_family = none)]
331 pub fn updatePanels(&self);
332
333 #[unsafe(method(ignoreWord:inSpellDocumentWithTag:))]
334 #[unsafe(method_family = none)]
335 pub fn ignoreWord_inSpellDocumentWithTag(&self, word_to_ignore: &NSString, tag: NSInteger);
336
337 #[unsafe(method(ignoredWordsInSpellDocumentWithTag:))]
338 #[unsafe(method_family = none)]
339 pub fn ignoredWordsInSpellDocumentWithTag(
340 &self,
341 tag: NSInteger,
342 ) -> Option<Retained<NSArray<NSString>>>;
343
344 #[unsafe(method(setIgnoredWords:inSpellDocumentWithTag:))]
345 #[unsafe(method_family = none)]
346 pub fn setIgnoredWords_inSpellDocumentWithTag(
347 &self,
348 words: &NSArray<NSString>,
349 tag: NSInteger,
350 );
351
352 #[unsafe(method(guessesForWordRange:inString:language:inSpellDocumentWithTag:))]
353 #[unsafe(method_family = none)]
354 pub fn guessesForWordRange_inString_language_inSpellDocumentWithTag(
355 &self,
356 range: NSRange,
357 string: &NSString,
358 language: Option<&NSString>,
359 tag: NSInteger,
360 ) -> Option<Retained<NSArray<NSString>>>;
361
362 #[unsafe(method(correctionForWordRange:inString:language:inSpellDocumentWithTag:))]
363 #[unsafe(method_family = none)]
364 pub fn correctionForWordRange_inString_language_inSpellDocumentWithTag(
365 &self,
366 range: NSRange,
367 string: &NSString,
368 language: &NSString,
369 tag: NSInteger,
370 ) -> Option<Retained<NSString>>;
371
372 #[unsafe(method(completionsForPartialWordRange:inString:language:inSpellDocumentWithTag:))]
373 #[unsafe(method_family = none)]
374 pub fn completionsForPartialWordRange_inString_language_inSpellDocumentWithTag(
375 &self,
376 range: NSRange,
377 string: &NSString,
378 language: Option<&NSString>,
379 tag: NSInteger,
380 ) -> Option<Retained<NSArray<NSString>>>;
381
382 #[unsafe(method(languageForWordRange:inString:orthography:))]
383 #[unsafe(method_family = none)]
384 pub fn languageForWordRange_inString_orthography(
385 &self,
386 range: NSRange,
387 string: &NSString,
388 orthography: Option<&NSOrthography>,
389 ) -> Option<Retained<NSString>>;
390
391 #[unsafe(method(closeSpellDocumentWithTag:))]
392 #[unsafe(method_family = none)]
393 pub fn closeSpellDocumentWithTag(&self, tag: NSInteger);
394
395 #[unsafe(method(recordResponse:toCorrection:forWord:language:inSpellDocumentWithTag:))]
396 #[unsafe(method_family = none)]
397 pub fn recordResponse_toCorrection_forWord_language_inSpellDocumentWithTag(
398 &self,
399 response: NSCorrectionResponse,
400 correction: &NSString,
401 word: &NSString,
402 language: Option<&NSString>,
403 tag: NSInteger,
404 );
405
406 #[cfg(all(feature = "NSResponder", feature = "NSView", feature = "block2"))]
407 #[unsafe(method(showCorrectionIndicatorOfType:primaryString:alternativeStrings:forStringInRect:view:completionHandler:))]
408 #[unsafe(method_family = none)]
409 pub fn showCorrectionIndicatorOfType_primaryString_alternativeStrings_forStringInRect_view_completionHandler(
410 &self,
411 r#type: NSCorrectionIndicatorType,
412 primary_string: &NSString,
413 alternative_strings: &NSArray<NSString>,
414 rect_of_typed_string: NSRect,
415 view: &NSView,
416 completion_block: Option<&block2::DynBlock<dyn Fn(*mut NSString)>>,
417 );
418
419 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
420 #[unsafe(method(dismissCorrectionIndicatorForView:))]
421 #[unsafe(method_family = none)]
422 pub fn dismissCorrectionIndicatorForView(&self, view: &NSView);
423
424 #[cfg(feature = "NSTextInputClient")]
425 #[unsafe(method(showInlinePredictionForCandidates:client:))]
426 #[unsafe(method_family = none)]
427 pub fn showInlinePredictionForCandidates_client(
428 &self,
429 candidates: &NSArray<NSTextCheckingResult>,
430 client: &ProtocolObject<dyn NSTextInputClient>,
431 );
432
433 #[unsafe(method(preventsAutocorrectionBeforeString:language:))]
434 #[unsafe(method_family = none)]
435 pub fn preventsAutocorrectionBeforeString_language(
436 &self,
437 string: &NSString,
438 language: Option<&NSString>,
439 ) -> bool;
440
441 #[unsafe(method(deletesAutospaceBetweenString:andString:language:))]
442 #[unsafe(method_family = none)]
443 pub fn deletesAutospaceBetweenString_andString_language(
444 &self,
445 preceding_string: &NSString,
446 following_string: &NSString,
447 language: Option<&NSString>,
448 ) -> bool;
449
450 #[unsafe(method(availableLanguages))]
451 #[unsafe(method_family = none)]
452 pub fn availableLanguages(&self) -> Retained<NSArray<NSString>>;
453
454 #[unsafe(method(userPreferredLanguages))]
455 #[unsafe(method_family = none)]
456 pub fn userPreferredLanguages(&self) -> Retained<NSArray<NSString>>;
457
458 #[unsafe(method(automaticallyIdentifiesLanguages))]
459 #[unsafe(method_family = none)]
460 pub fn automaticallyIdentifiesLanguages(&self) -> bool;
461
462 #[unsafe(method(setAutomaticallyIdentifiesLanguages:))]
464 #[unsafe(method_family = none)]
465 pub fn setAutomaticallyIdentifiesLanguages(&self, automatically_identifies_languages: bool);
466
467 #[unsafe(method(setWordFieldStringValue:))]
468 #[unsafe(method_family = none)]
469 pub fn setWordFieldStringValue(&self, string: &NSString);
470
471 #[unsafe(method(learnWord:))]
472 #[unsafe(method_family = none)]
473 pub fn learnWord(&self, word: &NSString);
474
475 #[unsafe(method(hasLearnedWord:))]
476 #[unsafe(method_family = none)]
477 pub fn hasLearnedWord(&self, word: &NSString) -> bool;
478
479 #[unsafe(method(unlearnWord:))]
480 #[unsafe(method_family = none)]
481 pub fn unlearnWord(&self, word: &NSString);
482
483 #[unsafe(method(isAutomaticTextReplacementEnabled))]
484 #[unsafe(method_family = none)]
485 pub fn isAutomaticTextReplacementEnabled() -> bool;
486
487 #[unsafe(method(isAutomaticSpellingCorrectionEnabled))]
488 #[unsafe(method_family = none)]
489 pub fn isAutomaticSpellingCorrectionEnabled() -> bool;
490
491 #[unsafe(method(isAutomaticQuoteSubstitutionEnabled))]
492 #[unsafe(method_family = none)]
493 pub fn isAutomaticQuoteSubstitutionEnabled() -> bool;
494
495 #[unsafe(method(isAutomaticDashSubstitutionEnabled))]
496 #[unsafe(method_family = none)]
497 pub fn isAutomaticDashSubstitutionEnabled() -> bool;
498
499 #[unsafe(method(isAutomaticCapitalizationEnabled))]
500 #[unsafe(method_family = none)]
501 pub fn isAutomaticCapitalizationEnabled() -> bool;
502
503 #[unsafe(method(isAutomaticPeriodSubstitutionEnabled))]
504 #[unsafe(method_family = none)]
505 pub fn isAutomaticPeriodSubstitutionEnabled() -> bool;
506
507 #[unsafe(method(isAutomaticTextCompletionEnabled))]
508 #[unsafe(method_family = none)]
509 pub fn isAutomaticTextCompletionEnabled() -> bool;
510
511 #[unsafe(method(isAutomaticInlinePredictionEnabled))]
512 #[unsafe(method_family = none)]
513 pub fn isAutomaticInlinePredictionEnabled() -> bool;
514
515 #[unsafe(method(language))]
516 #[unsafe(method_family = none)]
517 pub fn language(&self) -> Retained<NSString>;
518
519 #[unsafe(method(setLanguage:))]
520 #[unsafe(method_family = none)]
521 pub fn setLanguage(&self, language: &NSString) -> bool;
522 );
523}
524
525impl NSSpellChecker {
527 extern_methods!(
528 #[unsafe(method(init))]
529 #[unsafe(method_family = init)]
530 pub fn init(this: Allocated<Self>) -> Retained<Self>;
531
532 #[unsafe(method(new))]
533 #[unsafe(method_family = new)]
534 pub fn new() -> Retained<Self>;
535 );
536}
537
538impl DefaultRetained for NSSpellChecker {
539 #[inline]
540 fn default_retained() -> Retained<Self> {
541 Self::new()
542 }
543}
544
545extern "C" {
546 pub static NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification:
548 &'static NSNotificationName;
549}
550
551extern "C" {
552 pub static NSSpellCheckerDidChangeAutomaticTextReplacementNotification:
554 &'static NSNotificationName;
555}
556
557extern "C" {
558 pub static NSSpellCheckerDidChangeAutomaticQuoteSubstitutionNotification:
560 &'static NSNotificationName;
561}
562
563extern "C" {
564 pub static NSSpellCheckerDidChangeAutomaticDashSubstitutionNotification:
566 &'static NSNotificationName;
567}
568
569extern "C" {
570 pub static NSSpellCheckerDidChangeAutomaticCapitalizationNotification:
572 &'static NSNotificationName;
573}
574
575extern "C" {
576 pub static NSSpellCheckerDidChangeAutomaticPeriodSubstitutionNotification:
578 &'static NSNotificationName;
579}
580
581extern "C" {
582 pub static NSSpellCheckerDidChangeAutomaticTextCompletionNotification:
584 &'static NSNotificationName;
585}
586
587extern "C" {
588 pub static NSSpellCheckerDidChangeAutomaticInlinePredictionNotification:
590 &'static NSNotificationName;
591}
592
593impl NSSpellChecker {
595 extern_methods!(
596 #[deprecated = "Use -guessesForWordRange:inString:language:inSpellDocumentWithTag instead"]
600 #[unsafe(method(guessesForWord:))]
601 #[unsafe(method_family = none)]
602 pub unsafe fn guessesForWord(&self, word: Option<&NSString>) -> Option<Retained<NSArray>>;
603
604 #[deprecated]
608 #[unsafe(method(forgetWord:))]
609 #[unsafe(method_family = none)]
610 pub unsafe fn forgetWord(&self, word: Option<&NSString>);
611 );
612}