1use cairo;
6use gdk;
7use gdk_pixbuf;
8use glib::object::Cast;
9use glib::object::IsA;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use gtk_sys;
14use std::fmt;
15use Align;
16use Application;
17use Bin;
18use Buildable;
19use Container;
20use ResizeMode;
21use Widget;
22use Window;
23use WindowPosition;
24use WindowType;
25
26glib_wrapper! {
27 pub struct OffscreenWindow(Object<gtk_sys::GtkOffscreenWindow, gtk_sys::GtkOffscreenWindowClass, OffscreenWindowClass>) @extends Window, Bin, Container, Widget, @implements Buildable;
28
29 match fn {
30 get_type => || gtk_sys::gtk_offscreen_window_get_type(),
31 }
32}
33
34impl OffscreenWindow {
35 pub fn new() -> OffscreenWindow {
36 assert_initialized_main_thread!();
37 unsafe { Widget::from_glib_none(gtk_sys::gtk_offscreen_window_new()).unsafe_cast() }
38 }
39}
40
41impl Default for OffscreenWindow {
42 fn default() -> Self {
43 Self::new()
44 }
45}
46
47pub struct OffscreenWindowBuilder {
48 accept_focus: Option<bool>,
49 application: Option<Application>,
50 attached_to: Option<Widget>,
51 decorated: Option<bool>,
52 default_height: Option<i32>,
53 default_width: Option<i32>,
54 deletable: Option<bool>,
55 destroy_with_parent: Option<bool>,
56 focus_on_map: Option<bool>,
57 focus_visible: Option<bool>,
58 gravity: Option<gdk::Gravity>,
59 hide_titlebar_when_maximized: Option<bool>,
60 icon: Option<gdk_pixbuf::Pixbuf>,
61 icon_name: Option<String>,
62 mnemonics_visible: Option<bool>,
63 modal: Option<bool>,
64 resizable: Option<bool>,
65 role: Option<String>,
66 screen: Option<gdk::Screen>,
67 skip_pager_hint: Option<bool>,
68 skip_taskbar_hint: Option<bool>,
69 startup_id: Option<String>,
70 title: Option<String>,
71 transient_for: Option<Window>,
72 type_: Option<WindowType>,
73 type_hint: Option<gdk::WindowTypeHint>,
74 urgency_hint: Option<bool>,
75 window_position: Option<WindowPosition>,
76 border_width: Option<u32>,
77 child: Option<Widget>,
78 resize_mode: Option<ResizeMode>,
79 app_paintable: Option<bool>,
80 can_default: Option<bool>,
81 can_focus: Option<bool>,
82 events: Option<gdk::EventMask>,
83 expand: Option<bool>,
84 #[cfg(any(feature = "v3_20", feature = "dox"))]
85 focus_on_click: Option<bool>,
86 halign: Option<Align>,
87 has_default: Option<bool>,
88 has_focus: Option<bool>,
89 has_tooltip: Option<bool>,
90 height_request: Option<i32>,
91 hexpand: Option<bool>,
92 hexpand_set: Option<bool>,
93 is_focus: Option<bool>,
94 margin: Option<i32>,
95 margin_bottom: Option<i32>,
96 margin_end: Option<i32>,
97 margin_start: Option<i32>,
98 margin_top: Option<i32>,
99 name: Option<String>,
100 no_show_all: Option<bool>,
101 opacity: Option<f64>,
102 parent: Option<Container>,
103 receives_default: Option<bool>,
104 sensitive: Option<bool>,
105 tooltip_markup: Option<String>,
107 tooltip_text: Option<String>,
108 valign: Option<Align>,
109 vexpand: Option<bool>,
110 vexpand_set: Option<bool>,
111 visible: Option<bool>,
112 width_request: Option<i32>,
113}
114
115impl OffscreenWindowBuilder {
116 pub fn new() -> Self {
117 Self {
118 accept_focus: None,
119 application: None,
120 attached_to: None,
121 decorated: None,
122 default_height: None,
123 default_width: None,
124 deletable: None,
125 destroy_with_parent: None,
126 focus_on_map: None,
127 focus_visible: None,
128 gravity: None,
129 hide_titlebar_when_maximized: None,
130 icon: None,
131 icon_name: None,
132 mnemonics_visible: None,
133 modal: None,
134 resizable: None,
135 role: None,
136 screen: None,
137 skip_pager_hint: None,
138 skip_taskbar_hint: None,
139 startup_id: None,
140 title: None,
141 transient_for: None,
142 type_: None,
143 type_hint: None,
144 urgency_hint: None,
145 window_position: None,
146 border_width: None,
147 child: None,
148 resize_mode: None,
149 app_paintable: None,
150 can_default: None,
151 can_focus: None,
152 events: None,
153 expand: None,
154 #[cfg(any(feature = "v3_20", feature = "dox"))]
155 focus_on_click: None,
156 halign: None,
157 has_default: None,
158 has_focus: None,
159 has_tooltip: None,
160 height_request: None,
161 hexpand: None,
162 hexpand_set: None,
163 is_focus: None,
164 margin: None,
165 margin_bottom: None,
166 margin_end: None,
167 margin_start: None,
168 margin_top: None,
169 name: None,
170 no_show_all: None,
171 opacity: None,
172 parent: None,
173 receives_default: None,
174 sensitive: None,
175 tooltip_markup: None,
176 tooltip_text: None,
177 valign: None,
178 vexpand: None,
179 vexpand_set: None,
180 visible: None,
181 width_request: None,
182 }
183 }
184
185 pub fn build(self) -> OffscreenWindow {
186 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
187 if let Some(ref accept_focus) = self.accept_focus {
188 properties.push(("accept-focus", accept_focus));
189 }
190 if let Some(ref application) = self.application {
191 properties.push(("application", application));
192 }
193 if let Some(ref attached_to) = self.attached_to {
194 properties.push(("attached-to", attached_to));
195 }
196 if let Some(ref decorated) = self.decorated {
197 properties.push(("decorated", decorated));
198 }
199 if let Some(ref default_height) = self.default_height {
200 properties.push(("default-height", default_height));
201 }
202 if let Some(ref default_width) = self.default_width {
203 properties.push(("default-width", default_width));
204 }
205 if let Some(ref deletable) = self.deletable {
206 properties.push(("deletable", deletable));
207 }
208 if let Some(ref destroy_with_parent) = self.destroy_with_parent {
209 properties.push(("destroy-with-parent", destroy_with_parent));
210 }
211 if let Some(ref focus_on_map) = self.focus_on_map {
212 properties.push(("focus-on-map", focus_on_map));
213 }
214 if let Some(ref focus_visible) = self.focus_visible {
215 properties.push(("focus-visible", focus_visible));
216 }
217 if let Some(ref gravity) = self.gravity {
218 properties.push(("gravity", gravity));
219 }
220 if let Some(ref hide_titlebar_when_maximized) = self.hide_titlebar_when_maximized {
221 properties.push(("hide-titlebar-when-maximized", hide_titlebar_when_maximized));
222 }
223 if let Some(ref icon) = self.icon {
224 properties.push(("icon", icon));
225 }
226 if let Some(ref icon_name) = self.icon_name {
227 properties.push(("icon-name", icon_name));
228 }
229 if let Some(ref mnemonics_visible) = self.mnemonics_visible {
230 properties.push(("mnemonics-visible", mnemonics_visible));
231 }
232 if let Some(ref modal) = self.modal {
233 properties.push(("modal", modal));
234 }
235 if let Some(ref resizable) = self.resizable {
236 properties.push(("resizable", resizable));
237 }
238 if let Some(ref role) = self.role {
239 properties.push(("role", role));
240 }
241 if let Some(ref screen) = self.screen {
242 properties.push(("screen", screen));
243 }
244 if let Some(ref skip_pager_hint) = self.skip_pager_hint {
245 properties.push(("skip-pager-hint", skip_pager_hint));
246 }
247 if let Some(ref skip_taskbar_hint) = self.skip_taskbar_hint {
248 properties.push(("skip-taskbar-hint", skip_taskbar_hint));
249 }
250 if let Some(ref startup_id) = self.startup_id {
251 properties.push(("startup-id", startup_id));
252 }
253 if let Some(ref title) = self.title {
254 properties.push(("title", title));
255 }
256 if let Some(ref transient_for) = self.transient_for {
257 properties.push(("transient-for", transient_for));
258 }
259 if let Some(ref type_) = self.type_ {
260 properties.push(("type", type_));
261 }
262 if let Some(ref type_hint) = self.type_hint {
263 properties.push(("type-hint", type_hint));
264 }
265 if let Some(ref urgency_hint) = self.urgency_hint {
266 properties.push(("urgency-hint", urgency_hint));
267 }
268 if let Some(ref window_position) = self.window_position {
269 properties.push(("window-position", window_position));
270 }
271 if let Some(ref border_width) = self.border_width {
272 properties.push(("border-width", border_width));
273 }
274 if let Some(ref child) = self.child {
275 properties.push(("child", child));
276 }
277 if let Some(ref resize_mode) = self.resize_mode {
278 properties.push(("resize-mode", resize_mode));
279 }
280 if let Some(ref app_paintable) = self.app_paintable {
281 properties.push(("app-paintable", app_paintable));
282 }
283 if let Some(ref can_default) = self.can_default {
284 properties.push(("can-default", can_default));
285 }
286 if let Some(ref can_focus) = self.can_focus {
287 properties.push(("can-focus", can_focus));
288 }
289 if let Some(ref events) = self.events {
290 properties.push(("events", events));
291 }
292 if let Some(ref expand) = self.expand {
293 properties.push(("expand", expand));
294 }
295 #[cfg(any(feature = "v3_20", feature = "dox"))]
296 {
297 if let Some(ref focus_on_click) = self.focus_on_click {
298 properties.push(("focus-on-click", focus_on_click));
299 }
300 }
301 if let Some(ref halign) = self.halign {
302 properties.push(("halign", halign));
303 }
304 if let Some(ref has_default) = self.has_default {
305 properties.push(("has-default", has_default));
306 }
307 if let Some(ref has_focus) = self.has_focus {
308 properties.push(("has-focus", has_focus));
309 }
310 if let Some(ref has_tooltip) = self.has_tooltip {
311 properties.push(("has-tooltip", has_tooltip));
312 }
313 if let Some(ref height_request) = self.height_request {
314 properties.push(("height-request", height_request));
315 }
316 if let Some(ref hexpand) = self.hexpand {
317 properties.push(("hexpand", hexpand));
318 }
319 if let Some(ref hexpand_set) = self.hexpand_set {
320 properties.push(("hexpand-set", hexpand_set));
321 }
322 if let Some(ref is_focus) = self.is_focus {
323 properties.push(("is-focus", is_focus));
324 }
325 if let Some(ref margin) = self.margin {
326 properties.push(("margin", margin));
327 }
328 if let Some(ref margin_bottom) = self.margin_bottom {
329 properties.push(("margin-bottom", margin_bottom));
330 }
331 if let Some(ref margin_end) = self.margin_end {
332 properties.push(("margin-end", margin_end));
333 }
334 if let Some(ref margin_start) = self.margin_start {
335 properties.push(("margin-start", margin_start));
336 }
337 if let Some(ref margin_top) = self.margin_top {
338 properties.push(("margin-top", margin_top));
339 }
340 if let Some(ref name) = self.name {
341 properties.push(("name", name));
342 }
343 if let Some(ref no_show_all) = self.no_show_all {
344 properties.push(("no-show-all", no_show_all));
345 }
346 if let Some(ref opacity) = self.opacity {
347 properties.push(("opacity", opacity));
348 }
349 if let Some(ref parent) = self.parent {
350 properties.push(("parent", parent));
351 }
352 if let Some(ref receives_default) = self.receives_default {
353 properties.push(("receives-default", receives_default));
354 }
355 if let Some(ref sensitive) = self.sensitive {
356 properties.push(("sensitive", sensitive));
357 }
358 if let Some(ref tooltip_markup) = self.tooltip_markup {
359 properties.push(("tooltip-markup", tooltip_markup));
360 }
361 if let Some(ref tooltip_text) = self.tooltip_text {
362 properties.push(("tooltip-text", tooltip_text));
363 }
364 if let Some(ref valign) = self.valign {
365 properties.push(("valign", valign));
366 }
367 if let Some(ref vexpand) = self.vexpand {
368 properties.push(("vexpand", vexpand));
369 }
370 if let Some(ref vexpand_set) = self.vexpand_set {
371 properties.push(("vexpand-set", vexpand_set));
372 }
373 if let Some(ref visible) = self.visible {
374 properties.push(("visible", visible));
375 }
376 if let Some(ref width_request) = self.width_request {
377 properties.push(("width-request", width_request));
378 }
379 glib::Object::new(OffscreenWindow::static_type(), &properties)
380 .expect("object new")
381 .downcast()
382 .expect("downcast")
383 }
384
385 pub fn accept_focus(mut self, accept_focus: bool) -> Self {
386 self.accept_focus = Some(accept_focus);
387 self
388 }
389
390 pub fn application(mut self, application: &Application) -> Self {
391 self.application = Some(application.clone());
392 self
393 }
394
395 pub fn attached_to(mut self, attached_to: &Widget) -> Self {
396 self.attached_to = Some(attached_to.clone());
397 self
398 }
399
400 pub fn decorated(mut self, decorated: bool) -> Self {
401 self.decorated = Some(decorated);
402 self
403 }
404
405 pub fn default_height(mut self, default_height: i32) -> Self {
406 self.default_height = Some(default_height);
407 self
408 }
409
410 pub fn default_width(mut self, default_width: i32) -> Self {
411 self.default_width = Some(default_width);
412 self
413 }
414
415 pub fn deletable(mut self, deletable: bool) -> Self {
416 self.deletable = Some(deletable);
417 self
418 }
419
420 pub fn destroy_with_parent(mut self, destroy_with_parent: bool) -> Self {
421 self.destroy_with_parent = Some(destroy_with_parent);
422 self
423 }
424
425 pub fn focus_on_map(mut self, focus_on_map: bool) -> Self {
426 self.focus_on_map = Some(focus_on_map);
427 self
428 }
429
430 pub fn focus_visible(mut self, focus_visible: bool) -> Self {
431 self.focus_visible = Some(focus_visible);
432 self
433 }
434
435 pub fn gravity(mut self, gravity: gdk::Gravity) -> Self {
436 self.gravity = Some(gravity);
437 self
438 }
439
440 pub fn hide_titlebar_when_maximized(mut self, hide_titlebar_when_maximized: bool) -> Self {
441 self.hide_titlebar_when_maximized = Some(hide_titlebar_when_maximized);
442 self
443 }
444
445 pub fn icon(mut self, icon: &gdk_pixbuf::Pixbuf) -> Self {
446 self.icon = Some(icon.clone());
447 self
448 }
449
450 pub fn icon_name(mut self, icon_name: &str) -> Self {
451 self.icon_name = Some(icon_name.to_string());
452 self
453 }
454
455 pub fn mnemonics_visible(mut self, mnemonics_visible: bool) -> Self {
456 self.mnemonics_visible = Some(mnemonics_visible);
457 self
458 }
459
460 pub fn modal(mut self, modal: bool) -> Self {
461 self.modal = Some(modal);
462 self
463 }
464
465 pub fn resizable(mut self, resizable: bool) -> Self {
466 self.resizable = Some(resizable);
467 self
468 }
469
470 pub fn role(mut self, role: &str) -> Self {
471 self.role = Some(role.to_string());
472 self
473 }
474
475 pub fn screen(mut self, screen: &gdk::Screen) -> Self {
476 self.screen = Some(screen.clone());
477 self
478 }
479
480 pub fn skip_pager_hint(mut self, skip_pager_hint: bool) -> Self {
481 self.skip_pager_hint = Some(skip_pager_hint);
482 self
483 }
484
485 pub fn skip_taskbar_hint(mut self, skip_taskbar_hint: bool) -> Self {
486 self.skip_taskbar_hint = Some(skip_taskbar_hint);
487 self
488 }
489
490 pub fn startup_id(mut self, startup_id: &str) -> Self {
491 self.startup_id = Some(startup_id.to_string());
492 self
493 }
494
495 pub fn title(mut self, title: &str) -> Self {
496 self.title = Some(title.to_string());
497 self
498 }
499
500 pub fn transient_for(mut self, transient_for: &Window) -> Self {
501 self.transient_for = Some(transient_for.clone());
502 self
503 }
504
505 pub fn type_(mut self, type_: WindowType) -> Self {
506 self.type_ = Some(type_);
507 self
508 }
509
510 pub fn type_hint(mut self, type_hint: gdk::WindowTypeHint) -> Self {
511 self.type_hint = Some(type_hint);
512 self
513 }
514
515 pub fn urgency_hint(mut self, urgency_hint: bool) -> Self {
516 self.urgency_hint = Some(urgency_hint);
517 self
518 }
519
520 pub fn window_position(mut self, window_position: WindowPosition) -> Self {
521 self.window_position = Some(window_position);
522 self
523 }
524
525 pub fn border_width(mut self, border_width: u32) -> Self {
526 self.border_width = Some(border_width);
527 self
528 }
529
530 pub fn child(mut self, child: &Widget) -> Self {
531 self.child = Some(child.clone());
532 self
533 }
534
535 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
536 self.resize_mode = Some(resize_mode);
537 self
538 }
539
540 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
541 self.app_paintable = Some(app_paintable);
542 self
543 }
544
545 pub fn can_default(mut self, can_default: bool) -> Self {
546 self.can_default = Some(can_default);
547 self
548 }
549
550 pub fn can_focus(mut self, can_focus: bool) -> Self {
551 self.can_focus = Some(can_focus);
552 self
553 }
554
555 pub fn events(mut self, events: gdk::EventMask) -> Self {
556 self.events = Some(events);
557 self
558 }
559
560 pub fn expand(mut self, expand: bool) -> Self {
561 self.expand = Some(expand);
562 self
563 }
564
565 #[cfg(any(feature = "v3_20", feature = "dox"))]
566 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
567 self.focus_on_click = Some(focus_on_click);
568 self
569 }
570
571 pub fn halign(mut self, halign: Align) -> Self {
572 self.halign = Some(halign);
573 self
574 }
575
576 pub fn has_default(mut self, has_default: bool) -> Self {
577 self.has_default = Some(has_default);
578 self
579 }
580
581 pub fn has_focus(mut self, has_focus: bool) -> Self {
582 self.has_focus = Some(has_focus);
583 self
584 }
585
586 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
587 self.has_tooltip = Some(has_tooltip);
588 self
589 }
590
591 pub fn height_request(mut self, height_request: i32) -> Self {
592 self.height_request = Some(height_request);
593 self
594 }
595
596 pub fn hexpand(mut self, hexpand: bool) -> Self {
597 self.hexpand = Some(hexpand);
598 self
599 }
600
601 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
602 self.hexpand_set = Some(hexpand_set);
603 self
604 }
605
606 pub fn is_focus(mut self, is_focus: bool) -> Self {
607 self.is_focus = Some(is_focus);
608 self
609 }
610
611 pub fn margin(mut self, margin: i32) -> Self {
612 self.margin = Some(margin);
613 self
614 }
615
616 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
617 self.margin_bottom = Some(margin_bottom);
618 self
619 }
620
621 pub fn margin_end(mut self, margin_end: i32) -> Self {
622 self.margin_end = Some(margin_end);
623 self
624 }
625
626 pub fn margin_start(mut self, margin_start: i32) -> Self {
627 self.margin_start = Some(margin_start);
628 self
629 }
630
631 pub fn margin_top(mut self, margin_top: i32) -> Self {
632 self.margin_top = Some(margin_top);
633 self
634 }
635
636 pub fn name(mut self, name: &str) -> Self {
637 self.name = Some(name.to_string());
638 self
639 }
640
641 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
642 self.no_show_all = Some(no_show_all);
643 self
644 }
645
646 pub fn opacity(mut self, opacity: f64) -> Self {
647 self.opacity = Some(opacity);
648 self
649 }
650
651 pub fn parent(mut self, parent: &Container) -> Self {
652 self.parent = Some(parent.clone());
653 self
654 }
655
656 pub fn receives_default(mut self, receives_default: bool) -> Self {
657 self.receives_default = Some(receives_default);
658 self
659 }
660
661 pub fn sensitive(mut self, sensitive: bool) -> Self {
662 self.sensitive = Some(sensitive);
663 self
664 }
665
666 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
667 self.tooltip_markup = Some(tooltip_markup.to_string());
668 self
669 }
670
671 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
672 self.tooltip_text = Some(tooltip_text.to_string());
673 self
674 }
675
676 pub fn valign(mut self, valign: Align) -> Self {
677 self.valign = Some(valign);
678 self
679 }
680
681 pub fn vexpand(mut self, vexpand: bool) -> Self {
682 self.vexpand = Some(vexpand);
683 self
684 }
685
686 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
687 self.vexpand_set = Some(vexpand_set);
688 self
689 }
690
691 pub fn visible(mut self, visible: bool) -> Self {
692 self.visible = Some(visible);
693 self
694 }
695
696 pub fn width_request(mut self, width_request: i32) -> Self {
697 self.width_request = Some(width_request);
698 self
699 }
700}
701
702pub const NONE_OFFSCREEN_WINDOW: Option<&OffscreenWindow> = None;
703
704pub trait OffscreenWindowExt: 'static {
705 fn get_pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf>;
706
707 fn get_surface(&self) -> Option<cairo::Surface>;
708}
709
710impl<O: IsA<OffscreenWindow>> OffscreenWindowExt for O {
711 fn get_pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
712 unsafe {
713 from_glib_full(gtk_sys::gtk_offscreen_window_get_pixbuf(
714 self.as_ref().to_glib_none().0,
715 ))
716 }
717 }
718
719 fn get_surface(&self) -> Option<cairo::Surface> {
720 unsafe {
721 from_glib_none(gtk_sys::gtk_offscreen_window_get_surface(
722 self.as_ref().to_glib_none().0,
723 ))
724 }
725 }
726}
727
728impl fmt::Display for OffscreenWindow {
729 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
730 write!(f, "OffscreenWindow")
731 }
732}