1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct NSFontTraitMask(pub NSUInteger);
17bitflags::bitflags! {
18 impl NSFontTraitMask: NSUInteger {
19 #[doc(alias = "NSItalicFontMask")]
20 const ItalicFontMask = 0x00000001;
21 #[doc(alias = "NSBoldFontMask")]
22 const BoldFontMask = 0x00000002;
23 #[doc(alias = "NSUnboldFontMask")]
24 const UnboldFontMask = 0x00000004;
25 #[doc(alias = "NSNonStandardCharacterSetFontMask")]
26 const NonStandardCharacterSetFontMask = 0x00000008;
27 #[doc(alias = "NSNarrowFontMask")]
28 const NarrowFontMask = 0x00000010;
29 #[doc(alias = "NSExpandedFontMask")]
30 const ExpandedFontMask = 0x00000020;
31 #[doc(alias = "NSCondensedFontMask")]
32 const CondensedFontMask = 0x00000040;
33 #[doc(alias = "NSSmallCapsFontMask")]
34 const SmallCapsFontMask = 0x00000080;
35 #[doc(alias = "NSPosterFontMask")]
36 const PosterFontMask = 0x00000100;
37 #[doc(alias = "NSCompressedFontMask")]
38 const CompressedFontMask = 0x00000200;
39 #[doc(alias = "NSFixedPitchFontMask")]
40 const FixedPitchFontMask = 0x00000400;
41 #[doc(alias = "NSUnitalicFontMask")]
42 const UnitalicFontMask = 0x01000000;
43 }
44}
45
46unsafe impl Encode for NSFontTraitMask {
47 const ENCODING: Encoding = NSUInteger::ENCODING;
48}
49
50unsafe impl RefEncode for NSFontTraitMask {
51 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
52}
53
54#[repr(transparent)]
57#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
58pub struct NSFontCollectionOptions(pub NSUInteger);
59bitflags::bitflags! {
60 impl NSFontCollectionOptions: NSUInteger {
61 #[doc(alias = "NSFontCollectionApplicationOnlyMask")]
62 const ApplicationOnlyMask = 1<<0;
63 }
64}
65
66unsafe impl Encode for NSFontCollectionOptions {
67 const ENCODING: Encoding = NSUInteger::ENCODING;
68}
69
70unsafe impl RefEncode for NSFontCollectionOptions {
71 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
72}
73
74#[repr(transparent)]
77#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
78pub struct NSFontAction(pub NSUInteger);
79impl NSFontAction {
80 #[doc(alias = "NSNoFontChangeAction")]
81 pub const NoFontChangeAction: Self = Self(0);
82 #[doc(alias = "NSViaPanelFontAction")]
83 pub const ViaPanelFontAction: Self = Self(1);
84 #[doc(alias = "NSAddTraitFontAction")]
85 pub const AddTraitFontAction: Self = Self(2);
86 #[doc(alias = "NSSizeUpFontAction")]
87 pub const SizeUpFontAction: Self = Self(3);
88 #[doc(alias = "NSSizeDownFontAction")]
89 pub const SizeDownFontAction: Self = Self(4);
90 #[doc(alias = "NSHeavierFontAction")]
91 pub const HeavierFontAction: Self = Self(5);
92 #[doc(alias = "NSLighterFontAction")]
93 pub const LighterFontAction: Self = Self(6);
94 #[doc(alias = "NSRemoveTraitFontAction")]
95 pub const RemoveTraitFontAction: Self = Self(7);
96}
97
98unsafe impl Encode for NSFontAction {
99 const ENCODING: Encoding = NSUInteger::ENCODING;
100}
101
102unsafe impl RefEncode for NSFontAction {
103 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
104}
105
106extern_class!(
107 #[unsafe(super(NSObject))]
109 #[thread_kind = MainThreadOnly]
110 #[derive(Debug, PartialEq, Eq, Hash)]
111 pub struct NSFontManager;
112);
113
114#[cfg(feature = "NSMenu")]
115extern_conformance!(
116 unsafe impl NSMenuItemValidation for NSFontManager {}
117);
118
119extern_conformance!(
120 unsafe impl NSObjectProtocol for NSFontManager {}
121);
122
123impl NSFontManager {
124 extern_methods!(
125 #[unsafe(method(setFontPanelFactory:))]
129 #[unsafe(method_family = none)]
130 pub unsafe fn setFontPanelFactory(factory_id: Option<&AnyClass>, mtm: MainThreadMarker);
131
132 #[unsafe(method(setFontManagerFactory:))]
136 #[unsafe(method_family = none)]
137 pub unsafe fn setFontManagerFactory(factory_id: Option<&AnyClass>, mtm: MainThreadMarker);
138
139 #[unsafe(method(sharedFontManager))]
140 #[unsafe(method_family = none)]
141 pub fn sharedFontManager(mtm: MainThreadMarker) -> Retained<NSFontManager>;
142
143 #[unsafe(method(isMultiple))]
144 #[unsafe(method_family = none)]
145 pub fn isMultiple(&self) -> bool;
146
147 #[cfg(feature = "NSFont")]
148 #[unsafe(method(selectedFont))]
149 #[unsafe(method_family = none)]
150 pub fn selectedFont(&self) -> Option<Retained<NSFont>>;
151
152 #[cfg(feature = "NSFont")]
153 #[unsafe(method(setSelectedFont:isMultiple:))]
154 #[unsafe(method_family = none)]
155 pub fn setSelectedFont_isMultiple(&self, font_obj: &NSFont, flag: bool);
156
157 #[cfg(feature = "NSMenu")]
158 #[unsafe(method(setFontMenu:))]
159 #[unsafe(method_family = none)]
160 pub fn setFontMenu(&self, new_menu: &NSMenu);
161
162 #[cfg(feature = "NSMenu")]
163 #[unsafe(method(fontMenu:))]
164 #[unsafe(method_family = none)]
165 pub fn fontMenu(&self, create: bool) -> Option<Retained<NSMenu>>;
166
167 #[cfg(all(
168 feature = "NSFontPanel",
169 feature = "NSPanel",
170 feature = "NSResponder",
171 feature = "NSWindow"
172 ))]
173 #[unsafe(method(fontPanel:))]
174 #[unsafe(method_family = none)]
175 pub fn fontPanel(&self, create: bool) -> Option<Retained<NSFontPanel>>;
176
177 #[cfg(all(feature = "NSFont", feature = "objc2-core-foundation"))]
178 #[unsafe(method(fontWithFamily:traits:weight:size:))]
179 #[unsafe(method_family = none)]
180 pub fn fontWithFamily_traits_weight_size(
181 &self,
182 family: &NSString,
183 traits: NSFontTraitMask,
184 weight: NSInteger,
185 size: CGFloat,
186 ) -> Option<Retained<NSFont>>;
187
188 #[cfg(feature = "NSFont")]
189 #[unsafe(method(traitsOfFont:))]
190 #[unsafe(method_family = none)]
191 pub fn traitsOfFont(&self, font_obj: &NSFont) -> NSFontTraitMask;
192
193 #[cfg(feature = "NSFont")]
194 #[unsafe(method(weightOfFont:))]
195 #[unsafe(method_family = none)]
196 pub fn weightOfFont(&self, font_obj: &NSFont) -> NSInteger;
197
198 #[unsafe(method(availableFonts))]
199 #[unsafe(method_family = none)]
200 pub fn availableFonts(&self) -> Retained<NSArray<NSString>>;
201
202 #[unsafe(method(availableFontFamilies))]
203 #[unsafe(method_family = none)]
204 pub fn availableFontFamilies(&self) -> Retained<NSArray<NSString>>;
205
206 #[unsafe(method(availableMembersOfFontFamily:))]
207 #[unsafe(method_family = none)]
208 pub fn availableMembersOfFontFamily(
209 &self,
210 fam: &NSString,
211 ) -> Option<Retained<NSArray<NSArray>>>;
212
213 #[cfg(feature = "NSFont")]
214 #[unsafe(method(convertFont:))]
215 #[unsafe(method_family = none)]
216 pub fn convertFont(&self, font_obj: &NSFont) -> Retained<NSFont>;
217
218 #[cfg(all(feature = "NSFont", feature = "objc2-core-foundation"))]
219 #[unsafe(method(convertFont:toSize:))]
220 #[unsafe(method_family = none)]
221 pub fn convertFont_toSize(&self, font_obj: &NSFont, size: CGFloat) -> Retained<NSFont>;
222
223 #[cfg(feature = "NSFont")]
224 #[unsafe(method(convertFont:toFace:))]
225 #[unsafe(method_family = none)]
226 pub fn convertFont_toFace(
227 &self,
228 font_obj: &NSFont,
229 typeface: &NSString,
230 ) -> Option<Retained<NSFont>>;
231
232 #[cfg(feature = "NSFont")]
233 #[unsafe(method(convertFont:toFamily:))]
234 #[unsafe(method_family = none)]
235 pub fn convertFont_toFamily(
236 &self,
237 font_obj: &NSFont,
238 family: &NSString,
239 ) -> Retained<NSFont>;
240
241 #[cfg(feature = "NSFont")]
242 #[unsafe(method(convertFont:toHaveTrait:))]
243 #[unsafe(method_family = none)]
244 pub fn convertFont_toHaveTrait(
245 &self,
246 font_obj: &NSFont,
247 r#trait: NSFontTraitMask,
248 ) -> Retained<NSFont>;
249
250 #[cfg(feature = "NSFont")]
251 #[unsafe(method(convertFont:toNotHaveTrait:))]
252 #[unsafe(method_family = none)]
253 pub fn convertFont_toNotHaveTrait(
254 &self,
255 font_obj: &NSFont,
256 r#trait: NSFontTraitMask,
257 ) -> Retained<NSFont>;
258
259 #[cfg(feature = "NSFont")]
260 #[unsafe(method(convertWeight:ofFont:))]
261 #[unsafe(method_family = none)]
262 pub fn convertWeight_ofFont(&self, up_flag: bool, font_obj: &NSFont) -> Retained<NSFont>;
263
264 #[unsafe(method(isEnabled))]
265 #[unsafe(method_family = none)]
266 pub fn isEnabled(&self) -> bool;
267
268 #[unsafe(method(setEnabled:))]
270 #[unsafe(method_family = none)]
271 pub fn setEnabled(&self, enabled: bool);
272
273 #[unsafe(method(action))]
274 #[unsafe(method_family = none)]
275 pub fn action(&self) -> Sel;
276
277 #[unsafe(method(setAction:))]
283 #[unsafe(method_family = none)]
284 pub unsafe fn setAction(&self, action: Sel);
285
286 #[deprecated = "NSFontManager doesn't have any delegate method. This property should not be used."]
290 #[unsafe(method(delegate))]
291 #[unsafe(method_family = none)]
292 pub unsafe fn delegate(&self) -> Option<Retained<AnyObject>>;
293
294 #[deprecated = "NSFontManager doesn't have any delegate method. This property should not be used."]
301 #[unsafe(method(setDelegate:))]
302 #[unsafe(method_family = none)]
303 pub unsafe fn setDelegate(&self, delegate: Option<&AnyObject>);
304
305 #[unsafe(method(sendAction))]
306 #[unsafe(method_family = none)]
307 pub fn sendAction(&self) -> bool;
308
309 #[unsafe(method(localizedNameForFamily:face:))]
310 #[unsafe(method_family = none)]
311 pub fn localizedNameForFamily_face(
312 &self,
313 family: &NSString,
314 face_key: Option<&NSString>,
315 ) -> Retained<NSString>;
316
317 #[unsafe(method(setSelectedAttributes:isMultiple:))]
321 #[unsafe(method_family = none)]
322 pub unsafe fn setSelectedAttributes_isMultiple(
323 &self,
324 attributes: &NSDictionary<NSString, AnyObject>,
325 flag: bool,
326 );
327
328 #[unsafe(method(convertAttributes:))]
332 #[unsafe(method_family = none)]
333 pub unsafe fn convertAttributes(
334 &self,
335 attributes: &NSDictionary<NSString, AnyObject>,
336 ) -> Retained<NSDictionary<NSString, AnyObject>>;
337
338 #[cfg(feature = "NSFontDescriptor")]
339 #[deprecated = "Use -[NSFontDescriptor matchingFontDescriptorsWithMandatoryKeys:] instead"]
340 #[unsafe(method(availableFontNamesMatchingFontDescriptor:))]
341 #[unsafe(method_family = none)]
342 pub fn availableFontNamesMatchingFontDescriptor(
343 &self,
344 descriptor: &NSFontDescriptor,
345 ) -> Option<Retained<NSArray>>;
346
347 #[deprecated = "Use +[NSFontCollection allFontCollectionNames] instead"]
348 #[unsafe(method(collectionNames))]
349 #[unsafe(method_family = none)]
350 pub fn collectionNames(&self) -> Retained<NSArray>;
351
352 #[deprecated = "Use -[NSFontCollection matchingDescriptors] instead"]
353 #[unsafe(method(fontDescriptorsInCollection:))]
354 #[unsafe(method_family = none)]
355 pub fn fontDescriptorsInCollection(
356 &self,
357 collection_names: &NSString,
358 ) -> Option<Retained<NSArray>>;
359
360 #[deprecated = "Use +[NSFontCollection showFontCollection:withName:visibility:name:] instead"]
361 #[unsafe(method(addCollection:options:))]
362 #[unsafe(method_family = none)]
363 pub fn addCollection_options(
364 &self,
365 collection_name: &NSString,
366 collection_options: NSFontCollectionOptions,
367 ) -> bool;
368
369 #[deprecated = "Use +[NSFontCollection hideFontCollectionWithName:visibility:error:] instead"]
370 #[unsafe(method(removeCollection:))]
371 #[unsafe(method_family = none)]
372 pub fn removeCollection(&self, collection_name: &NSString) -> bool;
373
374 #[deprecated = "Use -[NSMutableFontCollection addQueryForDescriptors:] instead"]
378 #[unsafe(method(addFontDescriptors:toCollection:))]
379 #[unsafe(method_family = none)]
380 pub unsafe fn addFontDescriptors_toCollection(
381 &self,
382 descriptors: &NSArray,
383 collection_name: &NSString,
384 );
385
386 #[cfg(feature = "NSFontDescriptor")]
387 #[deprecated = "Use -[NSMutableFontCollection removeQueryForDescriptors:] instead"]
388 #[unsafe(method(removeFontDescriptor:fromCollection:))]
389 #[unsafe(method_family = none)]
390 pub fn removeFontDescriptor_fromCollection(
391 &self,
392 descriptor: &NSFontDescriptor,
393 collection: &NSString,
394 );
395
396 #[unsafe(method(currentFontAction))]
397 #[unsafe(method_family = none)]
398 pub fn currentFontAction(&self) -> NSFontAction;
399
400 #[unsafe(method(convertFontTraits:))]
401 #[unsafe(method_family = none)]
402 pub fn convertFontTraits(&self, traits: NSFontTraitMask) -> NSFontTraitMask;
403
404 #[unsafe(method(target))]
405 #[unsafe(method_family = none)]
406 pub fn target(&self) -> Option<Retained<AnyObject>>;
407
408 #[unsafe(method(setTarget:))]
416 #[unsafe(method_family = none)]
417 pub unsafe fn setTarget(&self, target: Option<&AnyObject>);
418 );
419}
420
421impl NSFontManager {
423 extern_methods!(
424 #[unsafe(method(init))]
425 #[unsafe(method_family = init)]
426 pub fn init(this: Allocated<Self>) -> Retained<Self>;
427
428 #[unsafe(method(new))]
429 #[unsafe(method_family = new)]
430 pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
431 );
432}
433
434impl NSFontManager {
436 extern_methods!(
437 #[unsafe(method(fontNamed:hasTraits:))]
438 #[unsafe(method_family = none)]
439 pub fn fontNamed_hasTraits(&self, f_name: &NSString, some_traits: NSFontTraitMask) -> bool;
440
441 #[unsafe(method(availableFontNamesWithTraits:))]
442 #[unsafe(method_family = none)]
443 pub fn availableFontNamesWithTraits(
444 &self,
445 some_traits: NSFontTraitMask,
446 ) -> Option<Retained<NSArray<NSString>>>;
447
448 #[unsafe(method(addFontTrait:))]
452 #[unsafe(method_family = none)]
453 pub unsafe fn addFontTrait(&self, sender: Option<&AnyObject>);
454
455 #[unsafe(method(removeFontTrait:))]
459 #[unsafe(method_family = none)]
460 pub unsafe fn removeFontTrait(&self, sender: Option<&AnyObject>);
461
462 #[unsafe(method(modifyFontViaPanel:))]
466 #[unsafe(method_family = none)]
467 pub unsafe fn modifyFontViaPanel(&self, sender: Option<&AnyObject>);
468
469 #[unsafe(method(modifyFont:))]
473 #[unsafe(method_family = none)]
474 pub unsafe fn modifyFont(&self, sender: Option<&AnyObject>);
475
476 #[unsafe(method(orderFrontFontPanel:))]
480 #[unsafe(method_family = none)]
481 pub unsafe fn orderFrontFontPanel(&self, sender: Option<&AnyObject>);
482
483 #[unsafe(method(orderFrontStylesPanel:))]
487 #[unsafe(method_family = none)]
488 pub unsafe fn orderFrontStylesPanel(&self, sender: Option<&AnyObject>);
489 );
490}