1use 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#[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}