rust_macios/foundation/
ns_orthography.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    object,
5    objective_c_runtime::{
6        macros::interface_impl,
7        traits::{FromId, PNSObject},
8    },
9};
10
11use super::{NSArray, NSCoder, NSDictionary, NSString};
12
13object! {
14    /// A description of the linguistic content of natural language text, typically used for spelling and grammar checking.
15    unsafe pub struct NSOrthography;
16}
17
18#[interface_impl(NSObject)]
19impl NSOrthography {
20    /* Creating Orthography Objects
21     */
22
23    /// Creates and returns an orthography object with the default language map for the specified language.
24    #[method]
25    pub fn default_orthography_for_language(language: NSString) -> Self
26    where
27        Self: Sized + FromId,
28    {
29        unsafe {
30            Self::from_id(msg_send![
31                Self::m_class(),
32                defaultOrthographyForLanguage: language
33            ])
34        }
35    }
36
37    /// Creates an orthography object with the specified dominant script and language map.
38    #[method]
39    pub fn init_with_dominant_script_language_map(
40        &mut self,
41        script: NSString,
42        map: NSDictionary<NSString, NSArray<NSString>>,
43    ) -> Self
44    where
45        Self: Sized + FromId,
46    {
47        unsafe {
48            Self::from_id(msg_send![self.m_self(), initWithDominantScript: script languageMap: map])
49        }
50    }
51
52    /// Creates and returns an orthography object with the specified dominant script and language map.
53    #[method]
54    pub fn orthography_with_dominant_script(
55        script: NSString,
56        map: NSDictionary<NSString, NSArray<NSString>>,
57    ) -> Self
58    where
59        Self: Sized + FromId,
60    {
61        unsafe {
62            Self::from_id(
63                msg_send![Self::m_class(), orthographyWithDominantScript: script languageMap: map],
64            )
65        }
66    }
67
68    /* Determining Correspondences Between Languages and Scripts
69     */
70
71    /// A dictionary that maps script tags to arrays of language tags.
72    #[property]
73    pub fn language_map(&self) -> NSDictionary<NSString, NSArray<NSString>> {
74        unsafe { NSDictionary::from_id(msg_send![self.m_self(), languageMap]) }
75    }
76
77    /// The first language in the list of languages for the dominant script.
78    #[property]
79    pub fn dominant_language(&self) -> NSString {
80        unsafe { NSString::from_id(msg_send![self.m_self(), dominantLanguage]) }
81    }
82
83    /// The dominant script for the text.
84    #[property]
85    pub fn dominant_script(&self) -> NSString {
86        unsafe { NSString::from_id(msg_send![self.m_self(), dominantScript]) }
87    }
88
89    /// Returns the dominant language for the specified script.
90    #[method]
91    pub fn dominant_language_for_script(&self, script: NSString) -> NSString {
92        unsafe { NSString::from_id(msg_send![self.m_self(), dominantLanguageForScript: script]) }
93    }
94
95    /// Returns the list of languages for the specified script.
96    #[method]
97    pub fn languages_for_script(&self, script: NSString) -> NSArray<NSString> {
98        unsafe { NSArray::from_id(msg_send![self.m_self(), languagesForScript: script]) }
99    }
100
101    /// The scripts appearing as keys in the language map.
102    #[property]
103    pub fn all_scripts(&self) -> NSArray<NSString> {
104        unsafe { NSArray::from_id(msg_send![self.m_self(), allScripts]) }
105    }
106
107    /// The languages appearing in values of the language map.
108    #[property]
109    pub fn all_languages(&self) -> NSArray<NSString> {
110        unsafe { NSArray::from_id(msg_send![self.m_self(), allLanguages]) }
111    }
112
113    /// Initialize with [`NSCoder`]
114    #[method]
115    pub fn init_with_coder(&mut self, coder: NSCoder) -> Self
116    where
117        Self: Sized + FromId,
118    {
119        unsafe { Self::from_id(msg_send![self.m_self(), initWithCoder: coder]) }
120    }
121}
122
123impl Default for NSOrthography {
124    fn default() -> Self {
125        NSOrthography::m_new()
126    }
127}