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