A button with a hyperlink.
<picture> <source srcset="link-button-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkLinkButton" src="link-button.png"> </picture> It is useful to show quick links to resources.
A link button is created by calling either [ctorGtk.LinkButton.new] or [ctorGtk.LinkButton.new_with_label]. If using the former, the URI you pass to the constructor is used as a label for the widget.
The URI bound to a GtkLinkButton can be set specifically using [methodGtk.LinkButton.set_uri].
By default, GtkLinkButton calls [methodGtk.FileLauncher.launch] when the button is clicked. This behaviour can be overridden by connecting to the [signalGtk.LinkButton::activate-link] signal and returning True from the signal handler.
# Shortcuts and Gestures
GtkLinkButton supports the following keyboard shortcuts:
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context
menu.
# Actions
GtkLinkButton defines a set of built-in actions:
clipboard.copy copies the url to the clipboard. - menu.popup opens
the context menu.
# CSS nodes
GtkLinkButton has a single CSS node with name button. To differentiate it from a plain GtkButton, it gets the .link style class.
# Accessibility
GtkLinkButton uses the [enumGtk.AccessibleRole.link] role.
<screenshot>gtk-link_button</screenshot> <group>Buttons and Toggles</group> <gtkada_demo>create_link_buttons.adb</gtkada_demo>
function "+"
(Widget : access Gtk_Link_Button_Record'Class)
return Gtk.Accessible.Gtk_Accessible
function "+"
(Widget : access Gtk_Link_Button_Record'Class)
return Gtk.Buildable.Gtk_Buildable
function "+"
(Widget : access Gtk_Link_Button_Record'Class)
return Gtk.Constraint_Target.Gtk_Constraint_Target
function "-"
(Interf : Gtk.Accessible.Gtk_Accessible)
return Gtk_Link_Button
function "-"
(Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Link_Button
function "-"
(Interf : Gtk.Constraint_Target.Gtk_Constraint_Target)
return Gtk_Link_Button
procedure Announce
(Self : not null access Gtk_Link_Button_Record;
Message : UTF8_String;
Priority : Gtk.Accessible.Gtk_Accessible_Announcement_Priority)
type Cb_GObject_Boolean is not null access function
(Self : access Glib.Object.GObject_Record'Class)
return Boolean;
type Cb_Gtk_Link_Button_Boolean is not null access function
(Self : access Gtk_Link_Button_Record'Class) return Boolean;
function Get_Accessible_Id
(Self : not null access Gtk_Link_Button_Record) return UTF8_String
function Get_Accessible_Parent
(Self : not null access Gtk_Link_Button_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Accessible_Role
(Self : not null access Gtk_Link_Button_Record)
return Gtk.Accessible.Gtk_Accessible_Role
function Get_At_Context
(Self : not null access Gtk_Link_Button_Record)
return Gtk.Atcontext.Gtk_Atcontext
function Get_Bounds
(Self : not null access Gtk_Link_Button_Record;
X : out Glib.Gint;
Y : out Glib.Gint;
Width : out Glib.Gint;
Height : out Glib.Gint) return Boolean
function Get_First_Accessible_Child
(Self : not null access Gtk_Link_Button_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Next_Accessible_Sibling
(Self : not null access Gtk_Link_Button_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Platform_State
(Self : not null access Gtk_Link_Button_Record;
State : Gtk.Accessible.Gtk_Accessible_Platform_State) return Boolean
function Get_Type return Glib.GType
function Get_Uri
(Self : not null access Gtk_Link_Button_Record) return UTF8_String
Retrieves the URI of the GtkLinkButton.
a valid URI. The returned string is owned by the link button and should not be modified or freed.
function Get_Visited
(Self : not null access Gtk_Link_Button_Record) return Boolean
Retrieves the "visited" state of the GtkLinkButton. The button becomes visited when it is clicked. If the URI is changed on the button, the "visited" state is unset again. The state may also be changed using [methodGtk.LinkButton.set_visited].
True if the link has been visited, False otherwise
type Gtk_Link_Button is access all Gtk_Link_Button_Record'Class;
function Gtk_Link_Button_New (URI : UTF8_String) return Gtk_Link_Button
Creates a new GtkLinkButton with the URI as its text.
a valid URI
function Gtk_Link_Button_New_With_Label
(URI : UTF8_String;
Label : UTF8_String := "") return Gtk_Link_Button
Creates a new GtkLinkButton containing a label.
a valid URI
the text of the button
type Gtk_Link_Button_Record is new Gtk_Button_Record with null record;
procedure Gtk_New (Self : out Gtk_Link_Button; URI : UTF8_String)
Creates a new GtkLinkButton with the URI as its text. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
a valid URI
procedure Gtk_New_With_Label
(Self : out Gtk_Link_Button;
URI : UTF8_String;
Label : UTF8_String := "")
Creates a new GtkLinkButton containing a label. Initialize_With_Label does nothing if the object was already created with another call to Initialize* or G_New.
a valid URI
the text of the button
package Implements_Gtk_Accessible is new Glib.Types.Implements
(Gtk.Accessible.Gtk_Accessible, Gtk_Link_Button_Record, Gtk_Link_Button);
package Implements_Gtk_Buildable is new Glib.Types.Implements
(Gtk.Buildable.Gtk_Buildable, Gtk_Link_Button_Record, Gtk_Link_Button);
package Implements_Gtk_Constraint_Target is new Glib.Types.Implements
(Gtk.Constraint_Target.Gtk_Constraint_Target, Gtk_Link_Button_Record, Gtk_Link_Button);
procedure Initialize
(Self : not null access Gtk_Link_Button_Record'Class;
URI : UTF8_String)
Creates a new GtkLinkButton with the URI as its text. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
a valid URI
procedure Initialize_With_Label
(Self : not null access Gtk_Link_Button_Record'Class;
URI : UTF8_String;
Label : UTF8_String := "")
Creates a new GtkLinkButton containing a label. Initialize_With_Label does nothing if the object was already created with another call to Initialize* or G_New.
a valid URI
the text of the button
procedure On_Activate_Link
(Self : not null access Gtk_Link_Button_Record;
Call : Cb_GObject_Boolean;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
Emitted each time the GtkLinkButton is clicked.
The default handler will call [methodGtk.FileLauncher.launch] with the URI stored inside the [propertyGtk.LinkButton:uri] property.
To override the default behavior, you can connect to the ::activate-link signal and stop the propagation of the signal by returning True from your handler.
Callback parameters:
procedure On_Activate_Link
(Self : not null access Gtk_Link_Button_Record;
Call : Cb_Gtk_Link_Button_Boolean;
After : Boolean := False)
Emitted each time the GtkLinkButton is clicked.
The default handler will call [methodGtk.FileLauncher.launch] with the URI stored inside the [propertyGtk.LinkButton:uri] property.
To override the default behavior, you can connect to the ::activate-link signal and stop the propagation of the signal by returning True from your handler.
Callback parameters:
procedure Reset_Property
(Self : not null access Gtk_Link_Button_Record;
Property : Gtk.Accessible.Gtk_Accessible_Property)
procedure Reset_Relation
(Self : not null access Gtk_Link_Button_Record;
Relation : Gtk.Accessible.Gtk_Accessible_Relation)
procedure Reset_State
(Self : not null access Gtk_Link_Button_Record;
State : Gtk.Accessible.Gtk_Accessible_State)
procedure Set_Accessible_Parent
(Self : not null access Gtk_Link_Button_Record;
Parent : Gtk.Accessible.Gtk_Accessible;
Next_Sibling : Gtk.Accessible.Gtk_Accessible)
procedure Set_Uri
(Self : not null access Gtk_Link_Button_Record;
URI : UTF8_String)
Sets Uri as the URI where the GtkLinkButton points. As a side-effect this unsets the "visited" state of the button.
a valid URI
procedure Set_Visited
(Self : not null access Gtk_Link_Button_Record;
Visited : Boolean)
Sets the "visited" state of the GtkLinkButton. See [methodGtk.LinkButton.get_visited] for more details.
the new "visited" state
Signal_Activate_Link : constant Glib.Signal_Name := "activate-link";
Emitted each time the GtkLinkButton is clicked.
The default handler will call [methodGtk.FileLauncher.launch] with the URI stored inside the [propertyGtk.LinkButton:uri] property.
To override the default behavior, you can connect to the ::activate-link signal and stop the propagation of the signal by returning True from your handler.
Callback parameters:
procedure Update_Next_Accessible_Sibling
(Self : not null access Gtk_Link_Button_Record;
New_Sibling : Gtk.Accessible.Gtk_Accessible)
procedure Update_Platform_State
(Self : not null access Gtk_Link_Button_Record;
State : Gtk.Accessible.Gtk_Accessible_Platform_State)
URI_Property : constant Glib.Properties.Property_String;
The URI bound to this button.
Visited_Property : constant Glib.Properties.Property_Boolean;
The 'visited' state of this button.
A visited link is drawn in a different color.