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 unsafe fn sharedSpellChecker() -> Retained<NSSpellChecker>;
135
136 #[unsafe(method(sharedSpellCheckerExists))]
137 #[unsafe(method_family = none)]
138 pub unsafe fn sharedSpellCheckerExists() -> bool;
139
140 #[unsafe(method(uniqueSpellDocumentTag))]
141 #[unsafe(method_family = none)]
142 pub unsafe fn uniqueSpellDocumentTag() -> NSInteger;
143
144 #[unsafe(method(checkSpellingOfString:startingAt:language:wrap:inSpellDocumentWithTag:wordCount:))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn checkSpellingOfString_startingAt_language_wrap_inSpellDocumentWithTag_wordCount(
147 &self,
148 string_to_check: &NSString,
149 starting_offset: NSInteger,
150 language: Option<&NSString>,
151 wrap_flag: bool,
152 tag: NSInteger,
153 word_count: *mut NSInteger,
154 ) -> NSRange;
155
156 #[unsafe(method(checkSpellingOfString:startingAt:))]
157 #[unsafe(method_family = none)]
158 pub unsafe fn checkSpellingOfString_startingAt(
159 &self,
160 string_to_check: &NSString,
161 starting_offset: NSInteger,
162 ) -> NSRange;
163
164 #[unsafe(method(countWordsInString:language:))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn countWordsInString_language(
167 &self,
168 string_to_count: &NSString,
169 language: Option<&NSString>,
170 ) -> NSInteger;
171
172 #[unsafe(method(checkGrammarOfString:startingAt:language:wrap:inSpellDocumentWithTag:details:))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn checkGrammarOfString_startingAt_language_wrap_inSpellDocumentWithTag_details(
175 &self,
176 string_to_check: &NSString,
177 starting_offset: NSInteger,
178 language: Option<&NSString>,
179 wrap_flag: bool,
180 tag: NSInteger,
181 details: Option<&mut Option<Retained<NSArray<NSDictionary<NSString, AnyObject>>>>>,
182 ) -> NSRange;
183
184 #[unsafe(method(checkString:range:types:options:inSpellDocumentWithTag:orthography:wordCount:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn checkString_range_types_options_inSpellDocumentWithTag_orthography_wordCount(
187 &self,
188 string_to_check: &NSString,
189 range: NSRange,
190 checking_types: NSTextCheckingTypes,
191 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
192 tag: NSInteger,
193 orthography: Option<&mut Option<Retained<NSOrthography>>>,
194 word_count: *mut NSInteger,
195 ) -> Retained<NSArray<NSTextCheckingResult>>;
196
197 #[cfg(feature = "block2")]
198 #[unsafe(method(requestCheckingOfString:range:types:options:inSpellDocumentWithTag:completionHandler:))]
199 #[unsafe(method_family = none)]
200 pub unsafe fn requestCheckingOfString_range_types_options_inSpellDocumentWithTag_completionHandler(
201 &self,
202 string_to_check: &NSString,
203 range: NSRange,
204 checking_types: NSTextCheckingTypes,
205 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
206 tag: NSInteger,
207 completion_handler: Option<
208 &block2::DynBlock<
209 dyn Fn(
210 NSInteger,
211 NonNull<NSArray<NSTextCheckingResult>>,
212 NonNull<NSOrthography>,
213 NSInteger,
214 ),
215 >,
216 >,
217 ) -> NSInteger;
218
219 #[cfg(feature = "block2")]
220 #[unsafe(method(requestCandidatesForSelectedRange:inString:types:options:inSpellDocumentWithTag:completionHandler:))]
221 #[unsafe(method_family = none)]
222 pub unsafe fn requestCandidatesForSelectedRange_inString_types_options_inSpellDocumentWithTag_completionHandler(
223 &self,
224 selected_range: NSRange,
225 string_to_check: &NSString,
226 checking_types: NSTextCheckingTypes,
227 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
228 tag: NSInteger,
229 completion_handler: Option<
230 &block2::DynBlock<dyn Fn(NSInteger, NonNull<NSArray<NSTextCheckingResult>>)>,
231 >,
232 ) -> NSInteger;
233
234 #[cfg(all(feature = "NSMenu", feature = "NSResponder", feature = "NSView"))]
235 #[unsafe(method(menuForResult:string:options:atLocation:inView:))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn menuForResult_string_options_atLocation_inView(
238 &self,
239 result: &NSTextCheckingResult,
240 checked_string: &NSString,
241 options: Option<&NSDictionary<NSTextCheckingOptionKey, AnyObject>>,
242 location: NSPoint,
243 view: &NSView,
244 ) -> Option<Retained<NSMenu>>;
245
246 #[unsafe(method(userQuotesArrayForLanguage:))]
247 #[unsafe(method_family = none)]
248 pub unsafe fn userQuotesArrayForLanguage(
249 &self,
250 language: &NSString,
251 ) -> Retained<NSArray<NSString>>;
252
253 #[unsafe(method(userReplacementsDictionary))]
254 #[unsafe(method_family = none)]
255 pub unsafe fn userReplacementsDictionary(
256 &self,
257 ) -> Retained<NSDictionary<NSString, NSString>>;
258
259 #[unsafe(method(updateSpellingPanelWithMisspelledWord:))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn updateSpellingPanelWithMisspelledWord(&self, word: &NSString);
262
263 #[unsafe(method(updateSpellingPanelWithGrammarString:detail:))]
264 #[unsafe(method_family = none)]
265 pub unsafe fn updateSpellingPanelWithGrammarString_detail(
266 &self,
267 string: &NSString,
268 detail: &NSDictionary<NSString, AnyObject>,
269 );
270
271 #[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
272 #[unsafe(method(spellingPanel))]
273 #[unsafe(method_family = none)]
274 pub unsafe fn spellingPanel(&self, mtm: MainThreadMarker) -> Retained<NSPanel>;
275
276 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
277 #[unsafe(method(accessoryView))]
278 #[unsafe(method_family = none)]
279 pub unsafe fn accessoryView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
280
281 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
282 #[unsafe(method(setAccessoryView:))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn setAccessoryView(&self, accessory_view: Option<&NSView>);
286
287 #[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
288 #[unsafe(method(substitutionsPanel))]
289 #[unsafe(method_family = none)]
290 pub unsafe fn substitutionsPanel(&self, mtm: MainThreadMarker) -> Retained<NSPanel>;
291
292 #[cfg(all(feature = "NSResponder", feature = "NSViewController"))]
293 #[unsafe(method(substitutionsPanelAccessoryViewController))]
294 #[unsafe(method_family = none)]
295 pub unsafe fn substitutionsPanelAccessoryViewController(
296 &self,
297 mtm: MainThreadMarker,
298 ) -> Option<Retained<NSViewController>>;
299
300 #[cfg(all(feature = "NSResponder", feature = "NSViewController"))]
301 #[unsafe(method(setSubstitutionsPanelAccessoryViewController:))]
303 #[unsafe(method_family = none)]
304 pub unsafe fn setSubstitutionsPanelAccessoryViewController(
305 &self,
306 substitutions_panel_accessory_view_controller: Option<&NSViewController>,
307 );
308
309 #[unsafe(method(updatePanels))]
310 #[unsafe(method_family = none)]
311 pub unsafe fn updatePanels(&self);
312
313 #[unsafe(method(ignoreWord:inSpellDocumentWithTag:))]
314 #[unsafe(method_family = none)]
315 pub unsafe fn ignoreWord_inSpellDocumentWithTag(
316 &self,
317 word_to_ignore: &NSString,
318 tag: NSInteger,
319 );
320
321 #[unsafe(method(ignoredWordsInSpellDocumentWithTag:))]
322 #[unsafe(method_family = none)]
323 pub unsafe fn ignoredWordsInSpellDocumentWithTag(
324 &self,
325 tag: NSInteger,
326 ) -> Option<Retained<NSArray<NSString>>>;
327
328 #[unsafe(method(setIgnoredWords:inSpellDocumentWithTag:))]
329 #[unsafe(method_family = none)]
330 pub unsafe fn setIgnoredWords_inSpellDocumentWithTag(
331 &self,
332 words: &NSArray<NSString>,
333 tag: NSInteger,
334 );
335
336 #[unsafe(method(guessesForWordRange:inString:language:inSpellDocumentWithTag:))]
337 #[unsafe(method_family = none)]
338 pub unsafe fn guessesForWordRange_inString_language_inSpellDocumentWithTag(
339 &self,
340 range: NSRange,
341 string: &NSString,
342 language: Option<&NSString>,
343 tag: NSInteger,
344 ) -> Option<Retained<NSArray<NSString>>>;
345
346 #[unsafe(method(correctionForWordRange:inString:language:inSpellDocumentWithTag:))]
347 #[unsafe(method_family = none)]
348 pub unsafe fn correctionForWordRange_inString_language_inSpellDocumentWithTag(
349 &self,
350 range: NSRange,
351 string: &NSString,
352 language: &NSString,
353 tag: NSInteger,
354 ) -> Option<Retained<NSString>>;
355
356 #[unsafe(method(completionsForPartialWordRange:inString:language:inSpellDocumentWithTag:))]
357 #[unsafe(method_family = none)]
358 pub unsafe fn completionsForPartialWordRange_inString_language_inSpellDocumentWithTag(
359 &self,
360 range: NSRange,
361 string: &NSString,
362 language: Option<&NSString>,
363 tag: NSInteger,
364 ) -> Option<Retained<NSArray<NSString>>>;
365
366 #[unsafe(method(languageForWordRange:inString:orthography:))]
367 #[unsafe(method_family = none)]
368 pub unsafe fn languageForWordRange_inString_orthography(
369 &self,
370 range: NSRange,
371 string: &NSString,
372 orthography: Option<&NSOrthography>,
373 ) -> Option<Retained<NSString>>;
374
375 #[unsafe(method(closeSpellDocumentWithTag:))]
376 #[unsafe(method_family = none)]
377 pub unsafe fn closeSpellDocumentWithTag(&self, tag: NSInteger);
378
379 #[unsafe(method(recordResponse:toCorrection:forWord:language:inSpellDocumentWithTag:))]
380 #[unsafe(method_family = none)]
381 pub unsafe fn recordResponse_toCorrection_forWord_language_inSpellDocumentWithTag(
382 &self,
383 response: NSCorrectionResponse,
384 correction: &NSString,
385 word: &NSString,
386 language: Option<&NSString>,
387 tag: NSInteger,
388 );
389
390 #[cfg(all(feature = "NSResponder", feature = "NSView", feature = "block2"))]
391 #[unsafe(method(showCorrectionIndicatorOfType:primaryString:alternativeStrings:forStringInRect:view:completionHandler:))]
392 #[unsafe(method_family = none)]
393 pub unsafe fn showCorrectionIndicatorOfType_primaryString_alternativeStrings_forStringInRect_view_completionHandler(
394 &self,
395 r#type: NSCorrectionIndicatorType,
396 primary_string: &NSString,
397 alternative_strings: &NSArray<NSString>,
398 rect_of_typed_string: NSRect,
399 view: &NSView,
400 completion_block: Option<&block2::DynBlock<dyn Fn(*mut NSString)>>,
401 );
402
403 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
404 #[unsafe(method(dismissCorrectionIndicatorForView:))]
405 #[unsafe(method_family = none)]
406 pub unsafe fn dismissCorrectionIndicatorForView(&self, view: &NSView);
407
408 #[cfg(feature = "NSTextInputClient")]
409 #[unsafe(method(showInlinePredictionForCandidates:client:))]
410 #[unsafe(method_family = none)]
411 pub unsafe fn showInlinePredictionForCandidates_client(
412 &self,
413 candidates: &NSArray<NSTextCheckingResult>,
414 client: &ProtocolObject<dyn NSTextInputClient>,
415 );
416
417 #[unsafe(method(preventsAutocorrectionBeforeString:language:))]
418 #[unsafe(method_family = none)]
419 pub unsafe fn preventsAutocorrectionBeforeString_language(
420 &self,
421 string: &NSString,
422 language: Option<&NSString>,
423 ) -> bool;
424
425 #[unsafe(method(deletesAutospaceBetweenString:andString:language:))]
426 #[unsafe(method_family = none)]
427 pub unsafe fn deletesAutospaceBetweenString_andString_language(
428 &self,
429 preceding_string: &NSString,
430 following_string: &NSString,
431 language: Option<&NSString>,
432 ) -> bool;
433
434 #[unsafe(method(availableLanguages))]
435 #[unsafe(method_family = none)]
436 pub unsafe fn availableLanguages(&self) -> Retained<NSArray<NSString>>;
437
438 #[unsafe(method(userPreferredLanguages))]
439 #[unsafe(method_family = none)]
440 pub unsafe fn userPreferredLanguages(&self) -> Retained<NSArray<NSString>>;
441
442 #[unsafe(method(automaticallyIdentifiesLanguages))]
443 #[unsafe(method_family = none)]
444 pub unsafe fn automaticallyIdentifiesLanguages(&self) -> bool;
445
446 #[unsafe(method(setAutomaticallyIdentifiesLanguages:))]
448 #[unsafe(method_family = none)]
449 pub unsafe fn setAutomaticallyIdentifiesLanguages(
450 &self,
451 automatically_identifies_languages: bool,
452 );
453
454 #[unsafe(method(setWordFieldStringValue:))]
455 #[unsafe(method_family = none)]
456 pub unsafe fn setWordFieldStringValue(&self, string: &NSString);
457
458 #[unsafe(method(learnWord:))]
459 #[unsafe(method_family = none)]
460 pub unsafe fn learnWord(&self, word: &NSString);
461
462 #[unsafe(method(hasLearnedWord:))]
463 #[unsafe(method_family = none)]
464 pub unsafe fn hasLearnedWord(&self, word: &NSString) -> bool;
465
466 #[unsafe(method(unlearnWord:))]
467 #[unsafe(method_family = none)]
468 pub unsafe fn unlearnWord(&self, word: &NSString);
469
470 #[unsafe(method(isAutomaticTextReplacementEnabled))]
471 #[unsafe(method_family = none)]
472 pub unsafe fn isAutomaticTextReplacementEnabled() -> bool;
473
474 #[unsafe(method(isAutomaticSpellingCorrectionEnabled))]
475 #[unsafe(method_family = none)]
476 pub unsafe fn isAutomaticSpellingCorrectionEnabled() -> bool;
477
478 #[unsafe(method(isAutomaticQuoteSubstitutionEnabled))]
479 #[unsafe(method_family = none)]
480 pub unsafe fn isAutomaticQuoteSubstitutionEnabled() -> bool;
481
482 #[unsafe(method(isAutomaticDashSubstitutionEnabled))]
483 #[unsafe(method_family = none)]
484 pub unsafe fn isAutomaticDashSubstitutionEnabled() -> bool;
485
486 #[unsafe(method(isAutomaticCapitalizationEnabled))]
487 #[unsafe(method_family = none)]
488 pub unsafe fn isAutomaticCapitalizationEnabled() -> bool;
489
490 #[unsafe(method(isAutomaticPeriodSubstitutionEnabled))]
491 #[unsafe(method_family = none)]
492 pub unsafe fn isAutomaticPeriodSubstitutionEnabled() -> bool;
493
494 #[unsafe(method(isAutomaticTextCompletionEnabled))]
495 #[unsafe(method_family = none)]
496 pub unsafe fn isAutomaticTextCompletionEnabled() -> bool;
497
498 #[unsafe(method(isAutomaticInlinePredictionEnabled))]
499 #[unsafe(method_family = none)]
500 pub unsafe fn isAutomaticInlinePredictionEnabled() -> bool;
501
502 #[unsafe(method(language))]
503 #[unsafe(method_family = none)]
504 pub unsafe fn language(&self) -> Retained<NSString>;
505
506 #[unsafe(method(setLanguage:))]
507 #[unsafe(method_family = none)]
508 pub unsafe fn setLanguage(&self, language: &NSString) -> bool;
509 );
510}
511
512impl NSSpellChecker {
514 extern_methods!(
515 #[unsafe(method(init))]
516 #[unsafe(method_family = init)]
517 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
518
519 #[unsafe(method(new))]
520 #[unsafe(method_family = new)]
521 pub unsafe fn new() -> Retained<Self>;
522 );
523}
524
525extern "C" {
526 pub static NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification:
528 &'static NSNotificationName;
529}
530
531extern "C" {
532 pub static NSSpellCheckerDidChangeAutomaticTextReplacementNotification:
534 &'static NSNotificationName;
535}
536
537extern "C" {
538 pub static NSSpellCheckerDidChangeAutomaticQuoteSubstitutionNotification:
540 &'static NSNotificationName;
541}
542
543extern "C" {
544 pub static NSSpellCheckerDidChangeAutomaticDashSubstitutionNotification:
546 &'static NSNotificationName;
547}
548
549extern "C" {
550 pub static NSSpellCheckerDidChangeAutomaticCapitalizationNotification:
552 &'static NSNotificationName;
553}
554
555extern "C" {
556 pub static NSSpellCheckerDidChangeAutomaticPeriodSubstitutionNotification:
558 &'static NSNotificationName;
559}
560
561extern "C" {
562 pub static NSSpellCheckerDidChangeAutomaticTextCompletionNotification:
564 &'static NSNotificationName;
565}
566
567extern "C" {
568 pub static NSSpellCheckerDidChangeAutomaticInlinePredictionNotification:
570 &'static NSNotificationName;
571}
572
573impl NSSpellChecker {
575 extern_methods!(
576 #[deprecated = "Use -guessesForWordRange:inString:language:inSpellDocumentWithTag instead"]
577 #[unsafe(method(guessesForWord:))]
578 #[unsafe(method_family = none)]
579 pub unsafe fn guessesForWord(&self, word: Option<&NSString>) -> Option<Retained<NSArray>>;
580
581 #[deprecated]
582 #[unsafe(method(forgetWord:))]
583 #[unsafe(method_family = none)]
584 pub unsafe fn forgetWord(&self, word: Option<&NSString>);
585 );
586}