rute/auto/
close_event.rs

1// This file is auto-generated by rute_gen. DO NOT EDIT.
2use std::cell::Cell;
3use std::rc::Rc;
4
5#[allow(unused_imports)]
6use std::marker::PhantomData;
7
8#[allow(unused_imports)]
9use std::os::raw::c_void;
10
11#[allow(unused_imports)]
12use std::mem::transmute;
13
14#[allow(unused_imports)]
15use std::ffi::{CStr, CString};
16
17use rute_ffi_base::*;
18
19#[allow(unused_imports)]
20use auto::*;
21
22/// **Notice these docs are heavy WIP and not very relevent yet**
23///
24/// Close events are sent to widgets that the user wants to close,
25/// usually by choosing from the window menu, or by clicking
26/// the **{X}** title bar button. They are also sent when you call
27/// QWidget::close() to close a widget programmatically.
28///
29/// Close events contain a flag that indicates whether the receiver
30/// wants the widget to be closed or not. When a widget accepts the
31/// close event, it is hidden (and destroyed if it was created with
32/// the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
33/// event nothing happens. (Under X11 it is possible that the window
34/// manager will forcibly close the window; but at the time of writing
35/// we are not aware of any window manager that does this.)
36///
37/// The event handler QWidget::closeEvent() receives close events. The
38/// default implementation of this event handler accepts the close
39/// event. If you do not want your widget to be hidden, or want some
40/// special handling, you should reimplement the event handler and
41/// ignore() the event.
42///
43/// The [closeEvent() in the
44/// Application example](mainwindows/application%23close%20event%20handler)
45/// shows a close event handler that
46/// asks whether to save a document before closing.
47///
48/// If you want the widget to be deleted when it is closed, create it
49/// with the Qt::WA_DeleteOnClose flag. This is very useful for
50/// independent top-level windows in a multi-window application.
51///
52/// [QObject](QObject)
53/// s emits the [destroyed()](QObject::destroyed())
54///
55/// signal when they are deleted.
56///
57/// If the last top-level window is closed, the
58/// QGuiApplication::lastWindowClosed() signal is emitted.
59///
60/// The isAccepted() function returns `true` if the event's receiver has
61/// agreed to close the widget; call accept() to agree to close the
62/// widget and call ignore() if the receiver of this event does not
63/// want the widget to be closed.
64///
65/// **See also:** [`Widget::close`]
66/// [`Widget::hide`]
67/// [`Object::destroyed`]
68/// [`CoreApplication::exec`]
69/// [`CoreApplication::quit`]
70/// [`GuiApplication::last_window_closed`]
71/// # Licence
72///
73/// 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.
74#[derive(Clone)]
75pub struct CloseEvent<'a> {
76    #[doc(hidden)]
77    pub data: Rc<Cell<Option<*const RUBase>>>,
78    #[doc(hidden)]
79    pub all_funcs: *const RUCloseEventAllFuncs,
80    #[doc(hidden)]
81    pub owned: bool,
82    #[doc(hidden)]
83    pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
84}
85
86impl<'a> CloseEvent<'a> {
87    #[allow(dead_code)]
88    pub(crate) fn new_from_rc(ffi_data: RUCloseEvent) -> CloseEvent<'a> {
89        CloseEvent {
90            data: unsafe { Rc::from_raw(ffi_data.host_data as *const Cell<Option<*const RUBase>>) },
91            all_funcs: ffi_data.all_funcs,
92            owned: false,
93            _marker: PhantomData,
94        }
95    }
96
97    #[allow(dead_code)]
98    pub(crate) fn new_from_owned(ffi_data: RUCloseEvent) -> CloseEvent<'a> {
99        CloseEvent {
100            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
101            all_funcs: ffi_data.all_funcs,
102            owned: true,
103            _marker: PhantomData,
104        }
105    }
106
107    #[allow(dead_code)]
108    pub(crate) fn new_from_temporary(ffi_data: RUCloseEvent) -> CloseEvent<'a> {
109        CloseEvent {
110            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
111            all_funcs: ffi_data.all_funcs,
112            owned: false,
113            _marker: PhantomData,
114        }
115    }
116    #[doc(hidden)]
117    pub fn spontaneous(&self) -> bool {
118        let (obj_data, funcs) = self.get_event_obj_funcs();
119        unsafe {
120            let ret_val = ((*funcs).spontaneous)(obj_data);
121            ret_val
122        }
123    }
124    #[doc(hidden)]
125    pub fn set_accepted(&self, accepted: bool) -> &Self {
126        let (obj_data, funcs) = self.get_event_obj_funcs();
127        unsafe {
128            ((*funcs).set_accepted)(obj_data, accepted);
129        }
130        self
131    }
132    #[doc(hidden)]
133    pub fn is_accepted(&self) -> bool {
134        let (obj_data, funcs) = self.get_event_obj_funcs();
135        unsafe {
136            let ret_val = ((*funcs).is_accepted)(obj_data);
137            ret_val
138        }
139    }
140    #[doc(hidden)]
141    pub fn accept(&self) -> &Self {
142        let (obj_data, funcs) = self.get_event_obj_funcs();
143        unsafe {
144            ((*funcs).accept)(obj_data);
145        }
146        self
147    }
148    #[doc(hidden)]
149    pub fn ignore(&self) -> &Self {
150        let (obj_data, funcs) = self.get_event_obj_funcs();
151        unsafe {
152            ((*funcs).ignore)(obj_data);
153        }
154        self
155    }
156
157    pub fn build(&self) -> Self {
158        self.clone()
159    }
160}
161pub trait CloseEventTrait<'a> {
162    #[inline]
163    #[doc(hidden)]
164    fn get_close_event_obj_funcs(&self) -> (*const RUBase, *const RUCloseEventFuncs);
165}
166
167impl<'a> EventTrait<'a> for CloseEvent<'a> {
168    #[doc(hidden)]
169    fn get_event_obj_funcs(&self) -> (*const RUBase, *const RUEventFuncs) {
170        let obj = self.data.get().unwrap();
171        unsafe { (obj, (*self.all_funcs).event_funcs) }
172    }
173}
174
175impl<'a> CloseEventTrait<'a> for CloseEvent<'a> {
176    #[doc(hidden)]
177    fn get_close_event_obj_funcs(&self) -> (*const RUBase, *const RUCloseEventFuncs) {
178        let obj = self.data.get().unwrap();
179        unsafe { (obj, (*self.all_funcs).close_event_funcs) }
180    }
181}