objc2_core_foundation/generated/
CFAttributedString.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
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfattributedstring?language=objc)
11#[repr(C)]
12pub struct CFAttributedString {
13    inner: [u8; 0],
14    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
15}
16
17cf_type!(
18    #[encoding_name = "__CFAttributedString"]
19    unsafe impl CFAttributedString {}
20);
21
22/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutableattributedstring?language=objc)
23#[repr(C)]
24pub struct CFMutableAttributedString {
25    inner: [u8; 0],
26    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
27}
28
29cf_type!(
30    #[encoding_name = "__CFAttributedString"]
31    unsafe impl CFMutableAttributedString: CFAttributedString {}
32);
33
34#[cfg(feature = "CFBase")]
35unsafe impl ConcreteType for CFAttributedString {
36    /// Returns the type identifier of all CFAttributedString instances.
37    #[doc(alias = "CFAttributedStringGetTypeID")]
38    #[inline]
39    fn type_id() -> CFTypeID {
40        extern "C-unwind" {
41            fn CFAttributedStringGetTypeID() -> CFTypeID;
42        }
43        unsafe { CFAttributedStringGetTypeID() }
44    }
45}
46
47/// Creates an attributed string with the specified string and attributes (both copied).
48#[cfg(all(feature = "CFBase", feature = "CFDictionary"))]
49#[inline]
50pub unsafe extern "C-unwind" fn CFAttributedStringCreate(
51    alloc: Option<&CFAllocator>,
52    str: Option<&CFString>,
53    attributes: Option<&CFDictionary>,
54) -> Option<CFRetained<CFAttributedString>> {
55    extern "C-unwind" {
56        fn CFAttributedStringCreate(
57            alloc: Option<&CFAllocator>,
58            str: Option<&CFString>,
59            attributes: Option<&CFDictionary>,
60        ) -> Option<NonNull<CFAttributedString>>;
61    }
62    let ret = unsafe { CFAttributedStringCreate(alloc, str, attributes) };
63    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
64}
65
66/// Creates a sub-attributed string from the specified range. It's a programming error for range to specify characters outside the bounds of aStr.
67#[cfg(feature = "CFBase")]
68#[inline]
69pub unsafe extern "C-unwind" fn CFAttributedStringCreateWithSubstring(
70    alloc: Option<&CFAllocator>,
71    a_str: Option<&CFAttributedString>,
72    range: CFRange,
73) -> Option<CFRetained<CFAttributedString>> {
74    extern "C-unwind" {
75        fn CFAttributedStringCreateWithSubstring(
76            alloc: Option<&CFAllocator>,
77            a_str: Option<&CFAttributedString>,
78            range: CFRange,
79        ) -> Option<NonNull<CFAttributedString>>;
80    }
81    let ret = unsafe { CFAttributedStringCreateWithSubstring(alloc, a_str, range) };
82    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
83}
84
85/// Creates an immutable attributed string copy.
86#[cfg(feature = "CFBase")]
87#[inline]
88pub unsafe extern "C-unwind" fn CFAttributedStringCreateCopy(
89    alloc: Option<&CFAllocator>,
90    a_str: Option<&CFAttributedString>,
91) -> Option<CFRetained<CFAttributedString>> {
92    extern "C-unwind" {
93        fn CFAttributedStringCreateCopy(
94            alloc: Option<&CFAllocator>,
95            a_str: Option<&CFAttributedString>,
96        ) -> Option<NonNull<CFAttributedString>>;
97    }
98    let ret = unsafe { CFAttributedStringCreateCopy(alloc, a_str) };
99    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
100}
101
102/// Returns the string for the attributed string. For performance reasons, this will often point at the backing store of the attributed string, and it might change if the attributed string is edited.  However, this is an implementation detail, and definitely not something that should be counted on.
103#[cfg(feature = "CFBase")]
104#[inline]
105pub unsafe extern "C-unwind" fn CFAttributedStringGetString(
106    a_str: &CFAttributedString,
107) -> Option<CFRetained<CFString>> {
108    extern "C-unwind" {
109        fn CFAttributedStringGetString(a_str: &CFAttributedString) -> Option<NonNull<CFString>>;
110    }
111    let ret = unsafe { CFAttributedStringGetString(a_str) };
112    ret.map(|ret| unsafe { CFRetained::retain(ret) })
113}
114
115extern "C-unwind" {
116    /// Returns the length of the attributed string in characters; same as CFStringGetLength(CFAttributedStringGetString(aStr))
117    #[cfg(feature = "CFBase")]
118    pub fn CFAttributedStringGetLength(a_str: &CFAttributedString) -> CFIndex;
119}
120
121/// Returns the attributes at the specified location. If effectiveRange is not NULL, upon return *effectiveRange contains a range over which the exact same set of attributes apply. Note that for performance reasons, the returned effectiveRange is not necessarily the maximal range - for that, use CFAttributedStringGetAttributesAndLongestEffectiveRange().  It's a programming error for loc to specify a location outside the bounds of the attributed string.
122///
123/// Note that the returned attribute dictionary might change in unpredictable ways from under the caller if the attributed string is edited after this call. If you wish to hang on to the dictionary long-term, you should make an actual copy of it rather than just retaining it.  Also, no assumptions should be made about the relationship of the actual CFDictionaryRef returned by this call and the dictionary originally used to set the attributes, other than the fact that the values stored in the dictionary will be identical (that is, ==) to those originally specified.
124#[cfg(all(feature = "CFBase", feature = "CFDictionary"))]
125#[inline]
126pub unsafe extern "C-unwind" fn CFAttributedStringGetAttributes(
127    a_str: &CFAttributedString,
128    loc: CFIndex,
129    effective_range: *mut CFRange,
130) -> Option<CFRetained<CFDictionary>> {
131    extern "C-unwind" {
132        fn CFAttributedStringGetAttributes(
133            a_str: &CFAttributedString,
134            loc: CFIndex,
135            effective_range: *mut CFRange,
136        ) -> Option<NonNull<CFDictionary>>;
137    }
138    let ret = unsafe { CFAttributedStringGetAttributes(a_str, loc, effective_range) };
139    ret.map(|ret| unsafe { CFRetained::retain(ret) })
140}
141
142/// Returns the value of a single attribute at the specified location. If the specified attribute doesn't exist at the location, returns NULL. If effectiveRange is not NULL, upon return *effectiveRange contains a range over which the exact same attribute value applies. Note that for performance reasons, the returned effectiveRange is not necessarily the maximal range - for that, use CFAttributedStringGetAttributeAndLongestEffectiveRange(). It's a programming error for loc to specify a location outside the bounds of the attributed string.
143#[cfg(feature = "CFBase")]
144#[inline]
145pub unsafe extern "C-unwind" fn CFAttributedStringGetAttribute(
146    a_str: &CFAttributedString,
147    loc: CFIndex,
148    attr_name: Option<&CFString>,
149    effective_range: *mut CFRange,
150) -> Option<CFRetained<CFType>> {
151    extern "C-unwind" {
152        fn CFAttributedStringGetAttribute(
153            a_str: &CFAttributedString,
154            loc: CFIndex,
155            attr_name: Option<&CFString>,
156            effective_range: *mut CFRange,
157        ) -> Option<NonNull<CFType>>;
158    }
159    let ret = unsafe { CFAttributedStringGetAttribute(a_str, loc, attr_name, effective_range) };
160    ret.map(|ret| unsafe { CFRetained::retain(ret) })
161}
162
163/// Returns the attributes at the specified location. If longestEffectiveRange is not NULL, upon return *longestEffectiveRange contains the maximal range within inRange over which the exact same set of attributes apply. The returned range is clipped to inRange. It's a programming error for loc or inRange to specify locations outside the bounds of the attributed string.
164#[cfg(all(feature = "CFBase", feature = "CFDictionary"))]
165#[inline]
166pub unsafe extern "C-unwind" fn CFAttributedStringGetAttributesAndLongestEffectiveRange(
167    a_str: &CFAttributedString,
168    loc: CFIndex,
169    in_range: CFRange,
170    longest_effective_range: *mut CFRange,
171) -> Option<CFRetained<CFDictionary>> {
172    extern "C-unwind" {
173        fn CFAttributedStringGetAttributesAndLongestEffectiveRange(
174            a_str: &CFAttributedString,
175            loc: CFIndex,
176            in_range: CFRange,
177            longest_effective_range: *mut CFRange,
178        ) -> Option<NonNull<CFDictionary>>;
179    }
180    let ret = unsafe {
181        CFAttributedStringGetAttributesAndLongestEffectiveRange(
182            a_str,
183            loc,
184            in_range,
185            longest_effective_range,
186        )
187    };
188    ret.map(|ret| unsafe { CFRetained::retain(ret) })
189}
190
191/// Returns the value of a single attribute at the specified location. If longestEffectiveRange is not NULL, upon return *longestEffectiveRange contains the maximal range within inRange over which the exact same attribute value applies. The returned range is clipped to inRange. It's a programming error for loc or inRange to specify locations outside the bounds of the attributed string.
192#[cfg(feature = "CFBase")]
193#[inline]
194pub unsafe extern "C-unwind" fn CFAttributedStringGetAttributeAndLongestEffectiveRange(
195    a_str: &CFAttributedString,
196    loc: CFIndex,
197    attr_name: Option<&CFString>,
198    in_range: CFRange,
199    longest_effective_range: *mut CFRange,
200) -> Option<CFRetained<CFType>> {
201    extern "C-unwind" {
202        fn CFAttributedStringGetAttributeAndLongestEffectiveRange(
203            a_str: &CFAttributedString,
204            loc: CFIndex,
205            attr_name: Option<&CFString>,
206            in_range: CFRange,
207            longest_effective_range: *mut CFRange,
208        ) -> Option<NonNull<CFType>>;
209    }
210    let ret = unsafe {
211        CFAttributedStringGetAttributeAndLongestEffectiveRange(
212            a_str,
213            loc,
214            attr_name,
215            in_range,
216            longest_effective_range,
217        )
218    };
219    ret.map(|ret| unsafe { CFRetained::retain(ret) })
220}
221
222/// Creates a mutable attributed string copy. maxLength, if not 0, is a hard bound on the length of the attributed string; exceeding this size limit during any editing operation is a programming error. If 0, there is no limit on the length.
223#[cfg(feature = "CFBase")]
224#[inline]
225pub unsafe extern "C-unwind" fn CFAttributedStringCreateMutableCopy(
226    alloc: Option<&CFAllocator>,
227    max_length: CFIndex,
228    a_str: Option<&CFAttributedString>,
229) -> Option<CFRetained<CFMutableAttributedString>> {
230    extern "C-unwind" {
231        fn CFAttributedStringCreateMutableCopy(
232            alloc: Option<&CFAllocator>,
233            max_length: CFIndex,
234            a_str: Option<&CFAttributedString>,
235        ) -> Option<NonNull<CFMutableAttributedString>>;
236    }
237    let ret = unsafe { CFAttributedStringCreateMutableCopy(alloc, max_length, a_str) };
238    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
239}
240
241/// Creates a mutable empty attributed string. maxLength, if not 0, is a hard bound on the length of the attributed string; exceeding this size limit during any editing operation is a programming error. If 0, there is no limit on the length.
242#[cfg(feature = "CFBase")]
243#[inline]
244pub unsafe extern "C-unwind" fn CFAttributedStringCreateMutable(
245    alloc: Option<&CFAllocator>,
246    max_length: CFIndex,
247) -> Option<CFRetained<CFMutableAttributedString>> {
248    extern "C-unwind" {
249        fn CFAttributedStringCreateMutable(
250            alloc: Option<&CFAllocator>,
251            max_length: CFIndex,
252        ) -> Option<NonNull<CFMutableAttributedString>>;
253    }
254    let ret = unsafe { CFAttributedStringCreateMutable(alloc, max_length) };
255    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
256}
257
258extern "C-unwind" {
259    /// Modifies the string for the attributed string, much like CFStringReplace().  It's an error for range to specify characters outside the bounds of aStr.
260    ///
261    /// (Note: This function is a convenience on CFAttributedStringGetMutableString(); however, until CFAttributedStringGetMutableString() is implemented, it remains the only way to edit the string of the attributed string.)
262    #[cfg(feature = "CFBase")]
263    pub fn CFAttributedStringReplaceString(
264        a_str: Option<&CFMutableAttributedString>,
265        range: CFRange,
266        replacement: Option<&CFString>,
267    );
268}
269
270/// Gets the string for the attributed string as a mutable string, allowing editing the character contents of the string as if it were an CFMutableString. Attributes corresponding to the edited range are appropriately modified. If, as a result of the edit, new characters are introduced into the string, they inherit the attributes of the first replaced character from range. If no existing characters are replaced by the edit, the new characters inherit the attributes of the character preceding range if it has any, otherwise of the character following range. If the initial string is empty, the attributes for the new characters are also empty.
271///
272/// (Note: This function is not yet implemented and will return NULL except for toll-free bridged instances.)
273#[cfg(feature = "CFBase")]
274#[inline]
275pub unsafe extern "C-unwind" fn CFAttributedStringGetMutableString(
276    a_str: Option<&CFMutableAttributedString>,
277) -> Option<CFRetained<CFMutableString>> {
278    extern "C-unwind" {
279        fn CFAttributedStringGetMutableString(
280            a_str: Option<&CFMutableAttributedString>,
281        ) -> Option<NonNull<CFMutableString>>;
282    }
283    let ret = unsafe { CFAttributedStringGetMutableString(a_str) };
284    ret.map(|ret| unsafe { CFRetained::retain(ret) })
285}
286
287/// Sets the value of multiple attributes over the specified range, which should be valid. If clearOtherAttributes is false, existing attributes (which aren't being replaced) are left alone; otherwise they are cleared. The dictionary should be setup for "usual" CF type usage --- CFString keys, and arbitrary CFType values. Note that after this call, further mutations to the replacement dictionary argument by the caller will not affect the contents of the attributed string.
288#[cfg(all(feature = "CFBase", feature = "CFDictionary"))]
289#[inline]
290pub unsafe extern "C-unwind" fn CFAttributedStringSetAttributes(
291    a_str: Option<&CFMutableAttributedString>,
292    range: CFRange,
293    replacement: Option<&CFDictionary>,
294    clear_other_attributes: bool,
295) {
296    extern "C-unwind" {
297        fn CFAttributedStringSetAttributes(
298            a_str: Option<&CFMutableAttributedString>,
299            range: CFRange,
300            replacement: Option<&CFDictionary>,
301            clear_other_attributes: Boolean,
302        );
303    }
304    unsafe {
305        CFAttributedStringSetAttributes(a_str, range, replacement, clear_other_attributes as _)
306    }
307}
308
309extern "C-unwind" {
310    /// Sets the value of a single attribute over the specified range, which should be valid. value should not be NULL.
311    #[cfg(feature = "CFBase")]
312    pub fn CFAttributedStringSetAttribute(
313        a_str: Option<&CFMutableAttributedString>,
314        range: CFRange,
315        attr_name: Option<&CFString>,
316        value: Option<&CFType>,
317    );
318}
319
320extern "C-unwind" {
321    /// Removes the value of a single attribute over the specified range, which should be valid. It's OK for the attribute not the exist over the specified range.
322    #[cfg(feature = "CFBase")]
323    pub fn CFAttributedStringRemoveAttribute(
324        a_str: Option<&CFMutableAttributedString>,
325        range: CFRange,
326        attr_name: Option<&CFString>,
327    );
328}
329
330extern "C-unwind" {
331    /// Replaces the attributed substring over the specified range with the attributed string specified in replacement. range should be valid. To delete a range of the attributed string, call CFAttributedStringReplaceString() with empty string and specified range.
332    #[cfg(feature = "CFBase")]
333    pub fn CFAttributedStringReplaceAttributedString(
334        a_str: Option<&CFMutableAttributedString>,
335        range: CFRange,
336        replacement: Option<&CFAttributedString>,
337    );
338}
339
340extern "C-unwind" {
341    /// In cases where attributed string might do a bunch of work to assure self-consistency, CFAttributedStringBeginEditing/CFAttributedStringEndEditing allow disabling that to allow deferring and coalescing any work. It's a good idea to call these around a set of related mutation calls which don't require the string to be in consistent state in between. These calls can be nested.
342    pub fn CFAttributedStringBeginEditing(a_str: Option<&CFMutableAttributedString>);
343}
344
345extern "C-unwind" {
346    /// In cases where attributed string might do a bunch of work to assure self-consistency, CFAttributedStringBeginEditing/CFAttributedStringEndEditing allow disabling that to allow deferring and coalescing any work. It's a good idea to call these around a set of related mutation calls which don't require the string to be in consistent state in between. These calls can be nested.
347    pub fn CFAttributedStringEndEditing(a_str: Option<&CFMutableAttributedString>);
348}
349
350extern "C-unwind" {
351    /// Fills bidiLevels by applying the Unicode Bidi Algorithm (P, X, W, N, and I) to the characters in range. Returns true if the result is not uni-level LTR (in other words, needing further Bidi processing). baseDirection is NSWritingDirection (NSWritingDirectionNatural, NSWritingDirectionLeftToRight, and NSWritingDirectionRightToLeft).  Understands NSWritingDirectionAttributeName values.
352    #[cfg(feature = "CFBase")]
353    pub fn CFAttributedStringGetBidiLevelsAndResolvedDirections(
354        attributed_string: &CFAttributedString,
355        range: CFRange,
356        base_direction: i8,
357        bidi_levels: *mut u8,
358        base_directions: *mut u8,
359    ) -> bool;
360}