1 // This file was generated by gir (https://github.com/gtk-rs/gir)
2 // from gir-files (https://github.com/gtk-rs/gir-files)
3 // DO NOT EDIT
4 
5 use crate::xlib;
6 use crate::Align;
7 use crate::Buildable;
8 use crate::Container;
9 use crate::ResizeMode;
10 use crate::Widget;
11 use glib::object::Cast;
12 use glib::object::IsA;
13 use glib::signal::connect_raw;
14 use glib::signal::SignalHandlerId;
15 use glib::translate::*;
16 use glib::StaticType;
17 use glib::ToValue;
18 use std::boxed::Box as Box_;
19 use std::fmt;
20 use std::mem::transmute;
21 
22 glib::wrapper! {
23     #[doc(alias = "GtkSocket")]
24     pub struct Socket(Object<ffi::GtkSocket, ffi::GtkSocketClass>) @extends Container, Widget, @implements Buildable;
25 
26     match fn {
27         type_ => || ffi::gtk_socket_get_type(),
28     }
29 }
30 
31 impl Socket {
32     #[doc(alias = "gtk_socket_new")]
new() -> Socket33     pub fn new() -> Socket {
34         assert_initialized_main_thread!();
35         unsafe { Widget::from_glib_none(ffi::gtk_socket_new()).unsafe_cast() }
36     }
37 
38     // rustdoc-stripper-ignore-next
39     /// Creates a new builder-pattern struct instance to construct [`Socket`] objects.
40     ///
41     /// This method returns an instance of [`SocketBuilder`] which can be used to create [`Socket`] objects.
builder() -> SocketBuilder42     pub fn builder() -> SocketBuilder {
43         SocketBuilder::default()
44     }
45 }
46 
47 impl Default for Socket {
default() -> Self48     fn default() -> Self {
49         Self::new()
50     }
51 }
52 
53 #[derive(Clone, Default)]
54 // rustdoc-stripper-ignore-next
55 /// A [builder-pattern] type to construct [`Socket`] objects.
56 ///
57 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
58 pub struct SocketBuilder {
59     border_width: Option<u32>,
60     child: Option<Widget>,
61     resize_mode: Option<ResizeMode>,
62     app_paintable: Option<bool>,
63     can_default: Option<bool>,
64     can_focus: Option<bool>,
65     events: Option<gdk::EventMask>,
66     expand: Option<bool>,
67     #[cfg(any(feature = "v3_20", feature = "dox"))]
68     #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
69     focus_on_click: Option<bool>,
70     halign: Option<Align>,
71     has_default: Option<bool>,
72     has_focus: Option<bool>,
73     has_tooltip: Option<bool>,
74     height_request: Option<i32>,
75     hexpand: Option<bool>,
76     hexpand_set: Option<bool>,
77     is_focus: Option<bool>,
78     margin: Option<i32>,
79     margin_bottom: Option<i32>,
80     margin_end: Option<i32>,
81     margin_start: Option<i32>,
82     margin_top: Option<i32>,
83     name: Option<String>,
84     no_show_all: Option<bool>,
85     opacity: Option<f64>,
86     parent: Option<Container>,
87     receives_default: Option<bool>,
88     sensitive: Option<bool>,
89     tooltip_markup: Option<String>,
90     tooltip_text: Option<String>,
91     valign: Option<Align>,
92     vexpand: Option<bool>,
93     vexpand_set: Option<bool>,
94     visible: Option<bool>,
95     width_request: Option<i32>,
96 }
97 
98 impl SocketBuilder {
99     // rustdoc-stripper-ignore-next
100     /// Create a new [`SocketBuilder`].
new() -> Self101     pub fn new() -> Self {
102         Self::default()
103     }
104 
105     // rustdoc-stripper-ignore-next
106     /// Build the [`Socket`].
build(self) -> Socket107     pub fn build(self) -> Socket {
108         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
109         if let Some(ref border_width) = self.border_width {
110             properties.push(("border-width", border_width));
111         }
112         if let Some(ref child) = self.child {
113             properties.push(("child", child));
114         }
115         if let Some(ref resize_mode) = self.resize_mode {
116             properties.push(("resize-mode", resize_mode));
117         }
118         if let Some(ref app_paintable) = self.app_paintable {
119             properties.push(("app-paintable", app_paintable));
120         }
121         if let Some(ref can_default) = self.can_default {
122             properties.push(("can-default", can_default));
123         }
124         if let Some(ref can_focus) = self.can_focus {
125             properties.push(("can-focus", can_focus));
126         }
127         if let Some(ref events) = self.events {
128             properties.push(("events", events));
129         }
130         if let Some(ref expand) = self.expand {
131             properties.push(("expand", expand));
132         }
133         #[cfg(any(feature = "v3_20", feature = "dox"))]
134         if let Some(ref focus_on_click) = self.focus_on_click {
135             properties.push(("focus-on-click", focus_on_click));
136         }
137         if let Some(ref halign) = self.halign {
138             properties.push(("halign", halign));
139         }
140         if let Some(ref has_default) = self.has_default {
141             properties.push(("has-default", has_default));
142         }
143         if let Some(ref has_focus) = self.has_focus {
144             properties.push(("has-focus", has_focus));
145         }
146         if let Some(ref has_tooltip) = self.has_tooltip {
147             properties.push(("has-tooltip", has_tooltip));
148         }
149         if let Some(ref height_request) = self.height_request {
150             properties.push(("height-request", height_request));
151         }
152         if let Some(ref hexpand) = self.hexpand {
153             properties.push(("hexpand", hexpand));
154         }
155         if let Some(ref hexpand_set) = self.hexpand_set {
156             properties.push(("hexpand-set", hexpand_set));
157         }
158         if let Some(ref is_focus) = self.is_focus {
159             properties.push(("is-focus", is_focus));
160         }
161         if let Some(ref margin) = self.margin {
162             properties.push(("margin", margin));
163         }
164         if let Some(ref margin_bottom) = self.margin_bottom {
165             properties.push(("margin-bottom", margin_bottom));
166         }
167         if let Some(ref margin_end) = self.margin_end {
168             properties.push(("margin-end", margin_end));
169         }
170         if let Some(ref margin_start) = self.margin_start {
171             properties.push(("margin-start", margin_start));
172         }
173         if let Some(ref margin_top) = self.margin_top {
174             properties.push(("margin-top", margin_top));
175         }
176         if let Some(ref name) = self.name {
177             properties.push(("name", name));
178         }
179         if let Some(ref no_show_all) = self.no_show_all {
180             properties.push(("no-show-all", no_show_all));
181         }
182         if let Some(ref opacity) = self.opacity {
183             properties.push(("opacity", opacity));
184         }
185         if let Some(ref parent) = self.parent {
186             properties.push(("parent", parent));
187         }
188         if let Some(ref receives_default) = self.receives_default {
189             properties.push(("receives-default", receives_default));
190         }
191         if let Some(ref sensitive) = self.sensitive {
192             properties.push(("sensitive", sensitive));
193         }
194         if let Some(ref tooltip_markup) = self.tooltip_markup {
195             properties.push(("tooltip-markup", tooltip_markup));
196         }
197         if let Some(ref tooltip_text) = self.tooltip_text {
198             properties.push(("tooltip-text", tooltip_text));
199         }
200         if let Some(ref valign) = self.valign {
201             properties.push(("valign", valign));
202         }
203         if let Some(ref vexpand) = self.vexpand {
204             properties.push(("vexpand", vexpand));
205         }
206         if let Some(ref vexpand_set) = self.vexpand_set {
207             properties.push(("vexpand-set", vexpand_set));
208         }
209         if let Some(ref visible) = self.visible {
210             properties.push(("visible", visible));
211         }
212         if let Some(ref width_request) = self.width_request {
213             properties.push(("width-request", width_request));
214         }
215         glib::Object::new::<Socket>(&properties).expect("Failed to create an instance of Socket")
216     }
217 
border_width(mut self, border_width: u32) -> Self218     pub fn border_width(mut self, border_width: u32) -> Self {
219         self.border_width = Some(border_width);
220         self
221     }
222 
child<P: IsA<Widget>>(mut self, child: &P) -> Self223     pub fn child<P: IsA<Widget>>(mut self, child: &P) -> Self {
224         self.child = Some(child.clone().upcast());
225         self
226     }
227 
resize_mode(mut self, resize_mode: ResizeMode) -> Self228     pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
229         self.resize_mode = Some(resize_mode);
230         self
231     }
232 
app_paintable(mut self, app_paintable: bool) -> Self233     pub fn app_paintable(mut self, app_paintable: bool) -> Self {
234         self.app_paintable = Some(app_paintable);
235         self
236     }
237 
can_default(mut self, can_default: bool) -> Self238     pub fn can_default(mut self, can_default: bool) -> Self {
239         self.can_default = Some(can_default);
240         self
241     }
242 
can_focus(mut self, can_focus: bool) -> Self243     pub fn can_focus(mut self, can_focus: bool) -> Self {
244         self.can_focus = Some(can_focus);
245         self
246     }
247 
events(mut self, events: gdk::EventMask) -> Self248     pub fn events(mut self, events: gdk::EventMask) -> Self {
249         self.events = Some(events);
250         self
251     }
252 
expand(mut self, expand: bool) -> Self253     pub fn expand(mut self, expand: bool) -> Self {
254         self.expand = Some(expand);
255         self
256     }
257 
258     #[cfg(any(feature = "v3_20", feature = "dox"))]
259     #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
focus_on_click(mut self, focus_on_click: bool) -> Self260     pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
261         self.focus_on_click = Some(focus_on_click);
262         self
263     }
264 
halign(mut self, halign: Align) -> Self265     pub fn halign(mut self, halign: Align) -> Self {
266         self.halign = Some(halign);
267         self
268     }
269 
has_default(mut self, has_default: bool) -> Self270     pub fn has_default(mut self, has_default: bool) -> Self {
271         self.has_default = Some(has_default);
272         self
273     }
274 
has_focus(mut self, has_focus: bool) -> Self275     pub fn has_focus(mut self, has_focus: bool) -> Self {
276         self.has_focus = Some(has_focus);
277         self
278     }
279 
has_tooltip(mut self, has_tooltip: bool) -> Self280     pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
281         self.has_tooltip = Some(has_tooltip);
282         self
283     }
284 
height_request(mut self, height_request: i32) -> Self285     pub fn height_request(mut self, height_request: i32) -> Self {
286         self.height_request = Some(height_request);
287         self
288     }
289 
hexpand(mut self, hexpand: bool) -> Self290     pub fn hexpand(mut self, hexpand: bool) -> Self {
291         self.hexpand = Some(hexpand);
292         self
293     }
294 
hexpand_set(mut self, hexpand_set: bool) -> Self295     pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
296         self.hexpand_set = Some(hexpand_set);
297         self
298     }
299 
is_focus(mut self, is_focus: bool) -> Self300     pub fn is_focus(mut self, is_focus: bool) -> Self {
301         self.is_focus = Some(is_focus);
302         self
303     }
304 
margin(mut self, margin: i32) -> Self305     pub fn margin(mut self, margin: i32) -> Self {
306         self.margin = Some(margin);
307         self
308     }
309 
margin_bottom(mut self, margin_bottom: i32) -> Self310     pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
311         self.margin_bottom = Some(margin_bottom);
312         self
313     }
314 
margin_end(mut self, margin_end: i32) -> Self315     pub fn margin_end(mut self, margin_end: i32) -> Self {
316         self.margin_end = Some(margin_end);
317         self
318     }
319 
margin_start(mut self, margin_start: i32) -> Self320     pub fn margin_start(mut self, margin_start: i32) -> Self {
321         self.margin_start = Some(margin_start);
322         self
323     }
324 
margin_top(mut self, margin_top: i32) -> Self325     pub fn margin_top(mut self, margin_top: i32) -> Self {
326         self.margin_top = Some(margin_top);
327         self
328     }
329 
name(mut self, name: &str) -> Self330     pub fn name(mut self, name: &str) -> Self {
331         self.name = Some(name.to_string());
332         self
333     }
334 
no_show_all(mut self, no_show_all: bool) -> Self335     pub fn no_show_all(mut self, no_show_all: bool) -> Self {
336         self.no_show_all = Some(no_show_all);
337         self
338     }
339 
opacity(mut self, opacity: f64) -> Self340     pub fn opacity(mut self, opacity: f64) -> Self {
341         self.opacity = Some(opacity);
342         self
343     }
344 
parent<P: IsA<Container>>(mut self, parent: &P) -> Self345     pub fn parent<P: IsA<Container>>(mut self, parent: &P) -> Self {
346         self.parent = Some(parent.clone().upcast());
347         self
348     }
349 
receives_default(mut self, receives_default: bool) -> Self350     pub fn receives_default(mut self, receives_default: bool) -> Self {
351         self.receives_default = Some(receives_default);
352         self
353     }
354 
sensitive(mut self, sensitive: bool) -> Self355     pub fn sensitive(mut self, sensitive: bool) -> Self {
356         self.sensitive = Some(sensitive);
357         self
358     }
359 
tooltip_markup(mut self, tooltip_markup: &str) -> Self360     pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
361         self.tooltip_markup = Some(tooltip_markup.to_string());
362         self
363     }
364 
tooltip_text(mut self, tooltip_text: &str) -> Self365     pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
366         self.tooltip_text = Some(tooltip_text.to_string());
367         self
368     }
369 
valign(mut self, valign: Align) -> Self370     pub fn valign(mut self, valign: Align) -> Self {
371         self.valign = Some(valign);
372         self
373     }
374 
vexpand(mut self, vexpand: bool) -> Self375     pub fn vexpand(mut self, vexpand: bool) -> Self {
376         self.vexpand = Some(vexpand);
377         self
378     }
379 
vexpand_set(mut self, vexpand_set: bool) -> Self380     pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
381         self.vexpand_set = Some(vexpand_set);
382         self
383     }
384 
visible(mut self, visible: bool) -> Self385     pub fn visible(mut self, visible: bool) -> Self {
386         self.visible = Some(visible);
387         self
388     }
389 
width_request(mut self, width_request: i32) -> Self390     pub fn width_request(mut self, width_request: i32) -> Self {
391         self.width_request = Some(width_request);
392         self
393     }
394 }
395 
396 pub const NONE_SOCKET: Option<&Socket> = None;
397 
398 pub trait GtkSocketExt: 'static {
399     #[doc(alias = "gtk_socket_add_id")]
add_id(&self, window: xlib::Window)400     fn add_id(&self, window: xlib::Window);
401 
402     #[doc(alias = "gtk_socket_get_id")]
403     #[doc(alias = "get_id")]
id(&self) -> xlib::Window404     fn id(&self) -> xlib::Window;
405 
406     #[doc(alias = "gtk_socket_get_plug_window")]
407     #[doc(alias = "get_plug_window")]
plug_window(&self) -> Option<gdk::Window>408     fn plug_window(&self) -> Option<gdk::Window>;
409 
410     #[doc(alias = "plug-added")]
connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId411     fn connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
412 
413     #[doc(alias = "plug-removed")]
connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId414     fn connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId;
415 }
416 
417 impl<O: IsA<Socket>> GtkSocketExt for O {
add_id(&self, window: xlib::Window)418     fn add_id(&self, window: xlib::Window) {
419         unsafe {
420             ffi::gtk_socket_add_id(self.as_ref().to_glib_none().0, window);
421         }
422     }
423 
id(&self) -> xlib::Window424     fn id(&self) -> xlib::Window {
425         unsafe { ffi::gtk_socket_get_id(self.as_ref().to_glib_none().0) }
426     }
427 
plug_window(&self) -> Option<gdk::Window>428     fn plug_window(&self) -> Option<gdk::Window> {
429         unsafe {
430             from_glib_none(ffi::gtk_socket_get_plug_window(
431                 self.as_ref().to_glib_none().0,
432             ))
433         }
434     }
435 
connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId436     fn connect_plug_added<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
437         unsafe extern "C" fn plug_added_trampoline<P: IsA<Socket>, F: Fn(&P) + 'static>(
438             this: *mut ffi::GtkSocket,
439             f: glib::ffi::gpointer,
440         ) {
441             let f: &F = &*(f as *const F);
442             f(Socket::from_glib_borrow(this).unsafe_cast_ref())
443         }
444         unsafe {
445             let f: Box_<F> = Box_::new(f);
446             connect_raw(
447                 self.as_ptr() as *mut _,
448                 b"plug-added\0".as_ptr() as *const _,
449                 Some(transmute::<_, unsafe extern "C" fn()>(
450                     plug_added_trampoline::<Self, F> as *const (),
451                 )),
452                 Box_::into_raw(f),
453             )
454         }
455     }
456 
connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId457     fn connect_plug_removed<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
458         unsafe extern "C" fn plug_removed_trampoline<
459             P: IsA<Socket>,
460             F: Fn(&P) -> bool + 'static,
461         >(
462             this: *mut ffi::GtkSocket,
463             f: glib::ffi::gpointer,
464         ) -> glib::ffi::gboolean {
465             let f: &F = &*(f as *const F);
466             f(Socket::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
467         }
468         unsafe {
469             let f: Box_<F> = Box_::new(f);
470             connect_raw(
471                 self.as_ptr() as *mut _,
472                 b"plug-removed\0".as_ptr() as *const _,
473                 Some(transmute::<_, unsafe extern "C" fn()>(
474                     plug_removed_trampoline::<Self, F> as *const (),
475                 )),
476                 Box_::into_raw(f),
477             )
478         }
479     }
480 }
481 
482 impl fmt::Display for Socket {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result483     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
484         f.write_str("Socket")
485     }
486 }
487