1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSFontTraitMask(pub NSUInteger);
impl NSFontTraitMask {
    pub const NSItalicFontMask: Self = Self(0x00000001);
    pub const NSBoldFontMask: Self = Self(0x00000002);
    pub const NSUnboldFontMask: Self = Self(0x00000004);
    pub const NSNonStandardCharacterSetFontMask: Self = Self(0x00000008);
    pub const NSNarrowFontMask: Self = Self(0x00000010);
    pub const NSExpandedFontMask: Self = Self(0x00000020);
    pub const NSCondensedFontMask: Self = Self(0x00000040);
    pub const NSSmallCapsFontMask: Self = Self(0x00000080);
    pub const NSPosterFontMask: Self = Self(0x00000100);
    pub const NSCompressedFontMask: Self = Self(0x00000200);
    pub const NSFixedPitchFontMask: Self = Self(0x00000400);
    pub const NSUnitalicFontMask: Self = Self(0x01000000);
}

unsafe impl Encode for NSFontTraitMask {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSFontTraitMask {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSFontCollectionOptions(pub NSUInteger);
impl NSFontCollectionOptions {
    pub const NSFontCollectionApplicationOnlyMask: Self = Self(1 << 0);
}

unsafe impl Encode for NSFontCollectionOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSFontCollectionOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSFontAction(pub NSUInteger);
impl NSFontAction {
    pub const NSNoFontChangeAction: Self = Self(0);
    pub const NSViaPanelFontAction: Self = Self(1);
    pub const NSAddTraitFontAction: Self = Self(2);
    pub const NSSizeUpFontAction: Self = Self(3);
    pub const NSSizeDownFontAction: Self = Self(4);
    pub const NSHeavierFontAction: Self = Self(5);
    pub const NSLighterFontAction: Self = Self(6);
    pub const NSRemoveTraitFontAction: Self = Self(7);
}

unsafe impl Encode for NSFontAction {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSFontAction {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSFontManager;

    unsafe impl ClassType for NSFontManager {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

#[cfg(feature = "NSMenu")]
unsafe impl NSMenuItemValidation for NSFontManager {}

unsafe impl NSObjectProtocol for NSFontManager {}

extern_methods!(
    unsafe impl NSFontManager {
        #[method(setFontPanelFactory:)]
        pub unsafe fn setFontPanelFactory(factory_id: Option<&AnyClass>, mtm: MainThreadMarker);

        #[method(setFontManagerFactory:)]
        pub unsafe fn setFontManagerFactory(factory_id: Option<&AnyClass>, mtm: MainThreadMarker);

        #[method_id(@__retain_semantics Other sharedFontManager)]
        pub unsafe fn sharedFontManager(mtm: MainThreadMarker) -> Id<NSFontManager>;

        #[method(isMultiple)]
        pub unsafe fn isMultiple(&self) -> bool;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other selectedFont)]
        pub unsafe fn selectedFont(&self) -> Option<Id<NSFont>>;

        #[cfg(feature = "NSFont")]
        #[method(setSelectedFont:isMultiple:)]
        pub unsafe fn setSelectedFont_isMultiple(&self, font_obj: &NSFont, flag: bool);

        #[cfg(feature = "NSMenu")]
        #[method(setFontMenu:)]
        pub unsafe fn setFontMenu(&self, new_menu: &NSMenu);

        #[cfg(feature = "NSMenu")]
        #[method_id(@__retain_semantics Other fontMenu:)]
        pub unsafe fn fontMenu(&self, create: bool) -> Option<Id<NSMenu>>;

        #[cfg(all(
            feature = "NSFontPanel",
            feature = "NSPanel",
            feature = "NSResponder",
            feature = "NSWindow"
        ))]
        #[method_id(@__retain_semantics Other fontPanel:)]
        pub unsafe fn fontPanel(&self, create: bool) -> Option<Id<NSFontPanel>>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other fontWithFamily:traits:weight:size:)]
        pub unsafe fn fontWithFamily_traits_weight_size(
            &self,
            family: &NSString,
            traits: NSFontTraitMask,
            weight: NSInteger,
            size: CGFloat,
        ) -> Option<Id<NSFont>>;

        #[cfg(feature = "NSFont")]
        #[method(traitsOfFont:)]
        pub unsafe fn traitsOfFont(&self, font_obj: &NSFont) -> NSFontTraitMask;

        #[cfg(feature = "NSFont")]
        #[method(weightOfFont:)]
        pub unsafe fn weightOfFont(&self, font_obj: &NSFont) -> NSInteger;

        #[method_id(@__retain_semantics Other availableFonts)]
        pub unsafe fn availableFonts(&self) -> Id<NSArray<NSString>>;

        #[method_id(@__retain_semantics Other availableFontFamilies)]
        pub unsafe fn availableFontFamilies(&self) -> Id<NSArray<NSString>>;

        #[method_id(@__retain_semantics Other availableMembersOfFontFamily:)]
        pub unsafe fn availableMembersOfFontFamily(
            &self,
            fam: &NSString,
        ) -> Option<Id<NSArray<NSArray>>>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other convertFont:)]
        pub unsafe fn convertFont(&self, font_obj: &NSFont) -> Id<NSFont>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other convertFont:toSize:)]
        pub unsafe fn convertFont_toSize(&self, font_obj: &NSFont, size: CGFloat) -> Id<NSFont>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other convertFont:toFace:)]
        pub unsafe fn convertFont_toFace(
            &self,
            font_obj: &NSFont,
            typeface: &NSString,
        ) -> Option<Id<NSFont>>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other convertFont:toFamily:)]
        pub unsafe fn convertFont_toFamily(
            &self,
            font_obj: &NSFont,
            family: &NSString,
        ) -> Id<NSFont>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other convertFont:toHaveTrait:)]
        pub unsafe fn convertFont_toHaveTrait(
            &self,
            font_obj: &NSFont,
            r#trait: NSFontTraitMask,
        ) -> Id<NSFont>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other convertFont:toNotHaveTrait:)]
        pub unsafe fn convertFont_toNotHaveTrait(
            &self,
            font_obj: &NSFont,
            r#trait: NSFontTraitMask,
        ) -> Id<NSFont>;

        #[cfg(feature = "NSFont")]
        #[method_id(@__retain_semantics Other convertWeight:ofFont:)]
        pub unsafe fn convertWeight_ofFont(&self, up_flag: bool, font_obj: &NSFont) -> Id<NSFont>;

        #[method(isEnabled)]
        pub unsafe fn isEnabled(&self) -> bool;

        #[method(setEnabled:)]
        pub unsafe fn setEnabled(&self, enabled: bool);

        #[method(action)]
        pub unsafe fn action(&self) -> Sel;

        #[method(setAction:)]
        pub unsafe fn setAction(&self, action: Sel);

        #[deprecated = "NSFontManager doesn't have any delegate method. This property should not be used."]
        #[method_id(@__retain_semantics Other delegate)]
        pub unsafe fn delegate(&self) -> Option<Id<AnyObject>>;

        #[deprecated = "NSFontManager doesn't have any delegate method. This property should not be used."]
        #[method(setDelegate:)]
        pub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>);

        #[method(sendAction)]
        pub unsafe fn sendAction(&self) -> bool;

        #[method_id(@__retain_semantics Other localizedNameForFamily:face:)]
        pub unsafe fn localizedNameForFamily_face(
            &self,
            family: &NSString,
            face_key: Option<&NSString>,
        ) -> Id<NSString>;

        #[method(setSelectedAttributes:isMultiple:)]
        pub unsafe fn setSelectedAttributes_isMultiple(
            &self,
            attributes: &NSDictionary<NSString, AnyObject>,
            flag: bool,
        );

        #[method_id(@__retain_semantics Other convertAttributes:)]
        pub unsafe fn convertAttributes(
            &self,
            attributes: &NSDictionary<NSString, AnyObject>,
        ) -> Id<NSDictionary<NSString, AnyObject>>;

        #[cfg(feature = "NSFontDescriptor")]
        #[deprecated = "Use -[NSFontDescriptor matchingFontDescriptorsWithMandatoryKeys:] instead"]
        #[method_id(@__retain_semantics Other availableFontNamesMatchingFontDescriptor:)]
        pub unsafe fn availableFontNamesMatchingFontDescriptor(
            &self,
            descriptor: &NSFontDescriptor,
        ) -> Option<Id<NSArray>>;

        #[deprecated = "Use +[NSFontCollection allFontCollectionNames] instead"]
        #[method_id(@__retain_semantics Other collectionNames)]
        pub unsafe fn collectionNames(&self) -> Id<NSArray>;

        #[deprecated = "Use -[NSFontCollection matchingDescriptors] instead"]
        #[method_id(@__retain_semantics Other fontDescriptorsInCollection:)]
        pub unsafe fn fontDescriptorsInCollection(
            &self,
            collection_names: &NSString,
        ) -> Option<Id<NSArray>>;

        #[deprecated = "Use +[NSFontCollection showFontCollection:withName:visibility:name:] instead"]
        #[method(addCollection:options:)]
        pub unsafe fn addCollection_options(
            &self,
            collection_name: &NSString,
            collection_options: NSFontCollectionOptions,
        ) -> bool;

        #[deprecated = "Use +[NSFontCollection hideFontCollectionWithName:visibility:error:] instead"]
        #[method(removeCollection:)]
        pub unsafe fn removeCollection(&self, collection_name: &NSString) -> bool;

        #[deprecated = "Use -[NSMutableFontCollection addQueryForDescriptors:] instead"]
        #[method(addFontDescriptors:toCollection:)]
        pub unsafe fn addFontDescriptors_toCollection(
            &self,
            descriptors: &NSArray,
            collection_name: &NSString,
        );

        #[cfg(feature = "NSFontDescriptor")]
        #[deprecated = "Use -[NSMutableFontCollection removeQueryForDescriptors:] instead"]
        #[method(removeFontDescriptor:fromCollection:)]
        pub unsafe fn removeFontDescriptor_fromCollection(
            &self,
            descriptor: &NSFontDescriptor,
            collection: &NSString,
        );

        #[method(currentFontAction)]
        pub unsafe fn currentFontAction(&self) -> NSFontAction;

        #[method(convertFontTraits:)]
        pub unsafe fn convertFontTraits(&self, traits: NSFontTraitMask) -> NSFontTraitMask;

        #[method_id(@__retain_semantics Other target)]
        pub unsafe fn target(&self) -> Option<Id<AnyObject>>;

        #[method(setTarget:)]
        pub unsafe fn setTarget(&self, target: Option<&AnyObject>);
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl NSFontManager {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Id<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Id<Self>;
    }
);

extern_methods!(
    /// NSFontManagerMenuActionMethods
    unsafe impl NSFontManager {
        #[method(fontNamed:hasTraits:)]
        pub unsafe fn fontNamed_hasTraits(
            &self,
            f_name: &NSString,
            some_traits: NSFontTraitMask,
        ) -> bool;

        #[method_id(@__retain_semantics Other availableFontNamesWithTraits:)]
        pub unsafe fn availableFontNamesWithTraits(
            &self,
            some_traits: NSFontTraitMask,
        ) -> Option<Id<NSArray<NSString>>>;

        #[method(addFontTrait:)]
        pub unsafe fn addFontTrait(&self, sender: Option<&AnyObject>);

        #[method(removeFontTrait:)]
        pub unsafe fn removeFontTrait(&self, sender: Option<&AnyObject>);

        #[method(modifyFontViaPanel:)]
        pub unsafe fn modifyFontViaPanel(&self, sender: Option<&AnyObject>);

        #[method(modifyFont:)]
        pub unsafe fn modifyFont(&self, sender: Option<&AnyObject>);

        #[method(orderFrontFontPanel:)]
        pub unsafe fn orderFrontFontPanel(&self, sender: Option<&AnyObject>);

        #[method(orderFrontStylesPanel:)]
        pub unsafe fn orderFrontStylesPanel(&self, sender: Option<&AnyObject>);
    }
);