Skip to main content

gtk4/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
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Accessible;
8use crate::{
9    AccessibleRole, Actionable, Align, Buildable, Button, ConstraintTarget, LayoutManager,
10    Overflow, Widget, ffi,
11};
12use glib::{
13    object::ObjectType as _,
14    prelude::*,
15    signal::{SignalHandlerId, connect_raw},
16    translate::*,
17};
18use std::boxed::Box as Box_;
19
20#[cfg(feature = "v4_10")]
21#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
22glib::wrapper! {
23    /// A button with a hyperlink.
24    ///
25    /// <picture>
26    ///   <source srcset="link-button-dark.png" media="(prefers-color-scheme: dark)">
27    ///   <img alt="An example GtkLinkButton" src="link-button.png">
28    /// </picture>
29    ///
30    /// It is useful to show quick links to resources.
31    ///
32    /// A link button is created by calling either [`new()`][Self::new()] or
33    /// [`with_label()`][Self::with_label()]. If using the former, the URI you
34    /// pass to the constructor is used as a label for the widget.
35    ///
36    /// The URI bound to a [`LinkButton`][crate::LinkButton] can be set specifically using
37    /// [`set_uri()`][Self::set_uri()].
38    ///
39    /// By default, [`LinkButton`][crate::LinkButton] calls [`FileLauncher::launch()`][crate::FileLauncher::launch()] when the button
40    /// is clicked. This behaviour can be overridden by connecting to the
41    /// [`activate-link`][struct@crate::LinkButton#activate-link] signal and returning [`true`] from
42    /// the signal handler.
43    ///
44    /// # Shortcuts and Gestures
45    ///
46    /// [`LinkButton`][crate::LinkButton] supports the following keyboard shortcuts:
47    ///
48    /// - <kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context menu.
49    ///
50    /// # Actions
51    ///
52    /// [`LinkButton`][crate::LinkButton] defines a set of built-in actions:
53    ///
54    /// - `clipboard.copy` copies the url to the clipboard.
55    /// - `menu.popup` opens the context menu.
56    ///
57    /// # CSS nodes
58    ///
59    /// [`LinkButton`][crate::LinkButton] has a single CSS node with name button. To differentiate
60    /// it from a plain [`Button`][crate::Button], it gets the .link style class.
61    ///
62    /// # Accessibility
63    ///
64    /// [`LinkButton`][crate::LinkButton] uses the [enum@Gtk.AccessibleRole.link] role.
65    ///
66    /// ## Properties
67    ///
68    ///
69    /// #### `uri`
70    ///  The URI bound to this button.
71    ///
72    /// Readable | Writable
73    ///
74    ///
75    /// #### `visited`
76    ///  The 'visited' state of this button.
77    ///
78    /// A visited link is drawn in a different color.
79    ///
80    /// Readable | Writable
81    /// <details><summary><h4>Button</h4></summary>
82    ///
83    ///
84    /// #### `can-shrink`
85    ///  Whether the size of the button can be made smaller than the natural
86    /// size of its contents.
87    ///
88    /// For text buttons, setting this property will allow ellipsizing the label.
89    ///
90    /// If the contents of a button are an icon or a custom widget, setting this
91    /// property has no effect.
92    ///
93    /// Readable | Writable
94    ///
95    ///
96    /// #### `child`
97    ///  The child widget.
98    ///
99    /// Readable | Writable
100    ///
101    ///
102    /// #### `has-frame`
103    ///  Whether the button has a frame.
104    ///
105    /// Readable | Writable
106    ///
107    ///
108    /// #### `icon-name`
109    ///  The name of the icon used to automatically populate the button.
110    ///
111    /// Readable | Writable
112    ///
113    ///
114    /// #### `label`
115    ///  Text of the label inside the button, if the button contains a label widget.
116    ///
117    /// Readable | Writable
118    ///
119    ///
120    /// #### `use-underline`
121    ///  If set, an underline in the text indicates that the following character is
122    /// to be used as mnemonic.
123    ///
124    /// Readable | Writable
125    /// </details>
126    /// <details><summary><h4>Widget</h4></summary>
127    ///
128    ///
129    /// #### `can-focus`
130    ///  Whether the widget or any of its descendents can accept
131    /// the input focus.
132    ///
133    /// This property is meant to be set by widget implementations,
134    /// typically in their instance init function.
135    ///
136    /// Readable | Writable
137    ///
138    ///
139    /// #### `can-target`
140    ///  Whether the widget can receive pointer events.
141    ///
142    /// Readable | Writable
143    ///
144    ///
145    /// #### `css-classes`
146    ///  A list of css classes applied to this widget.
147    ///
148    /// Readable | Writable
149    ///
150    ///
151    /// #### `css-name`
152    ///  The name of this widget in the CSS tree.
153    ///
154    /// This property is meant to be set by widget implementations,
155    /// typically in their instance init function.
156    ///
157    /// Readable | Writable | Construct Only
158    ///
159    ///
160    /// #### `cursor`
161    ///  The cursor used by @widget.
162    ///
163    /// Readable | Writable
164    ///
165    ///
166    /// #### `focus-on-click`
167    ///  Whether the widget should grab focus when it is clicked with the mouse.
168    ///
169    /// This property is only relevant for widgets that can take focus.
170    ///
171    /// Readable | Writable
172    ///
173    ///
174    /// #### `focusable`
175    ///  Whether this widget itself will accept the input focus.
176    ///
177    /// Readable | Writable
178    ///
179    ///
180    /// #### `halign`
181    ///  How to distribute horizontal space if widget gets extra space.
182    ///
183    /// Readable | Writable
184    ///
185    ///
186    /// #### `has-default`
187    ///  Whether the widget is the default widget.
188    ///
189    /// Readable
190    ///
191    ///
192    /// #### `has-focus`
193    ///  Whether the widget has the input focus.
194    ///
195    /// Readable
196    ///
197    ///
198    /// #### `has-tooltip`
199    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
200    /// signal on @widget.
201    ///
202    /// A true value indicates that @widget can have a tooltip, in this case
203    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
204    /// determine whether it will provide a tooltip or not.
205    ///
206    /// Readable | Writable
207    ///
208    ///
209    /// #### `height-request`
210    ///  Overrides for height request of the widget.
211    ///
212    /// If this is -1, the natural request will be used.
213    ///
214    /// Readable | Writable
215    ///
216    ///
217    /// #### `hexpand`
218    ///  Whether to expand horizontally.
219    ///
220    /// Readable | Writable
221    ///
222    ///
223    /// #### `hexpand-set`
224    ///  Whether to use the `hexpand` property.
225    ///
226    /// Readable | Writable
227    ///
228    ///
229    /// #### `layout-manager`
230    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
231    /// the preferred size of the widget, and allocate its children.
232    ///
233    /// This property is meant to be set by widget implementations,
234    /// typically in their instance init function.
235    ///
236    /// Readable | Writable
237    ///
238    ///
239    /// #### `limit-events`
240    ///  Makes this widget act like a modal dialog, with respect to
241    /// event delivery.
242    ///
243    /// Global event controllers will not handle events with targets
244    /// inside the widget, unless they are set up to ignore propagation
245    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
246    ///
247    /// Readable | Writable
248    ///
249    ///
250    /// #### `margin-bottom`
251    ///  Margin on bottom side of widget.
252    ///
253    /// This property adds margin outside of the widget's normal size
254    /// request, the margin will be added in addition to the size from
255    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
256    ///
257    /// Readable | Writable
258    ///
259    ///
260    /// #### `margin-end`
261    ///  Margin on end of widget, horizontally.
262    ///
263    /// This property supports left-to-right and right-to-left text
264    /// directions.
265    ///
266    /// This property adds margin outside of the widget's normal size
267    /// request, the margin will be added in addition to the size from
268    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
269    ///
270    /// Readable | Writable
271    ///
272    ///
273    /// #### `margin-start`
274    ///  Margin on start of widget, horizontally.
275    ///
276    /// This property supports left-to-right and right-to-left text
277    /// directions.
278    ///
279    /// This property adds margin outside of the widget's normal size
280    /// request, the margin will be added in addition to the size from
281    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
282    ///
283    /// Readable | Writable
284    ///
285    ///
286    /// #### `margin-top`
287    ///  Margin on top side of widget.
288    ///
289    /// This property adds margin outside of the widget's normal size
290    /// request, the margin will be added in addition to the size from
291    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
292    ///
293    /// Readable | Writable
294    ///
295    ///
296    /// #### `name`
297    ///  The name of the widget.
298    ///
299    /// Readable | Writable
300    ///
301    ///
302    /// #### `opacity`
303    ///  The requested opacity of the widget.
304    ///
305    /// Readable | Writable
306    ///
307    ///
308    /// #### `overflow`
309    ///  How content outside the widget's content area is treated.
310    ///
311    /// This property is meant to be set by widget implementations,
312    /// typically in their instance init function.
313    ///
314    /// Readable | Writable
315    ///
316    ///
317    /// #### `parent`
318    ///  The parent widget of this widget.
319    ///
320    /// Readable
321    ///
322    ///
323    /// #### `receives-default`
324    ///  Whether the widget will receive the default action when it is focused.
325    ///
326    /// Readable | Writable
327    ///
328    ///
329    /// #### `root`
330    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
331    ///
332    /// This will be `NULL` if the widget is not contained in a root widget.
333    ///
334    /// Readable
335    ///
336    ///
337    /// #### `scale-factor`
338    ///  The scale factor of the widget.
339    ///
340    /// Readable
341    ///
342    ///
343    /// #### `sensitive`
344    ///  Whether the widget responds to input.
345    ///
346    /// Readable | Writable
347    ///
348    ///
349    /// #### `tooltip-markup`
350    ///  Sets the text of tooltip to be the given string, which is marked up
351    /// with Pango markup.
352    ///
353    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
354    ///
355    /// This is a convenience property which will take care of getting the
356    /// tooltip shown if the given string is not `NULL`:
357    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
358    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
359    /// the default signal handler.
360    ///
361    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
362    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
363    ///
364    /// Readable | Writable
365    ///
366    ///
367    /// #### `tooltip-text`
368    ///  Sets the text of tooltip to be the given string.
369    ///
370    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
371    ///
372    /// This is a convenience property which will take care of getting the
373    /// tooltip shown if the given string is not `NULL`:
374    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
375    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
376    /// the default signal handler.
377    ///
378    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
379    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
380    ///
381    /// Readable | Writable
382    ///
383    ///
384    /// #### `valign`
385    ///  How to distribute vertical space if widget gets extra space.
386    ///
387    /// Readable | Writable
388    ///
389    ///
390    /// #### `vexpand`
391    ///  Whether to expand vertically.
392    ///
393    /// Readable | Writable
394    ///
395    ///
396    /// #### `vexpand-set`
397    ///  Whether to use the `vexpand` property.
398    ///
399    /// Readable | Writable
400    ///
401    ///
402    /// #### `visible`
403    ///  Whether the widget is visible.
404    ///
405    /// Readable | Writable
406    ///
407    ///
408    /// #### `width-request`
409    ///  Overrides for width request of the widget.
410    ///
411    /// If this is -1, the natural request will be used.
412    ///
413    /// Readable | Writable
414    /// </details>
415    /// <details><summary><h4>Accessible</h4></summary>
416    ///
417    ///
418    /// #### `accessible-role`
419    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
420    ///
421    /// The accessible role cannot be changed once set.
422    ///
423    /// Readable | Writable
424    /// </details>
425    /// <details><summary><h4>Actionable</h4></summary>
426    ///
427    ///
428    /// #### `action-name`
429    ///  The name of the action with which this widget should be associated.
430    ///
431    /// Readable | Writable
432    ///
433    ///
434    /// #### `action-target`
435    ///  The target value of the actionable widget's action.
436    ///
437    /// Readable | Writable
438    /// </details>
439    ///
440    /// ## Signals
441    ///
442    ///
443    /// #### `activate-link`
444    ///  Emitted each time the [`LinkButton`][crate::LinkButton] is clicked.
445    ///
446    /// The default handler will call [`FileLauncher::launch()`][crate::FileLauncher::launch()] with the URI
447    /// stored inside the [`uri`][struct@crate::LinkButton#uri] property.
448    ///
449    /// To override the default behavior, you can connect to the
450    /// ::activate-link signal and stop the propagation of the signal
451    /// by returning [`true`] from your handler.
452    ///
453    ///
454    /// <details><summary><h4>Button</h4></summary>
455    ///
456    ///
457    /// #### `activate`
458    ///  Emitted to animate press then release.
459    ///
460    /// This is an action signal. Applications should never connect
461    /// to this signal, but use the [`clicked`][struct@crate::Button#clicked] signal.
462    ///
463    /// The default bindings for this signal are all forms of the
464    /// <kbd>␣</kbd> and <kbd>Enter</kbd> keys.
465    ///
466    /// Action
467    ///
468    ///
469    /// #### `clicked`
470    ///  Emitted when the button has been activated (pressed and released).
471    ///
472    /// Action
473    /// </details>
474    /// <details><summary><h4>Widget</h4></summary>
475    ///
476    ///
477    /// #### `destroy`
478    ///  Signals that all holders of a reference to the widget should release
479    /// the reference that they hold.
480    ///
481    /// May result in finalization of the widget if all references are released.
482    ///
483    /// This signal is not suitable for saving widget state.
484    ///
485    ///
486    ///
487    ///
488    /// #### `direction-changed`
489    ///  Emitted when the text direction of a widget changes.
490    ///
491    ///
492    ///
493    ///
494    /// #### `hide`
495    ///  Emitted when @widget is hidden.
496    ///
497    ///
498    ///
499    ///
500    /// #### `keynav-failed`
501    ///  Emitted if keyboard navigation fails.
502    ///
503    /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
504    ///
505    ///
506    ///
507    ///
508    /// #### `map`
509    ///  Emitted when @widget is going to be mapped.
510    ///
511    /// A widget is mapped when the widget is visible (which is controlled with
512    /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
513    /// are also visible.
514    ///
515    /// The `::map` signal can be used to determine whether a widget will be drawn,
516    /// for instance it can resume an animation that was stopped during the
517    /// emission of [`unmap`][struct@crate::Widget#unmap].
518    ///
519    ///
520    ///
521    ///
522    /// #### `mnemonic-activate`
523    ///  Emitted when a widget is activated via a mnemonic.
524    ///
525    /// The default handler for this signal activates @widget if @group_cycling
526    /// is false, or just makes @widget grab focus if @group_cycling is true.
527    ///
528    ///
529    ///
530    ///
531    /// #### `move-focus`
532    ///  Emitted when the focus is moved.
533    ///
534    /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
535    ///
536    /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
537    /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
538    ///
539    /// Action
540    ///
541    ///
542    /// #### `query-tooltip`
543    ///  Emitted when the widget’s tooltip is about to be shown.
544    ///
545    /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
546    /// is true and the hover timeout has expired with the cursor hovering
547    /// above @widget; or emitted when @widget got focus in keyboard mode.
548    ///
549    /// Using the given coordinates, the signal handler should determine
550    /// whether a tooltip should be shown for @widget. If this is the case
551    /// true should be returned, false otherwise. Note that if @keyboard_mode
552    /// is true, the values of @x and @y are undefined and should not be used.
553    ///
554    /// The signal handler is free to manipulate @tooltip with the therefore
555    /// destined function calls.
556    ///
557    ///
558    ///
559    ///
560    /// #### `realize`
561    ///  Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
562    ///
563    /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
564    /// or the widget has been mapped (that is, it is going to be drawn).
565    ///
566    ///
567    ///
568    ///
569    /// #### `show`
570    ///  Emitted when @widget is shown.
571    ///
572    ///
573    ///
574    ///
575    /// #### `state-flags-changed`
576    ///  Emitted when the widget state changes.
577    ///
578    /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
579    ///
580    ///
581    ///
582    ///
583    /// #### `unmap`
584    ///  Emitted when @widget is going to be unmapped.
585    ///
586    /// A widget is unmapped when either it or any of its parents up to the
587    /// toplevel widget have been set as hidden.
588    ///
589    /// As `::unmap` indicates that a widget will not be shown any longer,
590    /// it can be used to, for example, stop an animation on the widget.
591    ///
592    ///
593    ///
594    ///
595    /// #### `unrealize`
596    ///  Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
597    ///
598    /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
599    /// or the widget has been unmapped (that is, it is going to be hidden).
600    ///
601    ///
602    /// </details>
603    ///
604    /// # Implements
605    ///
606    /// [`ButtonExt`][trait@crate::prelude::ButtonExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`ActionableExt`][trait@crate::prelude::ActionableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual], [`ActionableExtManual`][trait@crate::prelude::ActionableExtManual]
607    #[doc(alias = "GtkLinkButton")]
608    pub struct LinkButton(Object<ffi::GtkLinkButton>) @extends Button, Widget, @implements Accessible, Buildable, ConstraintTarget, Actionable;
609
610    match fn {
611        type_ => || ffi::gtk_link_button_get_type(),
612    }
613}
614
615#[cfg(not(feature = "v4_10"))]
616glib::wrapper! {
617    #[doc(alias = "GtkLinkButton")]
618    pub struct LinkButton(Object<ffi::GtkLinkButton>) @extends Button, Widget, @implements Buildable, ConstraintTarget, Actionable;
619
620    match fn {
621        type_ => || ffi::gtk_link_button_get_type(),
622    }
623}
624
625impl LinkButton {
626    /// Creates a new [`LinkButton`][crate::LinkButton] with the URI as its text.
627    /// ## `uri`
628    /// a valid URI
629    ///
630    /// # Returns
631    ///
632    /// a new link button widget.
633    #[doc(alias = "gtk_link_button_new")]
634    pub fn new(uri: &str) -> LinkButton {
635        assert_initialized_main_thread!();
636        unsafe {
637            Widget::from_glib_none(ffi::gtk_link_button_new(uri.to_glib_none().0)).unsafe_cast()
638        }
639    }
640
641    /// Creates a new [`LinkButton`][crate::LinkButton] containing a label.
642    /// ## `uri`
643    /// a valid URI
644    /// ## `label`
645    /// the text of the button
646    ///
647    /// # Returns
648    ///
649    /// a new link button widget.
650    #[doc(alias = "gtk_link_button_new_with_label")]
651    #[doc(alias = "new_with_label")]
652    pub fn with_label(uri: &str, label: &str) -> LinkButton {
653        assert_initialized_main_thread!();
654        unsafe {
655            Widget::from_glib_none(ffi::gtk_link_button_new_with_label(
656                uri.to_glib_none().0,
657                label.to_glib_none().0,
658            ))
659            .unsafe_cast()
660        }
661    }
662
663    // rustdoc-stripper-ignore-next
664    /// Creates a new builder-pattern struct instance to construct [`LinkButton`] objects.
665    ///
666    /// This method returns an instance of [`LinkButtonBuilder`](crate::builders::LinkButtonBuilder) which can be used to create [`LinkButton`] objects.
667    pub fn builder() -> LinkButtonBuilder {
668        LinkButtonBuilder::new()
669    }
670
671    /// Retrieves the URI of the [`LinkButton`][crate::LinkButton].
672    ///
673    /// # Returns
674    ///
675    /// a valid URI. The returned string is owned by the link button
676    ///   and should not be modified or freed.
677    #[doc(alias = "gtk_link_button_get_uri")]
678    #[doc(alias = "get_uri")]
679    pub fn uri(&self) -> glib::GString {
680        unsafe { from_glib_none(ffi::gtk_link_button_get_uri(self.to_glib_none().0)) }
681    }
682
683    /// Retrieves the “visited” state of the [`LinkButton`][crate::LinkButton].
684    ///
685    /// The button becomes visited when it is clicked. If the URI
686    /// is changed on the button, the “visited” state is unset again.
687    ///
688    /// The state may also be changed using [`set_visited()`][Self::set_visited()].
689    ///
690    /// # Returns
691    ///
692    /// [`true`] if the link has been visited, [`false`] otherwise
693    #[doc(alias = "gtk_link_button_get_visited")]
694    #[doc(alias = "get_visited")]
695    #[doc(alias = "visited")]
696    pub fn is_visited(&self) -> bool {
697        unsafe { from_glib(ffi::gtk_link_button_get_visited(self.to_glib_none().0)) }
698    }
699
700    /// Sets @uri as the URI where the [`LinkButton`][crate::LinkButton] points.
701    ///
702    /// As a side-effect this unsets the “visited” state of the button.
703    /// ## `uri`
704    /// a valid URI
705    #[doc(alias = "gtk_link_button_set_uri")]
706    #[doc(alias = "uri")]
707    pub fn set_uri(&self, uri: &str) {
708        unsafe {
709            ffi::gtk_link_button_set_uri(self.to_glib_none().0, uri.to_glib_none().0);
710        }
711    }
712
713    /// Sets the “visited” state of the [`LinkButton`][crate::LinkButton].
714    ///
715    /// See [`is_visited()`][Self::is_visited()] for more details.
716    /// ## `visited`
717    /// the new “visited” state
718    #[doc(alias = "gtk_link_button_set_visited")]
719    #[doc(alias = "visited")]
720    pub fn set_visited(&self, visited: bool) {
721        unsafe {
722            ffi::gtk_link_button_set_visited(self.to_glib_none().0, visited.into_glib());
723        }
724    }
725
726    /// Emitted each time the [`LinkButton`][crate::LinkButton] is clicked.
727    ///
728    /// The default handler will call [`FileLauncher::launch()`][crate::FileLauncher::launch()] with the URI
729    /// stored inside the [`uri`][struct@crate::LinkButton#uri] property.
730    ///
731    /// To override the default behavior, you can connect to the
732    /// ::activate-link signal and stop the propagation of the signal
733    /// by returning [`true`] from your handler.
734    ///
735    /// # Returns
736    ///
737    /// [`true`] if the signal has been handled
738    #[doc(alias = "activate-link")]
739    pub fn connect_activate_link<F: Fn(&Self) -> glib::Propagation + 'static>(
740        &self,
741        f: F,
742    ) -> SignalHandlerId {
743        unsafe extern "C" fn activate_link_trampoline<
744            F: Fn(&LinkButton) -> glib::Propagation + 'static,
745        >(
746            this: *mut ffi::GtkLinkButton,
747            f: glib::ffi::gpointer,
748        ) -> glib::ffi::gboolean {
749            unsafe {
750                let f: &F = &*(f as *const F);
751                f(&from_glib_borrow(this)).into_glib()
752            }
753        }
754        unsafe {
755            let f: Box_<F> = Box_::new(f);
756            connect_raw(
757                self.as_ptr() as *mut _,
758                c"activate-link".as_ptr(),
759                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
760                    activate_link_trampoline::<F> as *const (),
761                )),
762                Box_::into_raw(f),
763            )
764        }
765    }
766
767    #[doc(alias = "uri")]
768    pub fn connect_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
769        unsafe extern "C" fn notify_uri_trampoline<F: Fn(&LinkButton) + 'static>(
770            this: *mut ffi::GtkLinkButton,
771            _param_spec: glib::ffi::gpointer,
772            f: glib::ffi::gpointer,
773        ) {
774            unsafe {
775                let f: &F = &*(f as *const F);
776                f(&from_glib_borrow(this))
777            }
778        }
779        unsafe {
780            let f: Box_<F> = Box_::new(f);
781            connect_raw(
782                self.as_ptr() as *mut _,
783                c"notify::uri".as_ptr(),
784                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
785                    notify_uri_trampoline::<F> as *const (),
786                )),
787                Box_::into_raw(f),
788            )
789        }
790    }
791
792    #[doc(alias = "visited")]
793    pub fn connect_visited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
794        unsafe extern "C" fn notify_visited_trampoline<F: Fn(&LinkButton) + 'static>(
795            this: *mut ffi::GtkLinkButton,
796            _param_spec: glib::ffi::gpointer,
797            f: glib::ffi::gpointer,
798        ) {
799            unsafe {
800                let f: &F = &*(f as *const F);
801                f(&from_glib_borrow(this))
802            }
803        }
804        unsafe {
805            let f: Box_<F> = Box_::new(f);
806            connect_raw(
807                self.as_ptr() as *mut _,
808                c"notify::visited".as_ptr(),
809                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
810                    notify_visited_trampoline::<F> as *const (),
811                )),
812                Box_::into_raw(f),
813            )
814        }
815    }
816}
817
818impl Default for LinkButton {
819    fn default() -> Self {
820        glib::object::Object::new::<Self>()
821    }
822}
823
824// rustdoc-stripper-ignore-next
825/// A [builder-pattern] type to construct [`LinkButton`] objects.
826///
827/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
828#[must_use = "The builder must be built to be used"]
829pub struct LinkButtonBuilder {
830    builder: glib::object::ObjectBuilder<'static, LinkButton>,
831}
832
833impl LinkButtonBuilder {
834    fn new() -> Self {
835        Self {
836            builder: glib::object::Object::builder(),
837        }
838    }
839
840    /// The URI bound to this button.
841    pub fn uri(self, uri: impl Into<glib::GString>) -> Self {
842        Self {
843            builder: self.builder.property("uri", uri.into()),
844        }
845    }
846
847    /// The 'visited' state of this button.
848    ///
849    /// A visited link is drawn in a different color.
850    pub fn visited(self, visited: bool) -> Self {
851        Self {
852            builder: self.builder.property("visited", visited),
853        }
854    }
855
856    /// Whether the size of the button can be made smaller than the natural
857    /// size of its contents.
858    ///
859    /// For text buttons, setting this property will allow ellipsizing the label.
860    ///
861    /// If the contents of a button are an icon or a custom widget, setting this
862    /// property has no effect.
863    #[cfg(feature = "v4_12")]
864    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
865    pub fn can_shrink(self, can_shrink: bool) -> Self {
866        Self {
867            builder: self.builder.property("can-shrink", can_shrink),
868        }
869    }
870
871    /// The child widget.
872    pub fn child(self, child: &impl IsA<Widget>) -> Self {
873        Self {
874            builder: self.builder.property("child", child.clone().upcast()),
875        }
876    }
877
878    /// Whether the button has a frame.
879    pub fn has_frame(self, has_frame: bool) -> Self {
880        Self {
881            builder: self.builder.property("has-frame", has_frame),
882        }
883    }
884
885    /// The name of the icon used to automatically populate the button.
886    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
887        Self {
888            builder: self.builder.property("icon-name", icon_name.into()),
889        }
890    }
891
892    /// Text of the label inside the button, if the button contains a label widget.
893    pub fn label(self, label: impl Into<glib::GString>) -> Self {
894        Self {
895            builder: self.builder.property("label", label.into()),
896        }
897    }
898
899    /// If set, an underline in the text indicates that the following character is
900    /// to be used as mnemonic.
901    pub fn use_underline(self, use_underline: bool) -> Self {
902        Self {
903            builder: self.builder.property("use-underline", use_underline),
904        }
905    }
906
907    /// Whether the widget or any of its descendents can accept
908    /// the input focus.
909    ///
910    /// This property is meant to be set by widget implementations,
911    /// typically in their instance init function.
912    pub fn can_focus(self, can_focus: bool) -> Self {
913        Self {
914            builder: self.builder.property("can-focus", can_focus),
915        }
916    }
917
918    /// Whether the widget can receive pointer events.
919    pub fn can_target(self, can_target: bool) -> Self {
920        Self {
921            builder: self.builder.property("can-target", can_target),
922        }
923    }
924
925    /// A list of css classes applied to this widget.
926    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
927        Self {
928            builder: self.builder.property("css-classes", css_classes.into()),
929        }
930    }
931
932    /// The name of this widget in the CSS tree.
933    ///
934    /// This property is meant to be set by widget implementations,
935    /// typically in their instance init function.
936    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
937        Self {
938            builder: self.builder.property("css-name", css_name.into()),
939        }
940    }
941
942    /// The cursor used by @widget.
943    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
944        Self {
945            builder: self.builder.property("cursor", cursor.clone()),
946        }
947    }
948
949    /// Whether the widget should grab focus when it is clicked with the mouse.
950    ///
951    /// This property is only relevant for widgets that can take focus.
952    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
953        Self {
954            builder: self.builder.property("focus-on-click", focus_on_click),
955        }
956    }
957
958    /// Whether this widget itself will accept the input focus.
959    pub fn focusable(self, focusable: bool) -> Self {
960        Self {
961            builder: self.builder.property("focusable", focusable),
962        }
963    }
964
965    /// How to distribute horizontal space if widget gets extra space.
966    pub fn halign(self, halign: Align) -> Self {
967        Self {
968            builder: self.builder.property("halign", halign),
969        }
970    }
971
972    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
973    /// signal on @widget.
974    ///
975    /// A true value indicates that @widget can have a tooltip, in this case
976    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
977    /// determine whether it will provide a tooltip or not.
978    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
979        Self {
980            builder: self.builder.property("has-tooltip", has_tooltip),
981        }
982    }
983
984    /// Overrides for height request of the widget.
985    ///
986    /// If this is -1, the natural request will be used.
987    pub fn height_request(self, height_request: i32) -> Self {
988        Self {
989            builder: self.builder.property("height-request", height_request),
990        }
991    }
992
993    /// Whether to expand horizontally.
994    pub fn hexpand(self, hexpand: bool) -> Self {
995        Self {
996            builder: self.builder.property("hexpand", hexpand),
997        }
998    }
999
1000    /// Whether to use the `hexpand` property.
1001    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1002        Self {
1003            builder: self.builder.property("hexpand-set", hexpand_set),
1004        }
1005    }
1006
1007    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1008    /// the preferred size of the widget, and allocate its children.
1009    ///
1010    /// This property is meant to be set by widget implementations,
1011    /// typically in their instance init function.
1012    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1013        Self {
1014            builder: self
1015                .builder
1016                .property("layout-manager", layout_manager.clone().upcast()),
1017        }
1018    }
1019
1020    /// Makes this widget act like a modal dialog, with respect to
1021    /// event delivery.
1022    ///
1023    /// Global event controllers will not handle events with targets
1024    /// inside the widget, unless they are set up to ignore propagation
1025    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1026    #[cfg(feature = "v4_18")]
1027    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1028    pub fn limit_events(self, limit_events: bool) -> Self {
1029        Self {
1030            builder: self.builder.property("limit-events", limit_events),
1031        }
1032    }
1033
1034    /// Margin on bottom side of widget.
1035    ///
1036    /// This property adds margin outside of the widget's normal size
1037    /// request, the margin will be added in addition to the size from
1038    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1039    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1040        Self {
1041            builder: self.builder.property("margin-bottom", margin_bottom),
1042        }
1043    }
1044
1045    /// Margin on end of widget, horizontally.
1046    ///
1047    /// This property supports left-to-right and right-to-left text
1048    /// directions.
1049    ///
1050    /// This property adds margin outside of the widget's normal size
1051    /// request, the margin will be added in addition to the size from
1052    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1053    pub fn margin_end(self, margin_end: i32) -> Self {
1054        Self {
1055            builder: self.builder.property("margin-end", margin_end),
1056        }
1057    }
1058
1059    /// Margin on start of widget, horizontally.
1060    ///
1061    /// This property supports left-to-right and right-to-left text
1062    /// directions.
1063    ///
1064    /// This property adds margin outside of the widget's normal size
1065    /// request, the margin will be added in addition to the size from
1066    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1067    pub fn margin_start(self, margin_start: i32) -> Self {
1068        Self {
1069            builder: self.builder.property("margin-start", margin_start),
1070        }
1071    }
1072
1073    /// Margin on top side of widget.
1074    ///
1075    /// This property adds margin outside of the widget's normal size
1076    /// request, the margin will be added in addition to the size from
1077    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1078    pub fn margin_top(self, margin_top: i32) -> Self {
1079        Self {
1080            builder: self.builder.property("margin-top", margin_top),
1081        }
1082    }
1083
1084    /// The name of the widget.
1085    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1086        Self {
1087            builder: self.builder.property("name", name.into()),
1088        }
1089    }
1090
1091    /// The requested opacity of the widget.
1092    pub fn opacity(self, opacity: f64) -> Self {
1093        Self {
1094            builder: self.builder.property("opacity", opacity),
1095        }
1096    }
1097
1098    /// How content outside the widget's content area is treated.
1099    ///
1100    /// This property is meant to be set by widget implementations,
1101    /// typically in their instance init function.
1102    pub fn overflow(self, overflow: Overflow) -> Self {
1103        Self {
1104            builder: self.builder.property("overflow", overflow),
1105        }
1106    }
1107
1108    /// Whether the widget will receive the default action when it is focused.
1109    pub fn receives_default(self, receives_default: bool) -> Self {
1110        Self {
1111            builder: self.builder.property("receives-default", receives_default),
1112        }
1113    }
1114
1115    /// Whether the widget responds to input.
1116    pub fn sensitive(self, sensitive: bool) -> Self {
1117        Self {
1118            builder: self.builder.property("sensitive", sensitive),
1119        }
1120    }
1121
1122    /// Sets the text of tooltip to be the given string, which is marked up
1123    /// with Pango markup.
1124    ///
1125    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1126    ///
1127    /// This is a convenience property which will take care of getting the
1128    /// tooltip shown if the given string is not `NULL`:
1129    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1130    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1131    /// the default signal handler.
1132    ///
1133    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1134    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1135    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1136        Self {
1137            builder: self
1138                .builder
1139                .property("tooltip-markup", tooltip_markup.into()),
1140        }
1141    }
1142
1143    /// Sets the text of tooltip to be the given string.
1144    ///
1145    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1146    ///
1147    /// This is a convenience property which will take care of getting the
1148    /// tooltip shown if the given string is not `NULL`:
1149    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1150    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1151    /// the default signal handler.
1152    ///
1153    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1154    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1155    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1156        Self {
1157            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1158        }
1159    }
1160
1161    /// How to distribute vertical space if widget gets extra space.
1162    pub fn valign(self, valign: Align) -> Self {
1163        Self {
1164            builder: self.builder.property("valign", valign),
1165        }
1166    }
1167
1168    /// Whether to expand vertically.
1169    pub fn vexpand(self, vexpand: bool) -> Self {
1170        Self {
1171            builder: self.builder.property("vexpand", vexpand),
1172        }
1173    }
1174
1175    /// Whether to use the `vexpand` property.
1176    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1177        Self {
1178            builder: self.builder.property("vexpand-set", vexpand_set),
1179        }
1180    }
1181
1182    /// Whether the widget is visible.
1183    pub fn visible(self, visible: bool) -> Self {
1184        Self {
1185            builder: self.builder.property("visible", visible),
1186        }
1187    }
1188
1189    /// Overrides for width request of the widget.
1190    ///
1191    /// If this is -1, the natural request will be used.
1192    pub fn width_request(self, width_request: i32) -> Self {
1193        Self {
1194            builder: self.builder.property("width-request", width_request),
1195        }
1196    }
1197
1198    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1199    ///
1200    /// The accessible role cannot be changed once set.
1201    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1202        Self {
1203            builder: self.builder.property("accessible-role", accessible_role),
1204        }
1205    }
1206
1207    /// The name of the action with which this widget should be associated.
1208    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1209        Self {
1210            builder: self.builder.property("action-name", action_name.into()),
1211        }
1212    }
1213
1214    /// The target value of the actionable widget's action.
1215    pub fn action_target(self, action_target: &glib::Variant) -> Self {
1216        Self {
1217            builder: self
1218                .builder
1219                .property("action-target", action_target.clone()),
1220        }
1221    }
1222
1223    // rustdoc-stripper-ignore-next
1224    /// Build the [`LinkButton`].
1225    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1226    pub fn build(self) -> LinkButton {
1227        assert_initialized_main_thread!();
1228        self.builder.build()
1229    }
1230}