1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Take a look at the license at the top of the repository in the LICENSE file.

// rustdoc-stripper-ignore-next
//! Traits intended for implementing the [`PrintOperationPreview`](crate::PrintOperationPreview) interface.

use crate::{prelude::*, subclass::prelude::*, PageSetup, PrintContext, PrintOperationPreview};
use glib::translate::*;

pub trait PrintOperationPreviewImpl: ObjectImpl {
    fn ready(&self, context: &PrintContext) {
        self.parent_ready(context)
    }

    fn got_page_size(&self, context: &PrintContext, page_setup: &PageSetup) {
        self.parent_got_page_size(context, page_setup)
    }

    fn render_page(&self, page_nr: i32);
    fn is_selected(&self, page_nr: i32) -> bool;
    fn end_preview(&self);
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::PrintOperationPreviewImplExt> Sealed for T {}
}

pub trait PrintOperationPreviewImplExt: sealed::Sealed + ObjectSubclass {
    fn parent_ready(&self, context: &PrintContext) {
        unsafe {
            let type_data = Self::type_data();
            let parent_iface = type_data
                .as_ref()
                .parent_interface::<PrintOperationPreview>()
                as *const ffi::GtkPrintOperationPreviewIface;

            if let Some(func) = (*parent_iface).ready {
                func(
                    self.obj()
                        .unsafe_cast_ref::<PrintOperationPreview>()
                        .to_glib_none()
                        .0,
                    context.to_glib_none().0,
                );
            }
        }
    }

    fn parent_got_page_size(&self, context: &PrintContext, page_setup: &PageSetup) {
        unsafe {
            let type_data = Self::type_data();
            let parent_iface = type_data
                .as_ref()
                .parent_interface::<PrintOperationPreview>()
                as *const ffi::GtkPrintOperationPreviewIface;

            if let Some(func) = (*parent_iface).got_page_size {
                func(
                    self.obj()
                        .unsafe_cast_ref::<PrintOperationPreview>()
                        .to_glib_none()
                        .0,
                    context.to_glib_none().0,
                    page_setup.to_glib_none().0,
                );
            }
        }
    }

    fn parent_render_page(&self, page_nr: i32) {
        unsafe {
            let type_data = Self::type_data();
            let parent_iface = type_data
                .as_ref()
                .parent_interface::<PrintOperationPreview>()
                as *const ffi::GtkPrintOperationPreviewIface;

            if let Some(func) = (*parent_iface).render_page {
                func(
                    self.obj()
                        .unsafe_cast_ref::<PrintOperationPreview>()
                        .to_glib_none()
                        .0,
                    page_nr,
                );
            }
        }
    }

    fn parent_is_selected(&self, page_nr: i32) -> bool {
        unsafe {
            let type_data = Self::type_data();
            let parent_iface = type_data
                .as_ref()
                .parent_interface::<PrintOperationPreview>()
                as *const ffi::GtkPrintOperationPreviewIface;
            let func = (*parent_iface)
                .is_selected
                .expect("no parent \"is_selected\" implementation");

            from_glib(func(
                self.obj()
                    .unsafe_cast_ref::<PrintOperationPreview>()
                    .to_glib_none()
                    .0,
                page_nr,
            ))
        }
    }

    fn parent_end_preview(&self) {
        unsafe {
            let type_data = Self::type_data();
            let parent_iface = type_data
                .as_ref()
                .parent_interface::<PrintOperationPreview>()
                as *const ffi::GtkPrintOperationPreviewIface;

            if let Some(func) = (*parent_iface).end_preview {
                func(
                    self.obj()
                        .unsafe_cast_ref::<PrintOperationPreview>()
                        .to_glib_none()
                        .0,
                );
            }
        }
    }
}

impl<T: PrintOperationPreviewImpl> PrintOperationPreviewImplExt for T {}

unsafe impl<T: PrintOperationPreviewImpl> IsImplementable<T> for PrintOperationPreview {
    fn interface_init(iface: &mut glib::Interface<Self>) {
        let iface = iface.as_mut();

        assert_initialized_main_thread!();

        iface.ready = Some(print_operation_preview_ready::<T>);
        iface.got_page_size = Some(print_operation_preview_got_page_size::<T>);
        iface.render_page = Some(print_operation_preview_render_page::<T>);
        iface.is_selected = Some(print_operation_preview_is_selected::<T>);
        iface.end_preview = Some(print_operation_preview_end_preview::<T>);
    }
}

unsafe extern "C" fn print_operation_preview_ready<T: PrintOperationPreviewImpl>(
    print_operation_preview: *mut ffi::GtkPrintOperationPreview,
    contextptr: *mut ffi::GtkPrintContext,
) {
    let instance = &*(print_operation_preview as *mut T::Instance);
    let imp = instance.imp();
    let context: Borrowed<PrintContext> = from_glib_borrow(contextptr);

    imp.ready(&context)
}

unsafe extern "C" fn print_operation_preview_got_page_size<T: PrintOperationPreviewImpl>(
    print_operation_preview: *mut ffi::GtkPrintOperationPreview,
    contextptr: *mut ffi::GtkPrintContext,
    setupptr: *mut ffi::GtkPageSetup,
) {
    let instance = &*(print_operation_preview as *mut T::Instance);
    let imp = instance.imp();

    let context: Borrowed<PrintContext> = from_glib_borrow(contextptr);
    let setup: Borrowed<PageSetup> = from_glib_borrow(setupptr);

    imp.got_page_size(&context, &setup)
}

unsafe extern "C" fn print_operation_preview_render_page<T: PrintOperationPreviewImpl>(
    print_operation_preview: *mut ffi::GtkPrintOperationPreview,
    page_nr: i32,
) {
    let instance = &*(print_operation_preview as *mut T::Instance);
    let imp = instance.imp();

    imp.render_page(page_nr)
}

unsafe extern "C" fn print_operation_preview_is_selected<T: PrintOperationPreviewImpl>(
    print_operation_preview: *mut ffi::GtkPrintOperationPreview,
    page_nr: i32,
) -> glib::ffi::gboolean {
    let instance = &*(print_operation_preview as *mut T::Instance);
    let imp = instance.imp();

    imp.is_selected(page_nr).into_glib()
}

unsafe extern "C" fn print_operation_preview_end_preview<T: PrintOperationPreviewImpl>(
    print_operation_preview: *mut ffi::GtkPrintOperationPreview,
) {
    let instance = &*(print_operation_preview as *mut T::Instance);
    let imp = instance.imp();

    imp.end_preview()
}