rust_macios/appkit/
ns_nib.rs1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4 foundation::{NSArray, NSBundle, NSData, NSDictionary, NSString, NSURL},
5 object,
6 objective_c_runtime::{
7 id, nil,
8 traits::{FromId, PNSObject},
9 },
10 utils::to_bool,
11};
12
13use super::interface_impl;
14
15pub type NSNibName = NSString;
16
17object! {
18 unsafe pub struct NSNib;
20}
21
22#[interface_impl(NSObject)]
23impl NSNib {
24 #[deprecated = "use [`init_with_nib_data_bundle`] instead."]
29 #[method]
30 pub fn init_with_contents_of_url(&mut self, nib_file_url: NSURL) -> id {
31 unsafe { msg_send![self.m_self(), initWithContentsOfURL: nib_file_url] }
32 }
33
34 #[method]
36 pub fn init_with_nib_named_bundle(&mut self, nib_name: NSNibName, bundle: &NSBundle) -> Self
37 where
38 Self: Sized + FromId,
39 {
40 unsafe {
41 Self::from_id(
42 msg_send![self.m_self(), initWithNibNamed: nib_name bundle: bundle.m_self()],
43 )
44 }
45 }
46
47 #[method]
49 pub fn init_with_nib_data_bundle(&mut self, nib_data: &NSData, bundle: &NSBundle) -> Self
50 where
51 Self: Sized + FromId,
52 {
53 unsafe {
54 Self::from_id(
55 msg_send![self.m_self(), initWithNibData: nib_data.m_self() bundle: bundle.m_self()],
56 )
57 }
58 }
59
60 #[deprecated = "use [`instantiate_with_owner_top_level_objects`] instead."]
65 #[method]
66 pub fn instantiate_nib_with_owner_top_level_objects<T>(
67 &mut self,
68 owner: id,
69 top_lvl_objects: &NSArray<T>,
70 ) -> bool {
71 unsafe {
72 to_bool(
73 msg_send![self.m_self(), instantiateNibWithOwner: owner topLevelObjects: top_lvl_objects.m_self()],
74 )
75 }
76 }
77
78 #[deprecated = "use [`instantiate_with_owner_top_level_objects`] instead."]
80 #[method]
81 pub fn instantiate_nib_with_external_name_table<K, V>(
82 &self,
83 external_name_table: &NSDictionary<K, V>,
84 ) -> bool {
85 unsafe {
86 to_bool(
87 msg_send![self.m_self(), instantiateNibWithExternalNameTable: external_name_table.m_self()],
88 )
89 }
90 }
91
92 #[method]
94 pub fn instantiate_with_owner_top_level_objects<T>(
95 &self,
96 owner: id,
97 top_lvl_objects: Option<NSArray<T>>,
98 ) {
99 unsafe {
100 let top_lvl_objects = match top_lvl_objects {
101 Some(value) => value.m_self(),
102 None => nil,
103 };
104
105 msg_send![self.m_self(), instantiateWithOwner: owner topLevelObjects: top_lvl_objects]
106 }
107 }
108}
109
110extern "C" {
111 #[deprecated]
116 pub static NSNibOwner: NSString;
117
118 #[deprecated]
120 pub static NSNibTopLevelObjects: NSString;
121}