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 private import std.algorithm; 37 38 39 /** 40 * A GtkLinkButton is a #GtkButton with a hyperlink, similar to the one 41 * used by web browsers, which triggers an action when clicked. It is useful 42 * to show quick links to resources. 43 * 44 * A link button is created by calling either gtk_link_button_new() or 45 * gtk_link_button_new_with_label(). If using the former, the URI you pass 46 * to the constructor is used as a label for the widget. 47 * 48 * The URI bound to a GtkLinkButton can be set specifically using 49 * gtk_link_button_set_uri(), and retrieved using gtk_link_button_get_uri(). 50 * 51 * By default, GtkLinkButton calls gtk_show_uri() when the button is 52 * clicked. This behaviour can be overridden by connecting to the 53 * #GtkLinkButton::activate-link signal and returning %TRUE from the 54 * signal handler. 55 * 56 * # CSS nodes 57 * 58 * GtkLinkButton has a single CSS node with name button. To differentiate 59 * it from a plain #GtkButton, it gets the .link style class. 60 */ 61 public class LinkButton : Button 62 { 63 /** the main Gtk struct */ 64 protected GtkLinkButton* gtkLinkButton; 65 66 /** Get the main Gtk struct */ 67 public GtkLinkButton* getLinkButtonStruct() 68 { 69 return gtkLinkButton; 70 } 71 72 /** the main Gtk struct as a void* */ 73 protected override void* getStruct() 74 { 75 return cast(void*)gtkLinkButton; 76 } 77 78 protected override void setStruct(GObject* obj) 79 { 80 gtkLinkButton = cast(GtkLinkButton*)obj; 81 super.setStruct(obj); 82 } 83 84 /** 85 * Sets our main struct and passes it to the parent class. 86 */ 87 public this (GtkLinkButton* gtkLinkButton, bool ownedRef = false) 88 { 89 this.gtkLinkButton = gtkLinkButton; 90 super(cast(GtkButton*)gtkLinkButton, ownedRef); 91 } 92 93 94 /** */ 95 public static GType getType() 96 { 97 return gtk_link_button_get_type(); 98 } 99 100 /** 101 * Creates a new #GtkLinkButton with the URI as its text. 102 * 103 * Params: 104 * uri = a valid URI 105 * 106 * Return: a new link button widget. 107 * 108 * Since: 2.10 109 * 110 * Throws: ConstructionException GTK+ fails to create the object. 111 */ 112 public this(string uri) 113 { 114 auto p = gtk_link_button_new(Str.toStringz(uri)); 115 116 if(p is null) 117 { 118 throw new ConstructionException("null returned by new"); 119 } 120 121 this(cast(GtkLinkButton*) p); 122 } 123 124 /** 125 * Creates a new #GtkLinkButton containing a label. 126 * 127 * Params: 128 * uri = a valid URI 129 * label = the text of the button 130 * 131 * Return: a new link button widget. 132 * 133 * Since: 2.10 134 * 135 * Throws: ConstructionException GTK+ fails to create the object. 136 */ 137 public this(string uri, string label) 138 { 139 auto p = gtk_link_button_new_with_label(Str.toStringz(uri), Str.toStringz(label)); 140 141 if(p is null) 142 { 143 throw new ConstructionException("null returned by new_with_label"); 144 } 145 146 this(cast(GtkLinkButton*) p); 147 } 148 149 /** 150 * Retrieves the URI set using gtk_link_button_set_uri(). 151 * 152 * Return: a valid URI. The returned string is owned by the link button 153 * and should not be modified or freed. 154 * 155 * Since: 2.10 156 */ 157 public string getUri() 158 { 159 return Str.toString(gtk_link_button_get_uri(gtkLinkButton)); 160 } 161 162 /** 163 * Retrieves the “visited” state of the URI where the #GtkLinkButton 164 * points. The button becomes visited when it is clicked. If the URI 165 * is changed on the button, the “visited” state is unset again. 166 * 167 * The state may also be changed using gtk_link_button_set_visited(). 168 * 169 * Return: %TRUE if the link has been visited, %FALSE otherwise 170 * 171 * Since: 2.14 172 */ 173 public bool getVisited() 174 { 175 return gtk_link_button_get_visited(gtkLinkButton) != 0; 176 } 177 178 /** 179 * Sets @uri as the URI where the #GtkLinkButton points. As a side-effect 180 * this unsets the “visited” state of the button. 181 * 182 * Params: 183 * uri = a valid URI 184 * 185 * Since: 2.10 186 */ 187 public void setUri(string uri) 188 { 189 gtk_link_button_set_uri(gtkLinkButton, Str.toStringz(uri)); 190 } 191 192 /** 193 * Sets the “visited” state of the URI where the #GtkLinkButton 194 * points. See gtk_link_button_get_visited() for more details. 195 * 196 * Params: 197 * visited = the new “visited” state 198 * 199 * Since: 2.14 200 */ 201 public void setVisited(bool visited) 202 { 203 gtk_link_button_set_visited(gtkLinkButton, visited); 204 } 205 206 protected class OnActivateLinkDelegateWrapper 207 { 208 bool delegate(LinkButton) dlg; 209 gulong handlerId; 210 ConnectFlags flags; 211 this(bool delegate(LinkButton) dlg, gulong handlerId, ConnectFlags flags) 212 { 213 this.dlg = dlg; 214 this.handlerId = handlerId; 215 this.flags = flags; 216 } 217 } 218 protected OnActivateLinkDelegateWrapper[] onActivateLinkListeners; 219 220 /** 221 * The ::activate-link signal is emitted each time the #GtkLinkButton 222 * has been clicked. 223 * 224 * The default handler will call gtk_show_uri() with the URI stored inside 225 * the #GtkLinkButton:uri property. 226 * 227 * To override the default behavior, you can connect to the ::activate-link 228 * signal and stop the propagation of the signal by returning %TRUE from 229 * your handler. 230 */ 231 gulong addOnActivateLink(bool delegate(LinkButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 232 { 233 onActivateLinkListeners ~= new OnActivateLinkDelegateWrapper(dlg, 0, connectFlags); 234 onActivateLinkListeners[onActivateLinkListeners.length - 1].handlerId = Signals.connectData( 235 this, 236 "activate-link", 237 cast(GCallback)&callBackActivateLink, 238 cast(void*)onActivateLinkListeners[onActivateLinkListeners.length - 1], 239 cast(GClosureNotify)&callBackActivateLinkDestroy, 240 connectFlags); 241 return onActivateLinkListeners[onActivateLinkListeners.length - 1].handlerId; 242 } 243 244 extern(C) static int callBackActivateLink(GtkLinkButton* linkbuttonStruct,OnActivateLinkDelegateWrapper wrapper) 245 { 246 return wrapper.dlg(wrapper.outer); 247 } 248 249 extern(C) static void callBackActivateLinkDestroy(OnActivateLinkDelegateWrapper wrapper, GClosure* closure) 250 { 251 wrapper.outer.internalRemoveOnActivateLink(wrapper); 252 } 253 254 protected void internalRemoveOnActivateLink(OnActivateLinkDelegateWrapper source) 255 { 256 foreach(index, wrapper; onActivateLinkListeners) 257 { 258 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 259 { 260 onActivateLinkListeners[index] = null; 261 onActivateLinkListeners = std.algorithm.remove(onActivateLinkListeners, index); 262 break; 263 } 264 } 265 } 266 267 }