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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// This file is auto-generated by rute_gen. DO NOT EDIT.
use std::cell::Cell;
use std::rc::Rc;

#[allow(unused_imports)]
use std::marker::PhantomData;

#[allow(unused_imports)]
use std::os::raw::c_void;

#[allow(unused_imports)]
use std::mem::transmute;

#[allow(unused_imports)]
use std::ffi::{CStr, CString};

use rute_ffi_base::*;

#[allow(unused_imports)]
use auto::*;

/// **Notice these docs are heavy WIP and not very relevent yet**
///
/// QBackingStore enables the use of QPainter to paint on a QWindow with type
/// RasterSurface. The other way of rendering to a QWindow is through the use
/// of OpenGL with QOpenGLContext.
///
/// A QBackingStore contains a buffered representation of the window contents,
/// and thus supports partial updates by using QPainter to only update a sub
/// region of the window contents.
///
/// QBackingStore might be used by an application that wants to use QPainter
/// without OpenGL acceleration and without the extra overhead of using the
/// QWidget or QGraphicsView UI stacks. For an example of how to use
/// QBackingStore see the [Raster Window Example](Raster%20Window%20Example)
///
/// # Licence
///
/// The documentation is an adoption of the original [Qt Documentation](http://doc.qt.io/) and provided herein is licensed under the terms of the [GNU Free Documentation License version 1.3](http://www.gnu.org/licenses/fdl.html) as published by the Free Software Foundation.
#[derive(Clone)]
pub struct BackingStore<'a> {
    #[doc(hidden)]
    pub data: Rc<Cell<Option<*const RUBase>>>,
    #[doc(hidden)]
    pub all_funcs: *const RUBackingStoreAllFuncs,
    #[doc(hidden)]
    pub owned: bool,
    #[doc(hidden)]
    pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
}

impl<'a> BackingStore<'a> {
    #[allow(dead_code)]
    pub(crate) fn new_from_rc(ffi_data: RUBackingStore) -> BackingStore<'a> {
        BackingStore {
            data: unsafe { Rc::from_raw(ffi_data.host_data as *const Cell<Option<*const RUBase>>) },
            all_funcs: ffi_data.all_funcs,
            owned: false,
            _marker: PhantomData,
        }
    }

    #[allow(dead_code)]
    pub(crate) fn new_from_owned(ffi_data: RUBackingStore) -> BackingStore<'a> {
        BackingStore {
            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
            all_funcs: ffi_data.all_funcs,
            owned: true,
            _marker: PhantomData,
        }
    }

    #[allow(dead_code)]
    pub(crate) fn new_from_temporary(ffi_data: RUBackingStore) -> BackingStore<'a> {
        BackingStore {
            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
            all_funcs: ffi_data.all_funcs,
            owned: false,
            _marker: PhantomData,
        }
    }
    ///
    /// Returns a pointer to the top-level window associated with this
    /// surface.
    ///
    /// Returns the paint device for this surface.
    ///
    /// **Warning**: The device is only valid between calls to beginPaint() and
    /// endPaint(). You should not cache the returned value.
    ///
    /// Flushes the given *region* from the specified *window* onto the
    /// screen.
    ///
    /// The *window* must either be the top level window represented by
    /// this backingstore, or a non-transient child of that window. Passing
    /// `nullptr` falls back to using the backingstore's top level window.
    ///
    /// If the *window* is a child window, the *region* should be in child window
    /// coordinates, and the *offset* should be the child window's offset in relation
    /// to the backingstore's top level window.
    ///
    /// You should call this function after ending painting with endPaint().
    ///
    /// **See also:** [`Window::transient_parent`]
    pub fn flush<P: PointTrait<'a>, R: RegionTrait<'a>, W: WindowTrait<'a>>(
        &self,
        region: &R,
        window: &W,
        offset: &P,
    ) -> &Self {
        let (obj_region_1, _funcs) = region.get_region_obj_funcs();
        let (obj_window_2, _funcs) = window.get_window_obj_funcs();
        let (obj_offset_3, _funcs) = offset.get_point_obj_funcs();

        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            ((*funcs).flush)(obj_data, obj_region_1, obj_window_2, obj_offset_3);
        }
        self
    }
    ///
    /// Sets the size of the window surface to *size.*
    ///
    /// **See also:** [`size()`]
    pub fn resize<S: SizeTrait<'a>>(&self, size: &S) -> &Self {
        let (obj_size_1, _funcs) = size.get_size_obj_funcs();

        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            ((*funcs).resize)(obj_data, obj_size_1);
        }
        self
    }
    ///
    /// Returns the current size of the window surface.
    pub fn size(&self) -> Size {
        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).size)(obj_data);
            let t = ret_val;
            let ret_val;
            if t.host_data != ::std::ptr::null() {
                ret_val = Size::new_from_rc(t);
            } else {
                ret_val = Size::new_from_owned(t);
            }
            ret_val
        }
    }
    ///
    /// Scrolls the given *area* *dx* pixels to the right and *dy*
    /// downward; both *dx* and *dy* may be negative.
    ///
    /// Returns `true` if the area was scrolled successfully; false otherwise.
    pub fn scroll<R: RegionTrait<'a>>(&self, area: &R, dx: i32, dy: i32) -> bool {
        let (obj_area_1, _funcs) = area.get_region_obj_funcs();

        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).scroll)(obj_data, obj_area_1, dx, dy);
            ret_val
        }
    }
    ///
    /// Begins painting on the backing store surface in the given *region.*
    ///
    /// You should call this function before using the paintDevice() to
    /// paint.
    ///
    /// **See also:** [`end_paint()`]
    /// [`paint_device()`]
    pub fn begin_paint<R: RegionTrait<'a>>(&self, arg0: &R) -> &Self {
        let (obj_arg0_1, _funcs) = arg0.get_region_obj_funcs();

        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            ((*funcs).begin_paint)(obj_data, obj_arg0_1);
        }
        self
    }
    ///
    /// Ends painting.
    ///
    /// You should call this function after painting with the paintDevice()
    /// has ended.
    ///
    /// **See also:** [`begin_paint()`]
    /// [`paint_device()`]
    pub fn end_paint(&self) -> &Self {
        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            ((*funcs).end_paint)(obj_data);
        }
        self
    }
    ///
    /// Set *region* as the static contents of this window.
    pub fn set_static_contents<R: RegionTrait<'a>>(&self, region: &R) -> &Self {
        let (obj_region_1, _funcs) = region.get_region_obj_funcs();

        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            ((*funcs).set_static_contents)(obj_data, obj_region_1);
        }
        self
    }
    ///
    /// Returns a QRegion representing the area of the window that
    /// has static contents.
    pub fn static_contents(&self) -> Region {
        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).static_contents)(obj_data);
            let t = ret_val;
            let ret_val;
            if t.host_data != ::std::ptr::null() {
                ret_val = Region::new_from_rc(t);
            } else {
                ret_val = Region::new_from_owned(t);
            }
            ret_val
        }
    }
    ///
    /// Returns a boolean indicating if this window has static contents or not.
    pub fn has_static_contents(&self) -> bool {
        let (obj_data, funcs) = self.get_backing_store_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).has_static_contents)(obj_data);
            ret_val
        }
    }

    pub fn build(&self) -> Self {
        self.clone()
    }
}
pub trait BackingStoreTrait<'a> {
    #[inline]
    #[doc(hidden)]
    fn get_backing_store_obj_funcs(&self) -> (*const RUBase, *const RUBackingStoreFuncs);
}

impl<'a> BackingStoreTrait<'a> for BackingStore<'a> {
    #[doc(hidden)]
    fn get_backing_store_obj_funcs(&self) -> (*const RUBase, *const RUBackingStoreFuncs) {
        let obj = self.data.get().unwrap();
        unsafe { (obj, (*self.all_funcs).backing_store_funcs) }
    }
}