objc2-core-services 0.3.2

Bindings to the CoreServices framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// Opaque CF object that represents a dictionary file
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coreservices/dcsdictionary?language=objc)
#[doc(alias = "DCSDictionaryRef")]
#[repr(C)]
pub struct DCSDictionary {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl DCSDictionary {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"__DCSDictionary"> for DCSDictionary {}
);

extern "C-unwind" {
    /// Look for a word or a phrase that contains the specified offset in dictionaries
    /// activated in Dictionary.app preference
    ///
    /// Parameter `dictionary`: This parameter is not supported for Leopard. You should always pass NULL.
    ///
    /// Parameter `textString`: Text that contains the word or phrase to look up
    ///
    /// Parameter `offset`: Specifies a character offset in textString
    ///
    /// Returns: Returns a detected range of word or phrase around the specified offset,
    /// or (kCFNotFound, 0) is returned if any term is not found in active dictionaries.
    /// The result range can be used as an input parameter of DCSCopyTextDefinition()
    /// and HIDictionaryWindowShow() in Carbon framework.
    pub fn DCSGetTermRangeInString(
        dictionary: Option<&DCSDictionary>,
        text_string: &CFString,
        offset: CFIndex,
    ) -> CFRange;
}

/// Copies definition for a specified range of text
///
/// Parameter `dictionary`: This parameter is not supported for Leopard. You should always pass NULL.
///
/// Parameter `textString`: Text that contains the word or phrase to look up
///
/// Parameter `range`: Range of the target word or phrase in textString
///
/// Returns: Returns a definition of the specified term in range in plain text
#[inline]
pub unsafe extern "C-unwind" fn DCSCopyTextDefinition(
    dictionary: Option<&DCSDictionary>,
    text_string: &CFString,
    range: CFRange,
) -> Option<CFRetained<CFString>> {
    extern "C-unwind" {
        fn DCSCopyTextDefinition(
            dictionary: Option<&DCSDictionary>,
            text_string: &CFString,
            range: CFRange,
        ) -> Option<NonNull<CFString>>;
    }
    let ret = unsafe { DCSCopyTextDefinition(dictionary, text_string, range) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}