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