1use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use glib_sys;
14use gtk_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use Align;
19use Buildable;
20use Container;
21use Widget;
22
23glib_wrapper! {
24 pub struct Invisible(Object<gtk_sys::GtkInvisible, gtk_sys::GtkInvisibleClass, InvisibleClass>) @extends Widget, @implements Buildable;
25
26 match fn {
27 get_type => || gtk_sys::gtk_invisible_get_type(),
28 }
29}
30
31impl Invisible {
32 pub fn new() -> Invisible {
33 assert_initialized_main_thread!();
34 unsafe { Widget::from_glib_none(gtk_sys::gtk_invisible_new()).unsafe_cast() }
35 }
36
37 pub fn new_for_screen(screen: &gdk::Screen) -> Invisible {
38 assert_initialized_main_thread!();
39 unsafe {
40 Widget::from_glib_none(gtk_sys::gtk_invisible_new_for_screen(
41 screen.to_glib_none().0,
42 ))
43 .unsafe_cast()
44 }
45 }
46}
47
48impl Default for Invisible {
49 fn default() -> Self {
50 Self::new()
51 }
52}
53
54pub struct InvisibleBuilder {
55 screen: Option<gdk::Screen>,
56 app_paintable: Option<bool>,
57 can_default: Option<bool>,
58 can_focus: Option<bool>,
59 events: Option<gdk::EventMask>,
60 expand: Option<bool>,
61 #[cfg(any(feature = "v3_20", feature = "dox"))]
62 focus_on_click: Option<bool>,
63 halign: Option<Align>,
64 has_default: Option<bool>,
65 has_focus: Option<bool>,
66 has_tooltip: Option<bool>,
67 height_request: Option<i32>,
68 hexpand: Option<bool>,
69 hexpand_set: Option<bool>,
70 is_focus: Option<bool>,
71 margin: Option<i32>,
72 margin_bottom: Option<i32>,
73 margin_end: Option<i32>,
74 margin_start: Option<i32>,
75 margin_top: Option<i32>,
76 name: Option<String>,
77 no_show_all: Option<bool>,
78 opacity: Option<f64>,
79 parent: Option<Container>,
80 receives_default: Option<bool>,
81 sensitive: Option<bool>,
82 tooltip_markup: Option<String>,
84 tooltip_text: Option<String>,
85 valign: Option<Align>,
86 vexpand: Option<bool>,
87 vexpand_set: Option<bool>,
88 visible: Option<bool>,
89 width_request: Option<i32>,
90}
91
92impl InvisibleBuilder {
93 pub fn new() -> Self {
94 Self {
95 screen: None,
96 app_paintable: None,
97 can_default: None,
98 can_focus: None,
99 events: None,
100 expand: None,
101 #[cfg(any(feature = "v3_20", feature = "dox"))]
102 focus_on_click: None,
103 halign: None,
104 has_default: None,
105 has_focus: None,
106 has_tooltip: None,
107 height_request: None,
108 hexpand: None,
109 hexpand_set: None,
110 is_focus: None,
111 margin: None,
112 margin_bottom: None,
113 margin_end: None,
114 margin_start: None,
115 margin_top: None,
116 name: None,
117 no_show_all: None,
118 opacity: None,
119 parent: None,
120 receives_default: None,
121 sensitive: None,
122 tooltip_markup: None,
123 tooltip_text: None,
124 valign: None,
125 vexpand: None,
126 vexpand_set: None,
127 visible: None,
128 width_request: None,
129 }
130 }
131
132 pub fn build(self) -> Invisible {
133 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
134 if let Some(ref screen) = self.screen {
135 properties.push(("screen", screen));
136 }
137 if let Some(ref app_paintable) = self.app_paintable {
138 properties.push(("app-paintable", app_paintable));
139 }
140 if let Some(ref can_default) = self.can_default {
141 properties.push(("can-default", can_default));
142 }
143 if let Some(ref can_focus) = self.can_focus {
144 properties.push(("can-focus", can_focus));
145 }
146 if let Some(ref events) = self.events {
147 properties.push(("events", events));
148 }
149 if let Some(ref expand) = self.expand {
150 properties.push(("expand", expand));
151 }
152 #[cfg(any(feature = "v3_20", feature = "dox"))]
153 {
154 if let Some(ref focus_on_click) = self.focus_on_click {
155 properties.push(("focus-on-click", focus_on_click));
156 }
157 }
158 if let Some(ref halign) = self.halign {
159 properties.push(("halign", halign));
160 }
161 if let Some(ref has_default) = self.has_default {
162 properties.push(("has-default", has_default));
163 }
164 if let Some(ref has_focus) = self.has_focus {
165 properties.push(("has-focus", has_focus));
166 }
167 if let Some(ref has_tooltip) = self.has_tooltip {
168 properties.push(("has-tooltip", has_tooltip));
169 }
170 if let Some(ref height_request) = self.height_request {
171 properties.push(("height-request", height_request));
172 }
173 if let Some(ref hexpand) = self.hexpand {
174 properties.push(("hexpand", hexpand));
175 }
176 if let Some(ref hexpand_set) = self.hexpand_set {
177 properties.push(("hexpand-set", hexpand_set));
178 }
179 if let Some(ref is_focus) = self.is_focus {
180 properties.push(("is-focus", is_focus));
181 }
182 if let Some(ref margin) = self.margin {
183 properties.push(("margin", margin));
184 }
185 if let Some(ref margin_bottom) = self.margin_bottom {
186 properties.push(("margin-bottom", margin_bottom));
187 }
188 if let Some(ref margin_end) = self.margin_end {
189 properties.push(("margin-end", margin_end));
190 }
191 if let Some(ref margin_start) = self.margin_start {
192 properties.push(("margin-start", margin_start));
193 }
194 if let Some(ref margin_top) = self.margin_top {
195 properties.push(("margin-top", margin_top));
196 }
197 if let Some(ref name) = self.name {
198 properties.push(("name", name));
199 }
200 if let Some(ref no_show_all) = self.no_show_all {
201 properties.push(("no-show-all", no_show_all));
202 }
203 if let Some(ref opacity) = self.opacity {
204 properties.push(("opacity", opacity));
205 }
206 if let Some(ref parent) = self.parent {
207 properties.push(("parent", parent));
208 }
209 if let Some(ref receives_default) = self.receives_default {
210 properties.push(("receives-default", receives_default));
211 }
212 if let Some(ref sensitive) = self.sensitive {
213 properties.push(("sensitive", sensitive));
214 }
215 if let Some(ref tooltip_markup) = self.tooltip_markup {
216 properties.push(("tooltip-markup", tooltip_markup));
217 }
218 if let Some(ref tooltip_text) = self.tooltip_text {
219 properties.push(("tooltip-text", tooltip_text));
220 }
221 if let Some(ref valign) = self.valign {
222 properties.push(("valign", valign));
223 }
224 if let Some(ref vexpand) = self.vexpand {
225 properties.push(("vexpand", vexpand));
226 }
227 if let Some(ref vexpand_set) = self.vexpand_set {
228 properties.push(("vexpand-set", vexpand_set));
229 }
230 if let Some(ref visible) = self.visible {
231 properties.push(("visible", visible));
232 }
233 if let Some(ref width_request) = self.width_request {
234 properties.push(("width-request", width_request));
235 }
236 glib::Object::new(Invisible::static_type(), &properties)
237 .expect("object new")
238 .downcast()
239 .expect("downcast")
240 }
241
242 pub fn screen(mut self, screen: &gdk::Screen) -> Self {
243 self.screen = Some(screen.clone());
244 self
245 }
246
247 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
248 self.app_paintable = Some(app_paintable);
249 self
250 }
251
252 pub fn can_default(mut self, can_default: bool) -> Self {
253 self.can_default = Some(can_default);
254 self
255 }
256
257 pub fn can_focus(mut self, can_focus: bool) -> Self {
258 self.can_focus = Some(can_focus);
259 self
260 }
261
262 pub fn events(mut self, events: gdk::EventMask) -> Self {
263 self.events = Some(events);
264 self
265 }
266
267 pub fn expand(mut self, expand: bool) -> Self {
268 self.expand = Some(expand);
269 self
270 }
271
272 #[cfg(any(feature = "v3_20", feature = "dox"))]
273 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
274 self.focus_on_click = Some(focus_on_click);
275 self
276 }
277
278 pub fn halign(mut self, halign: Align) -> Self {
279 self.halign = Some(halign);
280 self
281 }
282
283 pub fn has_default(mut self, has_default: bool) -> Self {
284 self.has_default = Some(has_default);
285 self
286 }
287
288 pub fn has_focus(mut self, has_focus: bool) -> Self {
289 self.has_focus = Some(has_focus);
290 self
291 }
292
293 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
294 self.has_tooltip = Some(has_tooltip);
295 self
296 }
297
298 pub fn height_request(mut self, height_request: i32) -> Self {
299 self.height_request = Some(height_request);
300 self
301 }
302
303 pub fn hexpand(mut self, hexpand: bool) -> Self {
304 self.hexpand = Some(hexpand);
305 self
306 }
307
308 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
309 self.hexpand_set = Some(hexpand_set);
310 self
311 }
312
313 pub fn is_focus(mut self, is_focus: bool) -> Self {
314 self.is_focus = Some(is_focus);
315 self
316 }
317
318 pub fn margin(mut self, margin: i32) -> Self {
319 self.margin = Some(margin);
320 self
321 }
322
323 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
324 self.margin_bottom = Some(margin_bottom);
325 self
326 }
327
328 pub fn margin_end(mut self, margin_end: i32) -> Self {
329 self.margin_end = Some(margin_end);
330 self
331 }
332
333 pub fn margin_start(mut self, margin_start: i32) -> Self {
334 self.margin_start = Some(margin_start);
335 self
336 }
337
338 pub fn margin_top(mut self, margin_top: i32) -> Self {
339 self.margin_top = Some(margin_top);
340 self
341 }
342
343 pub fn name(mut self, name: &str) -> Self {
344 self.name = Some(name.to_string());
345 self
346 }
347
348 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
349 self.no_show_all = Some(no_show_all);
350 self
351 }
352
353 pub fn opacity(mut self, opacity: f64) -> Self {
354 self.opacity = Some(opacity);
355 self
356 }
357
358 pub fn parent(mut self, parent: &Container) -> Self {
359 self.parent = Some(parent.clone());
360 self
361 }
362
363 pub fn receives_default(mut self, receives_default: bool) -> Self {
364 self.receives_default = Some(receives_default);
365 self
366 }
367
368 pub fn sensitive(mut self, sensitive: bool) -> Self {
369 self.sensitive = Some(sensitive);
370 self
371 }
372
373 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
374 self.tooltip_markup = Some(tooltip_markup.to_string());
375 self
376 }
377
378 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
379 self.tooltip_text = Some(tooltip_text.to_string());
380 self
381 }
382
383 pub fn valign(mut self, valign: Align) -> Self {
384 self.valign = Some(valign);
385 self
386 }
387
388 pub fn vexpand(mut self, vexpand: bool) -> Self {
389 self.vexpand = Some(vexpand);
390 self
391 }
392
393 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
394 self.vexpand_set = Some(vexpand_set);
395 self
396 }
397
398 pub fn visible(mut self, visible: bool) -> Self {
399 self.visible = Some(visible);
400 self
401 }
402
403 pub fn width_request(mut self, width_request: i32) -> Self {
404 self.width_request = Some(width_request);
405 self
406 }
407}
408
409pub const NONE_INVISIBLE: Option<&Invisible> = None;
410
411pub trait InvisibleExt: 'static {
412 fn set_screen(&self, screen: &gdk::Screen);
413
414 fn connect_property_screen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
415}
416
417impl<O: IsA<Invisible>> InvisibleExt for O {
418 fn set_screen(&self, screen: &gdk::Screen) {
419 unsafe {
420 gtk_sys::gtk_invisible_set_screen(
421 self.as_ref().to_glib_none().0,
422 screen.to_glib_none().0,
423 );
424 }
425 }
426
427 fn connect_property_screen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
428 unsafe extern "C" fn notify_screen_trampoline<P, F: Fn(&P) + 'static>(
429 this: *mut gtk_sys::GtkInvisible,
430 _param_spec: glib_sys::gpointer,
431 f: glib_sys::gpointer,
432 ) where
433 P: IsA<Invisible>,
434 {
435 let f: &F = &*(f as *const F);
436 f(&Invisible::from_glib_borrow(this).unsafe_cast())
437 }
438 unsafe {
439 let f: Box_<F> = Box_::new(f);
440 connect_raw(
441 self.as_ptr() as *mut _,
442 b"notify::screen\0".as_ptr() as *const _,
443 Some(transmute(notify_screen_trampoline::<Self, F> as usize)),
444 Box_::into_raw(f),
445 )
446 }
447 }
448}
449
450impl fmt::Display for Invisible {
451 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
452 write!(f, "Invisible")
453 }
454}