1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.LinkButton; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Button; 32 private import gtk.Widget; 33 public import gtkc.gdktypes; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 37 38 /** 39 * A GtkLinkButton is a #GtkButton with a hyperlink, similar to the one 40 * used by web browsers, which triggers an action when clicked. It is useful 41 * to show quick links to resources. 42 * 43 * A link button is created by calling either gtk_link_button_new() or 44 * gtk_link_button_new_with_label(). If using the former, the URI you pass 45 * to the constructor is used as a label for the widget. 46 * 47 * The URI bound to a GtkLinkButton can be set specifically using 48 * gtk_link_button_set_uri(), and retrieved using gtk_link_button_get_uri(). 49 * 50 * By default, GtkLinkButton calls gtk_show_uri() when the button is 51 * clicked. This behaviour can be overridden by connecting to the 52 * #GtkLinkButton::activate-link signal and returning %TRUE from the 53 * signal handler. 54 * 55 * # CSS nodes 56 * 57 * GtkLinkButton has a single CSS node with name button. To differentiate 58 * it from a plain #GtkButton, it gets the .link style class. 59 */ 60 public class LinkButton : Button 61 { 62 /** the main Gtk struct */ 63 protected GtkLinkButton* gtkLinkButton; 64 65 /** Get the main Gtk struct */ 66 public GtkLinkButton* getLinkButtonStruct() 67 { 68 return gtkLinkButton; 69 } 70 71 /** the main Gtk struct as a void* */ 72 protected override void* getStruct() 73 { 74 return cast(void*)gtkLinkButton; 75 } 76 77 protected override void setStruct(GObject* obj) 78 { 79 gtkLinkButton = cast(GtkLinkButton*)obj; 80 super.setStruct(obj); 81 } 82 83 /** 84 * Sets our main struct and passes it to the parent class. 85 */ 86 public this (GtkLinkButton* gtkLinkButton, bool ownedRef = false) 87 { 88 this.gtkLinkButton = gtkLinkButton; 89 super(cast(GtkButton*)gtkLinkButton, ownedRef); 90 } 91 92 93 /** */ 94 public static GType getType() 95 { 96 return gtk_link_button_get_type(); 97 } 98 99 /** 100 * Creates a new #GtkLinkButton with the URI as its text. 101 * 102 * Params: 103 * uri = a valid URI 104 * 105 * Return: a new link button widget. 106 * 107 * Since: 2.10 108 * 109 * Throws: ConstructionException GTK+ fails to create the object. 110 */ 111 public this(string uri) 112 { 113 auto p = gtk_link_button_new(Str.toStringz(uri)); 114 115 if(p is null) 116 { 117 throw new ConstructionException("null returned by new"); 118 } 119 120 this(cast(GtkLinkButton*) p); 121 } 122 123 /** 124 * Creates a new #GtkLinkButton containing a label. 125 * 126 * Params: 127 * uri = a valid URI 128 * label = the text of the button 129 * 130 * Return: a new link button widget. 131 * 132 * Since: 2.10 133 * 134 * Throws: ConstructionException GTK+ fails to create the object. 135 */ 136 public this(string uri, string label) 137 { 138 auto p = gtk_link_button_new_with_label(Str.toStringz(uri), Str.toStringz(label)); 139 140 if(p is null) 141 { 142 throw new ConstructionException("null returned by new_with_label"); 143 } 144 145 this(cast(GtkLinkButton*) p); 146 } 147 148 /** 149 * Retrieves the URI set using gtk_link_button_set_uri(). 150 * 151 * Return: a valid URI. The returned string is owned by the link button 152 * and should not be modified or freed. 153 * 154 * Since: 2.10 155 */ 156 public string getUri() 157 { 158 return Str.toString(gtk_link_button_get_uri(gtkLinkButton)); 159 } 160 161 /** 162 * Retrieves the “visited” state of the URI where the #GtkLinkButton 163 * points. The button becomes visited when it is clicked. If the URI 164 * is changed on the button, the “visited” state is unset again. 165 * 166 * The state may also be changed using gtk_link_button_set_visited(). 167 * 168 * Return: %TRUE if the link has been visited, %FALSE otherwise 169 * 170 * Since: 2.14 171 */ 172 public bool getVisited() 173 { 174 return gtk_link_button_get_visited(gtkLinkButton) != 0; 175 } 176 177 /** 178 * Sets @uri as the URI where the #GtkLinkButton points. As a side-effect 179 * this unsets the “visited” state of the button. 180 * 181 * Params: 182 * uri = a valid URI 183 * 184 * Since: 2.10 185 */ 186 public void setUri(string uri) 187 { 188 gtk_link_button_set_uri(gtkLinkButton, Str.toStringz(uri)); 189 } 190 191 /** 192 * Sets the “visited” state of the URI where the #GtkLinkButton 193 * points. See gtk_link_button_get_visited() for more details. 194 * 195 * Params: 196 * visited = the new “visited” state 197 * 198 * Since: 2.14 199 */ 200 public void setVisited(bool visited) 201 { 202 gtk_link_button_set_visited(gtkLinkButton, visited); 203 } 204 205 int[string] connectedSignals; 206 207 bool delegate(LinkButton)[] onActivateLinkListeners; 208 /** 209 * The ::activate-link signal is emitted each time the #GtkLinkButton 210 * has been clicked. 211 * 212 * The default handler will call gtk_show_uri() with the URI stored inside 213 * the #GtkLinkButton:uri property. 214 * 215 * To override the default behavior, you can connect to the ::activate-link 216 * signal and stop the propagation of the signal by returning %TRUE from 217 * your handler. 218 */ 219 void addOnActivateLink(bool delegate(LinkButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 220 { 221 if ( "activate-link" !in connectedSignals ) 222 { 223 Signals.connectData( 224 this, 225 "activate-link", 226 cast(GCallback)&callBackActivateLink, 227 cast(void*)this, 228 null, 229 connectFlags); 230 connectedSignals["activate-link"] = 1; 231 } 232 onActivateLinkListeners ~= dlg; 233 } 234 extern(C) static int callBackActivateLink(GtkLinkButton* linkbuttonStruct, LinkButton _linkbutton) 235 { 236 foreach ( bool delegate(LinkButton) dlg; _linkbutton.onActivateLinkListeners ) 237 { 238 if ( dlg(_linkbutton) ) 239 { 240 return 1; 241 } 242 } 243 244 return 0; 245 } 246 }