use objc::{msg_send, sel, sel_impl};
use crate::{
foundation::{NSArray, NSBundle, NSData, NSDictionary, NSString, NSURL},
object,
objective_c_runtime::{
id, nil,
traits::{FromId, PNSObject},
},
utils::to_bool,
};
use super::interface_impl;
pub type NSNibName = NSString;
object! {
unsafe pub struct NSNib;
}
#[interface_impl(NSObject)]
impl NSNib {
#[deprecated = "use [`init_with_nib_data_bundle`] instead."]
#[method]
pub fn init_with_contents_of_url(&mut self, nib_file_url: NSURL) -> id {
unsafe { msg_send![self.m_self(), initWithContentsOfURL: nib_file_url] }
}
#[method]
pub fn init_with_nib_named_bundle(&mut self, nib_name: NSNibName, bundle: &NSBundle) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(
msg_send![self.m_self(), initWithNibNamed: nib_name bundle: bundle.m_self()],
)
}
}
#[method]
pub fn init_with_nib_data_bundle(&mut self, nib_data: &NSData, bundle: &NSBundle) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(
msg_send![self.m_self(), initWithNibData: nib_data.m_self() bundle: bundle.m_self()],
)
}
}
#[deprecated = "use [`instantiate_with_owner_top_level_objects`] instead."]
#[method]
pub fn instantiate_nib_with_owner_top_level_objects<T>(
&mut self,
owner: id,
top_lvl_objects: &NSArray<T>,
) -> bool {
unsafe {
to_bool(
msg_send![self.m_self(), instantiateNibWithOwner: owner topLevelObjects: top_lvl_objects.m_self()],
)
}
}
#[deprecated = "use [`instantiate_with_owner_top_level_objects`] instead."]
#[method]
pub fn instantiate_nib_with_external_name_table<K, V>(
&self,
external_name_table: &NSDictionary<K, V>,
) -> bool {
unsafe {
to_bool(
msg_send![self.m_self(), instantiateNibWithExternalNameTable: external_name_table.m_self()],
)
}
}
#[method]
pub fn instantiate_with_owner_top_level_objects<T>(
&self,
owner: id,
top_lvl_objects: Option<NSArray<T>>,
) {
unsafe {
let top_lvl_objects = match top_lvl_objects {
Some(value) => value.m_self(),
None => nil,
};
msg_send![self.m_self(), instantiateWithOwner: owner topLevelObjects: top_lvl_objects]
}
}
}
extern "C" {
#[deprecated]
pub static NSNibOwner: NSString;
#[deprecated]
pub static NSNibTopLevelObjects: NSString;
}