gtk/auto/
socket.rs

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