objc2-quick-look-ui 0.3.2

Bindings to the QuickLookUI framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
#[cfg(feature = "objc2-core-graphics")]
use objc2_core_graphics::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-pdf-kit")]
use objc2_pdf_kit::*;
#[cfg(feature = "objc2-uniform-type-identifiers")]
use objc2_uniform_type_identifiers::*;

use crate::*;

extern_class!(
    /// QLPreviewReplyAttachment is used to provide data for attachment in html data-based previews.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/quicklookui/qlpreviewreplyattachment?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct QLPreviewReplyAttachment;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for QLPreviewReplyAttachment {}
);

impl QLPreviewReplyAttachment {
    extern_methods!(
        /// The data content of an html preview
        #[unsafe(method(data))]
        #[unsafe(method_family = none)]
        pub unsafe fn data(&self) -> Retained<NSData>;

        #[cfg(feature = "objc2-uniform-type-identifiers")]
        /// The content type of the attachment for an html preview
        #[unsafe(method(contentType))]
        #[unsafe(method_family = none)]
        pub unsafe fn contentType(&self) -> Retained<UTType>;

        #[cfg(feature = "objc2-uniform-type-identifiers")]
        /// Create an attachment for html previews by providing the data and mime type of the attachment.
        ///
        /// Parameter `data`: The data content of an html preview
        ///
        /// Parameter `contentType`: The UTType of the attachment for an html preview
        #[unsafe(method(initWithData:contentType:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithData_contentType(
            this: Allocated<Self>,
            data: &NSData,
            content_type: &UTType,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl QLPreviewReplyAttachment {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// To provide a data-based preview, you have to return a QLPreviewReply object.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/quicklookui/qlpreviewreply?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct QLPreviewReply;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for QLPreviewReply {}
);

impl QLPreviewReply {
    extern_methods!(
        /// String encoding for text or html based previews. Defaults to NSUTF8StringEncoding.
        #[unsafe(method(stringEncoding))]
        #[unsafe(method_family = none)]
        pub unsafe fn stringEncoding(&self) -> NSStringEncoding;

        /// Setter for [`stringEncoding`][Self::stringEncoding].
        #[unsafe(method(setStringEncoding:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setStringEncoding(&self, string_encoding: NSStringEncoding);

        /// Attachments for HTML data previews. The keys of the dictionary are the attachment identifiers (eg foo) that can be referenced with the cid:id URL (eg cid:foo).
        #[unsafe(method(attachments))]
        #[unsafe(method_family = none)]
        pub unsafe fn attachments(
            &self,
        ) -> Retained<NSDictionary<NSString, QLPreviewReplyAttachment>>;

        /// Setter for [`attachments`][Self::attachments].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setAttachments:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAttachments(
            &self,
            attachments: &NSDictionary<NSString, QLPreviewReplyAttachment>,
        );

        /// Custom display title for the preview. If left as the empty string, QuickLook will use the file name.
        #[unsafe(method(title))]
        #[unsafe(method_family = none)]
        pub unsafe fn title(&self) -> Retained<NSString>;

        /// Setter for [`title`][Self::title].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setTitle:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTitle(&self, title: &NSString);

        #[cfg(all(
            feature = "block2",
            feature = "objc2-core-foundation",
            feature = "objc2-core-graphics"
        ))]
        /// Use this method to provide a preview by drawing into a context.
        ///
        ///
        /// Parameter `contextSize`: The size of your image.
        ///
        /// Parameter `isBitmap`: Whether the context should be bitmap or vector.
        ///
        /// Parameter `drawingBlock`: The preview should be drawn into the context passed to this block. The QLPreviewReply passed into this block is the same as the one created by this method and is provided for convenience for any further updates to its properties during the drawing block. Return YES if the preview was successfully drawn into the context. Return NO and populate error otherwise.
        #[unsafe(method(initWithContextSize:isBitmap:drawingBlock:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithContextSize_isBitmap_drawingBlock(
            this: Allocated<Self>,
            context_size: CGSize,
            is_bitmap: bool,
            drawing_block: &block2::DynBlock<
                dyn Fn(NonNull<CGContext>, NonNull<QLPreviewReply>, *mut *mut NSError) -> Bool,
            >,
        ) -> Retained<Self>;

        /// Use this method to provide a preview by providing a URL to a file of a supported type.
        ///
        ///
        /// Parameter `fileURL`: A file URL representing a preview of the previewed URL. Currently supported types include: UTTypeImage, UTTypePDF, UTTypeHTML, UTTypeXML, UTTypePlainText, UTTypeRTF, UTTypeRTFD, UTTypeMovie, UTTypeAudio
        #[unsafe(method(initWithFileURL:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithFileURL(this: Allocated<Self>, file_url: &NSURL) -> Retained<Self>;

        #[cfg(all(
            feature = "block2",
            feature = "objc2-core-foundation",
            feature = "objc2-uniform-type-identifiers"
        ))]
        /// Use this method to provide a preview with data of a supported format.
        ///
        ///
        /// Parameter `contentType`: The content type of the data.
        ///
        /// Parameter `contentSize`: A hint for the size you would like to display your content at. If your content has an intrinsic size built in, such as images and PDFs, that will be used as the final size, but providing the correct size here will allow QuickLook to present loading UI at the correct size before you are finished creating the data. QuickLook will use a default size if NSZeroSize is passed in.
        ///
        /// Parameter `dataCreationBlock`: Create and return data representing the file preview. Supported types include: UTTypeImage, UTTypePDF, UTTypeHTML, UTTypeXML, UTTypePlainText, UTTypeRTF. Heavy lifting should be done inside of the dataCreationBlock instead of when creating the QLPreviewReply. The QLPreviewReply passed into this block is the same as the one created by this method and is provided for convenience for any further updates to its properties, such as attachments, during the data generation. Return the data if successful. Populate error if unsuccessful.
        ///
        /// # Safety
        ///
        /// `data_creation_block` block's return must be a valid pointer or null.
        #[unsafe(method(initWithDataOfContentType:contentSize:dataCreationBlock:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDataOfContentType_contentSize_dataCreationBlock(
            this: Allocated<Self>,
            content_type: &UTType,
            content_size: CGSize,
            data_creation_block: &block2::DynBlock<
                dyn Fn(NonNull<QLPreviewReply>, *mut *mut NSError) -> *mut NSData,
            >,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl QLPreviewReply {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// UI.
impl QLPreviewReply {
    extern_methods!(
        #[cfg(all(
            feature = "block2",
            feature = "objc2-core-foundation",
            feature = "objc2-pdf-kit"
        ))]
        /// Use this method to provide a preview with a PDFDocument
        ///
        ///
        /// Parameter `defaultPageSize`: The size of your pages in the document. If the page size varies, use the first page's size.
        ///
        /// Parameter `documentCreationBlock`: Create and return the PDFDocument. Heavy lifting should be done inside of the documentCreationBlock instead of when creating the QLPreviewReply. The QLPreviewReply passed into this block is the same as the one created by this method and is provided for convenience for any further updates to its properties during document creation. Return the PDFDocument if successfully created. Populate error if unsuccessful.
        ///
        /// # Safety
        ///
        /// `document_creation_block` block's return must be a valid pointer or null.
        #[unsafe(method(initForPDFWithPageSize:documentCreationBlock:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initForPDFWithPageSize_documentCreationBlock(
            this: Allocated<Self>,
            default_page_size: CGSize,
            document_creation_block: &block2::DynBlock<
                dyn Fn(NonNull<QLPreviewReply>, *mut *mut NSError) -> *mut PDFDocument,
            >,
        ) -> Retained<Self>;
    );
}