use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
use crate::*;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AXValueType(pub u32);
impl AXValueType {
#[doc(alias = "kAXValueTypeCGPoint")]
pub const CGPoint: Self = Self(1);
#[doc(alias = "kAXValueTypeCGSize")]
pub const CGSize: Self = Self(2);
#[doc(alias = "kAXValueTypeCGRect")]
pub const CGRect: Self = Self(3);
#[doc(alias = "kAXValueTypeCFRange")]
pub const CFRange: Self = Self(4);
#[doc(alias = "kAXValueTypeAXError")]
pub const AXError: Self = Self(5);
#[doc(alias = "kAXValueTypeIllegal")]
pub const Illegal: Self = Self(0);
}
#[cfg(feature = "objc2")]
unsafe impl Encode for AXValueType {
const ENCODING: Encoding = u32::ENCODING;
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for AXValueType {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
pub static kAXValueCGPointType: u32 = AXValueType::CGPoint.0;
pub static kAXValueCGSizeType: u32 = AXValueType::CGSize.0;
pub static kAXValueCGRectType: u32 = AXValueType::CGRect.0;
pub static kAXValueCFRangeType: u32 = AXValueType::CFRange.0;
pub static kAXValueAXErrorType: u32 = AXValueType::AXError.0;
pub static kAXValueIllegalType: u32 = AXValueType::Illegal.0;
#[doc(alias = "AXValueRef")]
#[repr(C)]
pub struct AXValue {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl AXValue {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__AXValue"> for AXValue {}
);
unsafe impl ConcreteType for AXValue {
#[doc(alias = "AXValueGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn AXValueGetTypeID() -> CFTypeID;
}
unsafe { AXValueGetTypeID() }
}
}
impl AXValue {
#[doc(alias = "AXValueCreate")]
#[inline]
pub unsafe fn new(
the_type: AXValueType,
value_ptr: NonNull<c_void>,
) -> Option<CFRetained<AXValue>> {
extern "C-unwind" {
fn AXValueCreate(
the_type: AXValueType,
value_ptr: NonNull<c_void>,
) -> Option<NonNull<AXValue>>;
}
let ret = unsafe { AXValueCreate(the_type, value_ptr) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "AXValueGetType")]
#[inline]
pub unsafe fn r#type(&self) -> AXValueType {
extern "C-unwind" {
fn AXValueGetType(value: &AXValue) -> AXValueType;
}
unsafe { AXValueGetType(self) }
}
#[doc(alias = "AXValueGetValue")]
#[inline]
pub unsafe fn value(&self, the_type: AXValueType, value_ptr: NonNull<c_void>) -> bool {
extern "C-unwind" {
fn AXValueGetValue(
value: &AXValue,
the_type: AXValueType,
value_ptr: NonNull<c_void>,
) -> Boolean;
}
let ret = unsafe { AXValueGetValue(self, the_type, value_ptr) };
ret != 0
}
}
#[deprecated = "renamed to `AXValue::new`"]
#[inline]
pub unsafe extern "C-unwind" fn AXValueCreate(
the_type: AXValueType,
value_ptr: NonNull<c_void>,
) -> Option<CFRetained<AXValue>> {
extern "C-unwind" {
fn AXValueCreate(
the_type: AXValueType,
value_ptr: NonNull<c_void>,
) -> Option<NonNull<AXValue>>;
}
let ret = unsafe { AXValueCreate(the_type, value_ptr) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
extern "C-unwind" {
#[deprecated = "renamed to `AXValue::type`"]
pub fn AXValueGetType(value: &AXValue) -> AXValueType;
}
#[deprecated = "renamed to `AXValue::value`"]
#[inline]
pub unsafe extern "C-unwind" fn AXValueGetValue(
value: &AXValue,
the_type: AXValueType,
value_ptr: NonNull<c_void>,
) -> bool {
extern "C-unwind" {
fn AXValueGetValue(
value: &AXValue,
the_type: AXValueType,
value_ptr: NonNull<c_void>,
) -> Boolean;
}
let ret = unsafe { AXValueGetValue(value, the_type, value_ptr) };
ret != 0
}