objc2_application_services/generated/HIServices/
AXValue.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// These are AXValueType wrappers for other structures. You must use the AXValueCreate
14/// and AXValueGetValue functions to convert between the wrapped structure and the native structure.
15///
16/// See also [Apple's documentation](https://developer.apple.com/documentation/applicationservices/axvaluetype?language=objc)
17// NS_ENUM
18#[repr(transparent)]
19#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
20pub struct AXValueType(pub u32);
21impl AXValueType {
22    #[doc(alias = "kAXValueTypeCGPoint")]
23    pub const CGPoint: Self = Self(1);
24    #[doc(alias = "kAXValueTypeCGSize")]
25    pub const CGSize: Self = Self(2);
26    #[doc(alias = "kAXValueTypeCGRect")]
27    pub const CGRect: Self = Self(3);
28    #[doc(alias = "kAXValueTypeCFRange")]
29    pub const CFRange: Self = Self(4);
30    #[doc(alias = "kAXValueTypeAXError")]
31    pub const AXError: Self = Self(5);
32    #[doc(alias = "kAXValueTypeIllegal")]
33    pub const Illegal: Self = Self(0);
34}
35
36#[cfg(feature = "objc2")]
37unsafe impl Encode for AXValueType {
38    const ENCODING: Encoding = u32::ENCODING;
39}
40
41#[cfg(feature = "objc2")]
42unsafe impl RefEncode for AXValueType {
43    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
44}
45
46/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kaxvaluecgpointtype?language=objc)
47pub static kAXValueCGPointType: u32 = AXValueType::CGPoint.0;
48
49/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kaxvaluecgsizetype?language=objc)
50pub static kAXValueCGSizeType: u32 = AXValueType::CGSize.0;
51
52/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kaxvaluecgrecttype?language=objc)
53pub static kAXValueCGRectType: u32 = AXValueType::CGRect.0;
54
55/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kaxvaluecfrangetype?language=objc)
56pub static kAXValueCFRangeType: u32 = AXValueType::CFRange.0;
57
58/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kaxvalueaxerrortype?language=objc)
59pub static kAXValueAXErrorType: u32 = AXValueType::AXError.0;
60
61/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/kaxvalueillegaltype?language=objc)
62pub static kAXValueIllegalType: u32 = AXValueType::Illegal.0;
63
64/// [Apple's documentation](https://developer.apple.com/documentation/applicationservices/axvalue?language=objc)
65#[doc(alias = "AXValueRef")]
66#[repr(C)]
67pub struct AXValue {
68    inner: [u8; 0],
69    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
70}
71
72cf_type!(
73    unsafe impl AXValue {}
74);
75#[cfg(feature = "objc2")]
76cf_objc2_type!(
77    unsafe impl RefEncode<"__AXValue"> for AXValue {}
78);
79
80unsafe impl ConcreteType for AXValue {
81    /// Returns:
82    /// Availability: Mac OS X version 10.3 or later
83    #[doc(alias = "AXValueGetTypeID")]
84    #[inline]
85    fn type_id() -> CFTypeID {
86        extern "C-unwind" {
87            fn AXValueGetTypeID() -> CFTypeID;
88        }
89        unsafe { AXValueGetTypeID() }
90    }
91}
92
93impl AXValue {
94    /// Encodes a structure pointed to by valuePtr into a CFTypeRef.
95    ///
96    ///
97    /// Parameter `theType`:
98    /// Parameter `valuePtr`:
99    /// Returns:
100    ///
101    /// # Safety
102    ///
103    /// `value_ptr` must be a valid pointer.
104    #[doc(alias = "AXValueCreate")]
105    #[inline]
106    pub unsafe fn new(
107        the_type: AXValueType,
108        value_ptr: NonNull<c_void>,
109    ) -> Option<CFRetained<AXValue>> {
110        extern "C-unwind" {
111            fn AXValueCreate(
112                the_type: AXValueType,
113                value_ptr: NonNull<c_void>,
114            ) -> Option<NonNull<AXValue>>;
115        }
116        let ret = unsafe { AXValueCreate(the_type, value_ptr) };
117        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
118    }
119
120    /// Returns the structure type encoded in value. If the type is not recognized, it returns kAXValueIllegalType.
121    ///
122    ///
123    /// Parameter `value`:
124    /// Returns:
125    #[doc(alias = "AXValueGetType")]
126    #[inline]
127    pub unsafe fn r#type(&self) -> AXValueType {
128        extern "C-unwind" {
129            fn AXValueGetType(value: &AXValue) -> AXValueType;
130        }
131        unsafe { AXValueGetType(self) }
132    }
133
134    /// Decodes the structure stored in value and copies it into valuePtr. If the structure stored in value is not
135    /// the same as requested by theType, the function returns false.
136    ///
137    ///
138    /// Parameter `value`:
139    /// Returns:
140    ///
141    /// # Safety
142    ///
143    /// `value_ptr` must be a valid pointer.
144    #[doc(alias = "AXValueGetValue")]
145    #[inline]
146    pub unsafe fn value(&self, the_type: AXValueType, value_ptr: NonNull<c_void>) -> bool {
147        extern "C-unwind" {
148            fn AXValueGetValue(
149                value: &AXValue,
150                the_type: AXValueType,
151                value_ptr: NonNull<c_void>,
152            ) -> Boolean;
153        }
154        let ret = unsafe { AXValueGetValue(self, the_type, value_ptr) };
155        ret != 0
156    }
157}
158
159#[deprecated = "renamed to `AXValue::new`"]
160#[inline]
161pub unsafe extern "C-unwind" fn AXValueCreate(
162    the_type: AXValueType,
163    value_ptr: NonNull<c_void>,
164) -> Option<CFRetained<AXValue>> {
165    extern "C-unwind" {
166        fn AXValueCreate(
167            the_type: AXValueType,
168            value_ptr: NonNull<c_void>,
169        ) -> Option<NonNull<AXValue>>;
170    }
171    let ret = unsafe { AXValueCreate(the_type, value_ptr) };
172    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
173}
174
175extern "C-unwind" {
176    #[deprecated = "renamed to `AXValue::type`"]
177    pub fn AXValueGetType(value: &AXValue) -> AXValueType;
178}
179
180#[deprecated = "renamed to `AXValue::value`"]
181#[inline]
182pub unsafe extern "C-unwind" fn AXValueGetValue(
183    value: &AXValue,
184    the_type: AXValueType,
185    value_ptr: NonNull<c_void>,
186) -> bool {
187    extern "C-unwind" {
188        fn AXValueGetValue(
189            value: &AXValue,
190            the_type: AXValueType,
191            value_ptr: NonNull<c_void>,
192        ) -> Boolean;
193    }
194    let ret = unsafe { AXValueGetValue(value, the_type, value_ptr) };
195    ret != 0
196}