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 private import gtkc.gtk; 34 public import gtkc.gtktypes; 35 private import std.algorithm; 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_on_window() 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 * Returns: 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 * Returns: 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 * Returns: 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 * Returns: %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 protected class OnActivateLinkDelegateWrapper 206 { 207 static OnActivateLinkDelegateWrapper[] listeners; 208 bool delegate(LinkButton) dlg; 209 gulong handlerId; 210 211 this(bool delegate(LinkButton) dlg) 212 { 213 this.dlg = dlg; 214 this.listeners ~= this; 215 } 216 217 void remove(OnActivateLinkDelegateWrapper source) 218 { 219 foreach(index, wrapper; listeners) 220 { 221 if (wrapper.handlerId == source.handlerId) 222 { 223 listeners[index] = null; 224 listeners = std.algorithm.remove(listeners, index); 225 break; 226 } 227 } 228 } 229 } 230 231 /** 232 * The ::activate-link signal is emitted each time the #GtkLinkButton 233 * has been clicked. 234 * 235 * The default handler will call gtk_show_uri_on_window() with the URI stored inside 236 * the #GtkLinkButton:uri property. 237 * 238 * To override the default behavior, you can connect to the ::activate-link 239 * signal and stop the propagation of the signal by returning %TRUE from 240 * your handler. 241 */ 242 gulong addOnActivateLink(bool delegate(LinkButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 243 { 244 auto wrapper = new OnActivateLinkDelegateWrapper(dlg); 245 wrapper.handlerId = Signals.connectData( 246 this, 247 "activate-link", 248 cast(GCallback)&callBackActivateLink, 249 cast(void*)wrapper, 250 cast(GClosureNotify)&callBackActivateLinkDestroy, 251 connectFlags); 252 return wrapper.handlerId; 253 } 254 255 extern(C) static int callBackActivateLink(GtkLinkButton* linkbuttonStruct, OnActivateLinkDelegateWrapper wrapper) 256 { 257 return wrapper.dlg(wrapper.outer); 258 } 259 260 extern(C) static void callBackActivateLinkDestroy(OnActivateLinkDelegateWrapper wrapper, GClosure* closure) 261 { 262 wrapper.remove(wrapper); 263 } 264 }