rust_macios/foundation/
ns_spell_server.rs1use std::sync::Once;
2
3use objc::{
4 class,
5 declare::ClassDecl,
6 msg_send,
7 runtime::{Class, Object},
8 sel, sel_impl,
9};
10
11use objc_id::Id;
12
13use crate::{
14 objective_c_runtime::{
15 self, id,
16 macros::interface_impl,
17 traits::{FromId, PNSObject, ToId},
18 },
19 utils::to_bool,
20};
21
22use super::NSString;
23
24pub static NSSPELLSERVER_PTR: &str = "rstNSSpellServerPtr";
25
26pub struct NSSpellServer {
28 ptr: Id<Object>,
29}
30
31impl PNSObject for NSSpellServer {
32 fn m_class<'a>() -> &'a Class {
33 static mut NSSPELL_SERVER_CLASS: *const Class = 0 as *const Class;
34 static INIT: Once = Once::new();
35
36 INIT.call_once(|| unsafe {
37 let superclass = class!(NSApplication);
38 let decl = ClassDecl::new("RSTNSSpellServer", superclass).unwrap();
39 NSSPELL_SERVER_CLASS = decl.register();
40 });
41
42 unsafe { &*NSSPELL_SERVER_CLASS }
43 }
44
45 fn m_self(&self) -> id {
46 unsafe { msg_send![self.ptr, self] }
47 }
48}
49
50impl core::fmt::Debug for NSSpellServer {
51 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
52 std::write!(f, "{}", self.p_debug_description())
53 }
54}
55
56impl core::fmt::Display for NSSpellServer {
57 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
58 std::write!(f, "{}", self.p_description())
59 }
60}
61
62impl ToId for NSSpellServer {
63 fn to_id(mut self) -> id {
64 &mut *self.ptr
65 }
66}
67
68impl FromId for NSSpellServer {
69 unsafe fn from_id(ptr: id) -> Self {
70 Self {
71 ptr: Id::from_ptr(ptr),
72 }
73 }
74}
75
76#[interface_impl(NSObject)]
77impl NSSpellServer {
78 #[property]
82 pub fn delegate(&self) -> id {
83 unsafe { msg_send![self.m_self(), delegate] }
84 }
85
86 #[method]
93 pub fn register_language_by_vendor(&mut self, language: &NSString, vendor: &NSString) {
94 unsafe {
95 msg_send![self.m_self(), registerLanguage: language.m_self() byVendor: vendor.m_self()]
96 }
97 }
98
99 #[method]
101 pub fn run(&mut self) {
102 unsafe { msg_send![self.m_self(), run] }
103 }
104
105 #[method]
110 pub fn is_word_in_user_dictionaries_case_sensitive(&self, word: &NSString, flag: bool) -> bool {
111 unsafe {
112 to_bool(
113 msg_send![self.m_self(), isWordInUserDictionaries: word.m_self() caseSensitive: flag],
114 )
115 }
116 }
117}
118
119unsafe impl objective_c_runtime::Encode for NSSpellServer {
120 fn encode() -> objc::Encoding {
121 unsafe { objective_c_runtime::Encoding::from_str("@") }
122 }
123}
124
125extern "C" {
126 pub static NSGrammarRange: NSString;
131
132 pub static NSGrammarUserDescription: NSString;
134
135 pub static NSGrammarCorrections: NSString;
137}