gtk/auto/
link_button.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::GString;
12use glib::StaticType;
13use glib::ToValue;
14use glib_sys;
15use gtk_sys;
16use signal::Inhibit;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem::transmute;
20use Actionable;
21use Align;
22use Bin;
23use Buildable;
24use Button;
25use Container;
26use PositionType;
27use ReliefStyle;
28use ResizeMode;
29use Widget;
30
31glib_wrapper! {
32    pub struct LinkButton(Object<gtk_sys::GtkLinkButton, gtk_sys::GtkLinkButtonClass, LinkButtonClass>) @extends Button, Bin, Container, Widget, @implements Buildable, Actionable;
33
34    match fn {
35        get_type => || gtk_sys::gtk_link_button_get_type(),
36    }
37}
38
39impl LinkButton {
40    pub fn new(uri: &str) -> LinkButton {
41        assert_initialized_main_thread!();
42        unsafe {
43            Widget::from_glib_none(gtk_sys::gtk_link_button_new(uri.to_glib_none().0)).unsafe_cast()
44        }
45    }
46
47    pub fn new_with_label(uri: &str, label: Option<&str>) -> LinkButton {
48        assert_initialized_main_thread!();
49        unsafe {
50            Widget::from_glib_none(gtk_sys::gtk_link_button_new_with_label(
51                uri.to_glib_none().0,
52                label.to_glib_none().0,
53            ))
54            .unsafe_cast()
55        }
56    }
57}
58
59pub struct LinkButtonBuilder {
60    uri: Option<String>,
61    visited: Option<bool>,
62    always_show_image: Option<bool>,
63    image: Option<Widget>,
64    image_position: Option<PositionType>,
65    label: Option<String>,
66    relief: Option<ReliefStyle>,
67    use_underline: Option<bool>,
68    border_width: Option<u32>,
69    child: Option<Widget>,
70    resize_mode: Option<ResizeMode>,
71    app_paintable: Option<bool>,
72    can_default: Option<bool>,
73    can_focus: Option<bool>,
74    events: Option<gdk::EventMask>,
75    expand: Option<bool>,
76    #[cfg(any(feature = "v3_20", feature = "dox"))]
77    focus_on_click: Option<bool>,
78    halign: Option<Align>,
79    has_default: Option<bool>,
80    has_focus: Option<bool>,
81    has_tooltip: Option<bool>,
82    height_request: Option<i32>,
83    hexpand: Option<bool>,
84    hexpand_set: Option<bool>,
85    is_focus: Option<bool>,
86    margin: Option<i32>,
87    margin_bottom: Option<i32>,
88    margin_end: Option<i32>,
89    margin_start: Option<i32>,
90    margin_top: Option<i32>,
91    name: Option<String>,
92    no_show_all: Option<bool>,
93    opacity: Option<f64>,
94    parent: Option<Container>,
95    receives_default: Option<bool>,
96    sensitive: Option<bool>,
97    //style: /*Unknown type*/,
98    tooltip_markup: Option<String>,
99    tooltip_text: Option<String>,
100    valign: Option<Align>,
101    vexpand: Option<bool>,
102    vexpand_set: Option<bool>,
103    visible: Option<bool>,
104    width_request: Option<i32>,
105}
106
107impl LinkButtonBuilder {
108    pub fn new() -> Self {
109        Self {
110            uri: None,
111            visited: None,
112            always_show_image: None,
113            image: None,
114            image_position: None,
115            label: None,
116            relief: None,
117            use_underline: None,
118            border_width: None,
119            child: None,
120            resize_mode: None,
121            app_paintable: None,
122            can_default: None,
123            can_focus: None,
124            events: None,
125            expand: None,
126            #[cfg(any(feature = "v3_20", feature = "dox"))]
127            focus_on_click: None,
128            halign: None,
129            has_default: None,
130            has_focus: None,
131            has_tooltip: None,
132            height_request: None,
133            hexpand: None,
134            hexpand_set: None,
135            is_focus: None,
136            margin: None,
137            margin_bottom: None,
138            margin_end: None,
139            margin_start: None,
140            margin_top: None,
141            name: None,
142            no_show_all: None,
143            opacity: None,
144            parent: None,
145            receives_default: None,
146            sensitive: None,
147            tooltip_markup: None,
148            tooltip_text: None,
149            valign: None,
150            vexpand: None,
151            vexpand_set: None,
152            visible: None,
153            width_request: None,
154        }
155    }
156
157    pub fn build(self) -> LinkButton {
158        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
159        if let Some(ref uri) = self.uri {
160            properties.push(("uri", uri));
161        }
162        if let Some(ref visited) = self.visited {
163            properties.push(("visited", visited));
164        }
165        if let Some(ref always_show_image) = self.always_show_image {
166            properties.push(("always-show-image", always_show_image));
167        }
168        if let Some(ref image) = self.image {
169            properties.push(("image", image));
170        }
171        if let Some(ref image_position) = self.image_position {
172            properties.push(("image-position", image_position));
173        }
174        if let Some(ref label) = self.label {
175            properties.push(("label", label));
176        }
177        if let Some(ref relief) = self.relief {
178            properties.push(("relief", relief));
179        }
180        if let Some(ref use_underline) = self.use_underline {
181            properties.push(("use-underline", use_underline));
182        }
183        if let Some(ref border_width) = self.border_width {
184            properties.push(("border-width", border_width));
185        }
186        if let Some(ref child) = self.child {
187            properties.push(("child", child));
188        }
189        if let Some(ref resize_mode) = self.resize_mode {
190            properties.push(("resize-mode", resize_mode));
191        }
192        if let Some(ref app_paintable) = self.app_paintable {
193            properties.push(("app-paintable", app_paintable));
194        }
195        if let Some(ref can_default) = self.can_default {
196            properties.push(("can-default", can_default));
197        }
198        if let Some(ref can_focus) = self.can_focus {
199            properties.push(("can-focus", can_focus));
200        }
201        if let Some(ref events) = self.events {
202            properties.push(("events", events));
203        }
204        if let Some(ref expand) = self.expand {
205            properties.push(("expand", expand));
206        }
207        #[cfg(any(feature = "v3_20", feature = "dox"))]
208        {
209            if let Some(ref focus_on_click) = self.focus_on_click {
210                properties.push(("focus-on-click", focus_on_click));
211            }
212        }
213        if let Some(ref halign) = self.halign {
214            properties.push(("halign", halign));
215        }
216        if let Some(ref has_default) = self.has_default {
217            properties.push(("has-default", has_default));
218        }
219        if let Some(ref has_focus) = self.has_focus {
220            properties.push(("has-focus", has_focus));
221        }
222        if let Some(ref has_tooltip) = self.has_tooltip {
223            properties.push(("has-tooltip", has_tooltip));
224        }
225        if let Some(ref height_request) = self.height_request {
226            properties.push(("height-request", height_request));
227        }
228        if let Some(ref hexpand) = self.hexpand {
229            properties.push(("hexpand", hexpand));
230        }
231        if let Some(ref hexpand_set) = self.hexpand_set {
232            properties.push(("hexpand-set", hexpand_set));
233        }
234        if let Some(ref is_focus) = self.is_focus {
235            properties.push(("is-focus", is_focus));
236        }
237        if let Some(ref margin) = self.margin {
238            properties.push(("margin", margin));
239        }
240        if let Some(ref margin_bottom) = self.margin_bottom {
241            properties.push(("margin-bottom", margin_bottom));
242        }
243        if let Some(ref margin_end) = self.margin_end {
244            properties.push(("margin-end", margin_end));
245        }
246        if let Some(ref margin_start) = self.margin_start {
247            properties.push(("margin-start", margin_start));
248        }
249        if let Some(ref margin_top) = self.margin_top {
250            properties.push(("margin-top", margin_top));
251        }
252        if let Some(ref name) = self.name {
253            properties.push(("name", name));
254        }
255        if let Some(ref no_show_all) = self.no_show_all {
256            properties.push(("no-show-all", no_show_all));
257        }
258        if let Some(ref opacity) = self.opacity {
259            properties.push(("opacity", opacity));
260        }
261        if let Some(ref parent) = self.parent {
262            properties.push(("parent", parent));
263        }
264        if let Some(ref receives_default) = self.receives_default {
265            properties.push(("receives-default", receives_default));
266        }
267        if let Some(ref sensitive) = self.sensitive {
268            properties.push(("sensitive", sensitive));
269        }
270        if let Some(ref tooltip_markup) = self.tooltip_markup {
271            properties.push(("tooltip-markup", tooltip_markup));
272        }
273        if let Some(ref tooltip_text) = self.tooltip_text {
274            properties.push(("tooltip-text", tooltip_text));
275        }
276        if let Some(ref valign) = self.valign {
277            properties.push(("valign", valign));
278        }
279        if let Some(ref vexpand) = self.vexpand {
280            properties.push(("vexpand", vexpand));
281        }
282        if let Some(ref vexpand_set) = self.vexpand_set {
283            properties.push(("vexpand-set", vexpand_set));
284        }
285        if let Some(ref visible) = self.visible {
286            properties.push(("visible", visible));
287        }
288        if let Some(ref width_request) = self.width_request {
289            properties.push(("width-request", width_request));
290        }
291        glib::Object::new(LinkButton::static_type(), &properties)
292            .expect("object new")
293            .downcast()
294            .expect("downcast")
295    }
296
297    pub fn uri(mut self, uri: &str) -> Self {
298        self.uri = Some(uri.to_string());
299        self
300    }
301
302    pub fn visited(mut self, visited: bool) -> Self {
303        self.visited = Some(visited);
304        self
305    }
306
307    pub fn always_show_image(mut self, always_show_image: bool) -> Self {
308        self.always_show_image = Some(always_show_image);
309        self
310    }
311
312    pub fn image(mut self, image: &Widget) -> Self {
313        self.image = Some(image.clone());
314        self
315    }
316
317    pub fn image_position(mut self, image_position: PositionType) -> Self {
318        self.image_position = Some(image_position);
319        self
320    }
321
322    pub fn label(mut self, label: &str) -> Self {
323        self.label = Some(label.to_string());
324        self
325    }
326
327    pub fn relief(mut self, relief: ReliefStyle) -> Self {
328        self.relief = Some(relief);
329        self
330    }
331
332    pub fn use_underline(mut self, use_underline: bool) -> Self {
333        self.use_underline = Some(use_underline);
334        self
335    }
336
337    pub fn border_width(mut self, border_width: u32) -> Self {
338        self.border_width = Some(border_width);
339        self
340    }
341
342    pub fn child(mut self, child: &Widget) -> Self {
343        self.child = Some(child.clone());
344        self
345    }
346
347    pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
348        self.resize_mode = Some(resize_mode);
349        self
350    }
351
352    pub fn app_paintable(mut self, app_paintable: bool) -> Self {
353        self.app_paintable = Some(app_paintable);
354        self
355    }
356
357    pub fn can_default(mut self, can_default: bool) -> Self {
358        self.can_default = Some(can_default);
359        self
360    }
361
362    pub fn can_focus(mut self, can_focus: bool) -> Self {
363        self.can_focus = Some(can_focus);
364        self
365    }
366
367    pub fn events(mut self, events: gdk::EventMask) -> Self {
368        self.events = Some(events);
369        self
370    }
371
372    pub fn expand(mut self, expand: bool) -> Self {
373        self.expand = Some(expand);
374        self
375    }
376
377    #[cfg(any(feature = "v3_20", feature = "dox"))]
378    pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
379        self.focus_on_click = Some(focus_on_click);
380        self
381    }
382
383    pub fn halign(mut self, halign: Align) -> Self {
384        self.halign = Some(halign);
385        self
386    }
387
388    pub fn has_default(mut self, has_default: bool) -> Self {
389        self.has_default = Some(has_default);
390        self
391    }
392
393    pub fn has_focus(mut self, has_focus: bool) -> Self {
394        self.has_focus = Some(has_focus);
395        self
396    }
397
398    pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
399        self.has_tooltip = Some(has_tooltip);
400        self
401    }
402
403    pub fn height_request(mut self, height_request: i32) -> Self {
404        self.height_request = Some(height_request);
405        self
406    }
407
408    pub fn hexpand(mut self, hexpand: bool) -> Self {
409        self.hexpand = Some(hexpand);
410        self
411    }
412
413    pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
414        self.hexpand_set = Some(hexpand_set);
415        self
416    }
417
418    pub fn is_focus(mut self, is_focus: bool) -> Self {
419        self.is_focus = Some(is_focus);
420        self
421    }
422
423    pub fn margin(mut self, margin: i32) -> Self {
424        self.margin = Some(margin);
425        self
426    }
427
428    pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
429        self.margin_bottom = Some(margin_bottom);
430        self
431    }
432
433    pub fn margin_end(mut self, margin_end: i32) -> Self {
434        self.margin_end = Some(margin_end);
435        self
436    }
437
438    pub fn margin_start(mut self, margin_start: i32) -> Self {
439        self.margin_start = Some(margin_start);
440        self
441    }
442
443    pub fn margin_top(mut self, margin_top: i32) -> Self {
444        self.margin_top = Some(margin_top);
445        self
446    }
447
448    pub fn name(mut self, name: &str) -> Self {
449        self.name = Some(name.to_string());
450        self
451    }
452
453    pub fn no_show_all(mut self, no_show_all: bool) -> Self {
454        self.no_show_all = Some(no_show_all);
455        self
456    }
457
458    pub fn opacity(mut self, opacity: f64) -> Self {
459        self.opacity = Some(opacity);
460        self
461    }
462
463    pub fn parent(mut self, parent: &Container) -> Self {
464        self.parent = Some(parent.clone());
465        self
466    }
467
468    pub fn receives_default(mut self, receives_default: bool) -> Self {
469        self.receives_default = Some(receives_default);
470        self
471    }
472
473    pub fn sensitive(mut self, sensitive: bool) -> Self {
474        self.sensitive = Some(sensitive);
475        self
476    }
477
478    pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
479        self.tooltip_markup = Some(tooltip_markup.to_string());
480        self
481    }
482
483    pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
484        self.tooltip_text = Some(tooltip_text.to_string());
485        self
486    }
487
488    pub fn valign(mut self, valign: Align) -> Self {
489        self.valign = Some(valign);
490        self
491    }
492
493    pub fn vexpand(mut self, vexpand: bool) -> Self {
494        self.vexpand = Some(vexpand);
495        self
496    }
497
498    pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
499        self.vexpand_set = Some(vexpand_set);
500        self
501    }
502
503    pub fn visible(mut self, visible: bool) -> Self {
504        self.visible = Some(visible);
505        self
506    }
507
508    pub fn width_request(mut self, width_request: i32) -> Self {
509        self.width_request = Some(width_request);
510        self
511    }
512}
513
514pub const NONE_LINK_BUTTON: Option<&LinkButton> = None;
515
516pub trait LinkButtonExt: 'static {
517    fn get_uri(&self) -> Option<GString>;
518
519    fn get_visited(&self) -> bool;
520
521    fn set_uri(&self, uri: &str);
522
523    fn set_visited(&self, visited: bool);
524
525    fn connect_activate_link<F: Fn(&Self) -> Inhibit + 'static>(&self, f: F) -> SignalHandlerId;
526
527    fn connect_property_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
528
529    fn connect_property_visited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
530}
531
532impl<O: IsA<LinkButton>> LinkButtonExt for O {
533    fn get_uri(&self) -> Option<GString> {
534        unsafe {
535            from_glib_none(gtk_sys::gtk_link_button_get_uri(
536                self.as_ref().to_glib_none().0,
537            ))
538        }
539    }
540
541    fn get_visited(&self) -> bool {
542        unsafe {
543            from_glib(gtk_sys::gtk_link_button_get_visited(
544                self.as_ref().to_glib_none().0,
545            ))
546        }
547    }
548
549    fn set_uri(&self, uri: &str) {
550        unsafe {
551            gtk_sys::gtk_link_button_set_uri(self.as_ref().to_glib_none().0, uri.to_glib_none().0);
552        }
553    }
554
555    fn set_visited(&self, visited: bool) {
556        unsafe {
557            gtk_sys::gtk_link_button_set_visited(self.as_ref().to_glib_none().0, visited.to_glib());
558        }
559    }
560
561    fn connect_activate_link<F: Fn(&Self) -> Inhibit + 'static>(&self, f: F) -> SignalHandlerId {
562        unsafe extern "C" fn activate_link_trampoline<P, F: Fn(&P) -> Inhibit + 'static>(
563            this: *mut gtk_sys::GtkLinkButton,
564            f: glib_sys::gpointer,
565        ) -> glib_sys::gboolean
566        where
567            P: IsA<LinkButton>,
568        {
569            let f: &F = &*(f as *const F);
570            f(&LinkButton::from_glib_borrow(this).unsafe_cast()).to_glib()
571        }
572        unsafe {
573            let f: Box_<F> = Box_::new(f);
574            connect_raw(
575                self.as_ptr() as *mut _,
576                b"activate-link\0".as_ptr() as *const _,
577                Some(transmute(activate_link_trampoline::<Self, F> as usize)),
578                Box_::into_raw(f),
579            )
580        }
581    }
582
583    fn connect_property_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
584        unsafe extern "C" fn notify_uri_trampoline<P, F: Fn(&P) + 'static>(
585            this: *mut gtk_sys::GtkLinkButton,
586            _param_spec: glib_sys::gpointer,
587            f: glib_sys::gpointer,
588        ) where
589            P: IsA<LinkButton>,
590        {
591            let f: &F = &*(f as *const F);
592            f(&LinkButton::from_glib_borrow(this).unsafe_cast())
593        }
594        unsafe {
595            let f: Box_<F> = Box_::new(f);
596            connect_raw(
597                self.as_ptr() as *mut _,
598                b"notify::uri\0".as_ptr() as *const _,
599                Some(transmute(notify_uri_trampoline::<Self, F> as usize)),
600                Box_::into_raw(f),
601            )
602        }
603    }
604
605    fn connect_property_visited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
606        unsafe extern "C" fn notify_visited_trampoline<P, F: Fn(&P) + 'static>(
607            this: *mut gtk_sys::GtkLinkButton,
608            _param_spec: glib_sys::gpointer,
609            f: glib_sys::gpointer,
610        ) where
611            P: IsA<LinkButton>,
612        {
613            let f: &F = &*(f as *const F);
614            f(&LinkButton::from_glib_borrow(this).unsafe_cast())
615        }
616        unsafe {
617            let f: Box_<F> = Box_::new(f);
618            connect_raw(
619                self.as_ptr() as *mut _,
620                b"notify::visited\0".as_ptr() as *const _,
621                Some(transmute(notify_visited_trampoline::<Self, F> as usize)),
622                Box_::into_raw(f),
623            )
624        }
625    }
626}
627
628impl fmt::Display for LinkButton {
629    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
630        write!(f, "LinkButton")
631    }
632}